Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 1 | //==- llvm/CodeGen/TargetLoweringObjectFileImpl.h - Object Info --*- C++ -*-==// |
| 2 | // |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This file implements classes used to handle lowerings specific to common |
| 10 | // object file formats. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef LLVM_CODEGEN_TARGETLOWERINGOBJECTFILEIMPL_H |
| 15 | #define LLVM_CODEGEN_TARGETLOWERINGOBJECTFILEIMPL_H |
| 16 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 17 | #include "llvm/BinaryFormat/XCOFF.h" |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 18 | #include "llvm/Target/TargetLoweringObjectFile.h" |
| 19 | |
| 20 | namespace llvm { |
| 21 | |
| 22 | class GlobalValue; |
| 23 | class MachineModuleInfo; |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 24 | class MachineFunction; |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 25 | class MCContext; |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 26 | class MCExpr; |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 27 | class MCSection; |
| 28 | class MCSymbol; |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 29 | class Module; |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 30 | class TargetMachine; |
| 31 | |
| 32 | class TargetLoweringObjectFileELF : public TargetLoweringObjectFile { |
| 33 | bool UseInitArray = false; |
| 34 | mutable unsigned NextUniqueID = 1; // ID 0 is reserved for execute-only sections |
| 35 | |
| 36 | protected: |
| 37 | MCSymbolRefExpr::VariantKind PLTRelativeVariantKind = |
| 38 | MCSymbolRefExpr::VK_None; |
| 39 | |
| 40 | public: |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 41 | TargetLoweringObjectFileELF(); |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 42 | ~TargetLoweringObjectFileELF() override = default; |
| 43 | |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 44 | void Initialize(MCContext &Ctx, const TargetMachine &TM) override; |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 45 | |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 46 | /// Emit Obj-C garbage collection and linker options. |
| 47 | void emitModuleMetadata(MCStreamer &Streamer, Module &M) const override; |
| 48 | |
| 49 | void emitPersonalityValue(MCStreamer &Streamer, const DataLayout &DL, |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 50 | const MCSymbol *Sym) const override; |
| 51 | |
| 52 | /// Given a constant with the SectionKind, return a section that it should be |
| 53 | /// placed in. |
| 54 | MCSection *getSectionForConstant(const DataLayout &DL, SectionKind Kind, |
| 55 | const Constant *C, |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 56 | Align &Alignment) const override; |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 57 | |
| 58 | MCSection *getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind, |
| 59 | const TargetMachine &TM) const override; |
| 60 | |
| 61 | MCSection *SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, |
| 62 | const TargetMachine &TM) const override; |
| 63 | |
| 64 | MCSection *getSectionForJumpTable(const Function &F, |
| 65 | const TargetMachine &TM) const override; |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 66 | MCSection *getSectionForLSDA(const Function &F, |
| 67 | const TargetMachine &TM) const override; |
| 68 | |
| 69 | MCSection * |
| 70 | getSectionForMachineBasicBlock(const Function &F, |
| 71 | const MachineBasicBlock &MBB, |
| 72 | const TargetMachine &TM) const override; |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 73 | |
| 74 | bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference, |
| 75 | const Function &F) const override; |
| 76 | |
| 77 | /// Return an MCExpr to use for a reference to the specified type info global |
| 78 | /// variable from exception handling information. |
| 79 | const MCExpr *getTTypeGlobalReference(const GlobalValue *GV, |
| 80 | unsigned Encoding, |
| 81 | const TargetMachine &TM, |
| 82 | MachineModuleInfo *MMI, |
| 83 | MCStreamer &Streamer) const override; |
| 84 | |
| 85 | // The symbol that gets passed to .cfi_personality. |
| 86 | MCSymbol *getCFIPersonalitySymbol(const GlobalValue *GV, |
| 87 | const TargetMachine &TM, |
| 88 | MachineModuleInfo *MMI) const override; |
| 89 | |
| 90 | void InitializeELF(bool UseInitArray_); |
| 91 | MCSection *getStaticCtorSection(unsigned Priority, |
| 92 | const MCSymbol *KeySym) const override; |
| 93 | MCSection *getStaticDtorSection(unsigned Priority, |
| 94 | const MCSymbol *KeySym) const override; |
| 95 | |
| 96 | const MCExpr *lowerRelativeReference(const GlobalValue *LHS, |
| 97 | const GlobalValue *RHS, |
| 98 | const TargetMachine &TM) const override; |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 99 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 100 | const MCExpr *lowerDSOLocalEquivalent(const DSOLocalEquivalent *Equiv, |
| 101 | const TargetMachine &TM) const override; |
| 102 | |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 103 | MCSection *getSectionForCommandLines() const override; |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 104 | }; |
| 105 | |
| 106 | class TargetLoweringObjectFileMachO : public TargetLoweringObjectFile { |
| 107 | public: |
| 108 | TargetLoweringObjectFileMachO(); |
| 109 | ~TargetLoweringObjectFileMachO() override = default; |
| 110 | |
| 111 | void Initialize(MCContext &Ctx, const TargetMachine &TM) override; |
| 112 | |
| 113 | /// Emit the module flags that specify the garbage collection information. |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 114 | void emitModuleMetadata(MCStreamer &Streamer, Module &M) const override; |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 115 | |
| 116 | MCSection *SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, |
| 117 | const TargetMachine &TM) const override; |
| 118 | |
| 119 | MCSection *getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind, |
| 120 | const TargetMachine &TM) const override; |
| 121 | |
| 122 | MCSection *getSectionForConstant(const DataLayout &DL, SectionKind Kind, |
| 123 | const Constant *C, |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 124 | Align &Alignment) const override; |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 125 | |
| 126 | /// The mach-o version of this method defaults to returning a stub reference. |
| 127 | const MCExpr *getTTypeGlobalReference(const GlobalValue *GV, |
| 128 | unsigned Encoding, |
| 129 | const TargetMachine &TM, |
| 130 | MachineModuleInfo *MMI, |
| 131 | MCStreamer &Streamer) const override; |
| 132 | |
| 133 | // The symbol that gets passed to .cfi_personality. |
| 134 | MCSymbol *getCFIPersonalitySymbol(const GlobalValue *GV, |
| 135 | const TargetMachine &TM, |
| 136 | MachineModuleInfo *MMI) const override; |
| 137 | |
| 138 | /// Get MachO PC relative GOT entry relocation |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 139 | const MCExpr *getIndirectSymViaGOTPCRel(const GlobalValue *GV, |
| 140 | const MCSymbol *Sym, |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 141 | const MCValue &MV, int64_t Offset, |
| 142 | MachineModuleInfo *MMI, |
| 143 | MCStreamer &Streamer) const override; |
| 144 | |
| 145 | void getNameWithPrefix(SmallVectorImpl<char> &OutName, const GlobalValue *GV, |
| 146 | const TargetMachine &TM) const override; |
| 147 | }; |
| 148 | |
| 149 | class TargetLoweringObjectFileCOFF : public TargetLoweringObjectFile { |
| 150 | mutable unsigned NextUniqueID = 0; |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 151 | const TargetMachine *TM = nullptr; |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 152 | |
| 153 | public: |
| 154 | ~TargetLoweringObjectFileCOFF() override = default; |
| 155 | |
| 156 | void Initialize(MCContext &Ctx, const TargetMachine &TM) override; |
| 157 | MCSection *getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind, |
| 158 | const TargetMachine &TM) const override; |
| 159 | |
| 160 | MCSection *SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, |
| 161 | const TargetMachine &TM) const override; |
| 162 | |
| 163 | void getNameWithPrefix(SmallVectorImpl<char> &OutName, const GlobalValue *GV, |
| 164 | const TargetMachine &TM) const override; |
| 165 | |
| 166 | MCSection *getSectionForJumpTable(const Function &F, |
| 167 | const TargetMachine &TM) const override; |
| 168 | |
| 169 | /// Emit Obj-C garbage collection and linker options. |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 170 | void emitModuleMetadata(MCStreamer &Streamer, Module &M) const override; |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 171 | |
| 172 | MCSection *getStaticCtorSection(unsigned Priority, |
| 173 | const MCSymbol *KeySym) const override; |
| 174 | MCSection *getStaticDtorSection(unsigned Priority, |
| 175 | const MCSymbol *KeySym) const override; |
| 176 | |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 177 | const MCExpr *lowerRelativeReference(const GlobalValue *LHS, |
| 178 | const GlobalValue *RHS, |
| 179 | const TargetMachine &TM) const override; |
| 180 | |
| 181 | /// Given a mergeable constant with the specified size and relocation |
| 182 | /// information, return a section that it should be placed in. |
| 183 | MCSection *getSectionForConstant(const DataLayout &DL, SectionKind Kind, |
| 184 | const Constant *C, |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 185 | Align &Alignment) const override; |
| 186 | |
| 187 | private: |
| 188 | void emitLinkerDirectives(MCStreamer &Streamer, Module &M) const; |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 189 | }; |
| 190 | |
| 191 | class TargetLoweringObjectFileWasm : public TargetLoweringObjectFile { |
| 192 | mutable unsigned NextUniqueID = 0; |
| 193 | |
| 194 | public: |
| 195 | TargetLoweringObjectFileWasm() = default; |
| 196 | ~TargetLoweringObjectFileWasm() override = default; |
| 197 | |
| 198 | MCSection *getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind, |
| 199 | const TargetMachine &TM) const override; |
| 200 | |
| 201 | MCSection *SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, |
| 202 | const TargetMachine &TM) const override; |
| 203 | |
| 204 | bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference, |
| 205 | const Function &F) const override; |
| 206 | |
| 207 | void InitializeWasm(); |
| 208 | MCSection *getStaticCtorSection(unsigned Priority, |
| 209 | const MCSymbol *KeySym) const override; |
| 210 | MCSection *getStaticDtorSection(unsigned Priority, |
| 211 | const MCSymbol *KeySym) const override; |
| 212 | |
| 213 | const MCExpr *lowerRelativeReference(const GlobalValue *LHS, |
| 214 | const GlobalValue *RHS, |
| 215 | const TargetMachine &TM) const override; |
| 216 | }; |
| 217 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 218 | class TargetLoweringObjectFileXCOFF : public TargetLoweringObjectFile { |
| 219 | public: |
| 220 | TargetLoweringObjectFileXCOFF() = default; |
| 221 | ~TargetLoweringObjectFileXCOFF() override = default; |
| 222 | |
| 223 | static bool ShouldEmitEHBlock(const MachineFunction *MF); |
| 224 | |
| 225 | static MCSymbol *getEHInfoTableSymbol(const MachineFunction *MF); |
| 226 | |
| 227 | void Initialize(MCContext &Ctx, const TargetMachine &TM) override; |
| 228 | |
| 229 | bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference, |
| 230 | const Function &F) const override; |
| 231 | |
| 232 | MCSection *getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind, |
| 233 | const TargetMachine &TM) const override; |
| 234 | |
| 235 | MCSection *getStaticCtorSection(unsigned Priority, |
| 236 | const MCSymbol *KeySym) const override; |
| 237 | MCSection *getStaticDtorSection(unsigned Priority, |
| 238 | const MCSymbol *KeySym) const override; |
| 239 | |
| 240 | const MCExpr *lowerRelativeReference(const GlobalValue *LHS, |
| 241 | const GlobalValue *RHS, |
| 242 | const TargetMachine &TM) const override; |
| 243 | |
| 244 | MCSection *SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, |
| 245 | const TargetMachine &TM) const override; |
| 246 | |
| 247 | MCSection *getSectionForJumpTable(const Function &F, |
| 248 | const TargetMachine &TM) const override; |
| 249 | |
| 250 | /// Given a constant with the SectionKind, return a section that it should be |
| 251 | /// placed in. |
| 252 | MCSection *getSectionForConstant(const DataLayout &DL, SectionKind Kind, |
| 253 | const Constant *C, |
| 254 | Align &Alignment) const override; |
| 255 | |
| 256 | static XCOFF::StorageClass getStorageClassForGlobal(const GlobalValue *GV); |
| 257 | |
| 258 | MCSection * |
| 259 | getSectionForFunctionDescriptor(const Function *F, |
| 260 | const TargetMachine &TM) const override; |
| 261 | MCSection *getSectionForTOCEntry(const MCSymbol *Sym, |
| 262 | const TargetMachine &TM) const override; |
| 263 | |
| 264 | /// For external functions, this will always return a function descriptor |
| 265 | /// csect. |
| 266 | MCSection * |
| 267 | getSectionForExternalReference(const GlobalObject *GO, |
| 268 | const TargetMachine &TM) const override; |
| 269 | |
| 270 | /// For functions, this will always return a function descriptor symbol. |
| 271 | MCSymbol *getTargetSymbol(const GlobalValue *GV, |
| 272 | const TargetMachine &TM) const override; |
| 273 | |
| 274 | MCSymbol *getFunctionEntryPointSymbol(const GlobalValue *Func, |
| 275 | const TargetMachine &TM) const override; |
| 276 | }; |
| 277 | |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 278 | } // end namespace llvm |
| 279 | |
| 280 | #endif // LLVM_CODEGEN_TARGETLOWERINGOBJECTFILEIMPL_H |