1 //==- llvm/CodeGen/TargetLoweringObjectFileImpl.h - Object Info --*- C++ -*-==// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // This file implements classes used to handle lowerings specific to common 11 // object file formats. 12 // 13 //===----------------------------------------------------------------------===// 14 15 #ifndef LLVM_CODEGEN_TARGETLOWERINGOBJECTFILEIMPL_H 16 #define LLVM_CODEGEN_TARGETLOWERINGOBJECTFILEIMPL_H 17 18 #include "llvm/IR/Module.h" 19 #include "llvm/MC/MCExpr.h" 20 #include "llvm/Target/TargetLoweringObjectFile.h" 21 22 namespace llvm { 23 24 class GlobalValue; 25 class MachineModuleInfo; 26 class Mangler; 27 class MCContext; 28 class MCSection; 29 class MCSymbol; 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: 41 TargetLoweringObjectFileELF() = default; 42 ~TargetLoweringObjectFileELF() override = default; 43 44 /// Emit Obj-C garbage collection and linker options. 45 void emitModuleMetadata(MCStreamer &Streamer, Module &M, 46 const TargetMachine &TM) const override; 47 48 void emitPersonalityValue(MCStreamer &Streamer, const DataLayout &TM, 49 const MCSymbol *Sym) const override; 50 51 /// Given a constant with the SectionKind, return a section that it should be 52 /// placed in. 53 MCSection *getSectionForConstant(const DataLayout &DL, SectionKind Kind, 54 const Constant *C, 55 unsigned &Align) const override; 56 57 MCSection *getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind, 58 const TargetMachine &TM) const override; 59 60 MCSection *SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, 61 const TargetMachine &TM) const override; 62 63 MCSection *getSectionForJumpTable(const Function &F, 64 const TargetMachine &TM) const override; 65 66 bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference, 67 const Function &F) const override; 68 69 /// Return an MCExpr to use for a reference to the specified type info global 70 /// variable from exception handling information. 71 const MCExpr *getTTypeGlobalReference(const GlobalValue *GV, 72 unsigned Encoding, 73 const TargetMachine &TM, 74 MachineModuleInfo *MMI, 75 MCStreamer &Streamer) const override; 76 77 // The symbol that gets passed to .cfi_personality. 78 MCSymbol *getCFIPersonalitySymbol(const GlobalValue *GV, 79 const TargetMachine &TM, 80 MachineModuleInfo *MMI) const override; 81 82 void InitializeELF(bool UseInitArray_); 83 MCSection *getStaticCtorSection(unsigned Priority, 84 const MCSymbol *KeySym) const override; 85 MCSection *getStaticDtorSection(unsigned Priority, 86 const MCSymbol *KeySym) const override; 87 88 const MCExpr *lowerRelativeReference(const GlobalValue *LHS, 89 const GlobalValue *RHS, 90 const TargetMachine &TM) const override; 91 }; 92 93 class TargetLoweringObjectFileMachO : public TargetLoweringObjectFile { 94 public: 95 TargetLoweringObjectFileMachO(); 96 ~TargetLoweringObjectFileMachO() override = default; 97 98 void Initialize(MCContext &Ctx, const TargetMachine &TM) override; 99 100 /// Emit the module flags that specify the garbage collection information. 101 void emitModuleMetadata(MCStreamer &Streamer, Module &M, 102 const TargetMachine &TM) const override; 103 104 MCSection *SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, 105 const TargetMachine &TM) const override; 106 107 MCSection *getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind, 108 const TargetMachine &TM) const override; 109 110 MCSection *getSectionForConstant(const DataLayout &DL, SectionKind Kind, 111 const Constant *C, 112 unsigned &Align) const override; 113 114 /// The mach-o version of this method defaults to returning a stub reference. 115 const MCExpr *getTTypeGlobalReference(const GlobalValue *GV, 116 unsigned Encoding, 117 const TargetMachine &TM, 118 MachineModuleInfo *MMI, 119 MCStreamer &Streamer) const override; 120 121 // The symbol that gets passed to .cfi_personality. 122 MCSymbol *getCFIPersonalitySymbol(const GlobalValue *GV, 123 const TargetMachine &TM, 124 MachineModuleInfo *MMI) const override; 125 126 /// Get MachO PC relative GOT entry relocation 127 const MCExpr *getIndirectSymViaGOTPCRel(const MCSymbol *Sym, 128 const MCValue &MV, int64_t Offset, 129 MachineModuleInfo *MMI, 130 MCStreamer &Streamer) const override; 131 132 void getNameWithPrefix(SmallVectorImpl<char> &OutName, const GlobalValue *GV, 133 const TargetMachine &TM) const override; 134 }; 135 136 class TargetLoweringObjectFileCOFF : public TargetLoweringObjectFile { 137 mutable unsigned NextUniqueID = 0; 138 139 public: 140 ~TargetLoweringObjectFileCOFF() override = default; 141 142 void Initialize(MCContext &Ctx, const TargetMachine &TM) override; 143 MCSection *getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind, 144 const TargetMachine &TM) const override; 145 146 MCSection *SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, 147 const TargetMachine &TM) const override; 148 149 void getNameWithPrefix(SmallVectorImpl<char> &OutName, const GlobalValue *GV, 150 const TargetMachine &TM) const override; 151 152 MCSection *getSectionForJumpTable(const Function &F, 153 const TargetMachine &TM) const override; 154 155 /// Emit Obj-C garbage collection and linker options. 156 void emitModuleMetadata(MCStreamer &Streamer, Module &M, 157 const TargetMachine &TM) const override; 158 159 MCSection *getStaticCtorSection(unsigned Priority, 160 const MCSymbol *KeySym) const override; 161 MCSection *getStaticDtorSection(unsigned Priority, 162 const MCSymbol *KeySym) const override; 163 164 void emitLinkerFlagsForGlobal(raw_ostream &OS, 165 const GlobalValue *GV) const override; 166 }; 167 168 class TargetLoweringObjectFileWasm : public TargetLoweringObjectFile { 169 mutable unsigned NextUniqueID = 0; 170 171 public: 172 TargetLoweringObjectFileWasm() = default; 173 ~TargetLoweringObjectFileWasm() override = default; 174 175 MCSection *getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind, 176 const TargetMachine &TM) const override; 177 178 MCSection *SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, 179 const TargetMachine &TM) const override; 180 181 bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference, 182 const Function &F) const override; 183 184 void InitializeWasm(); 185 186 const MCExpr *lowerRelativeReference(const GlobalValue *LHS, 187 const GlobalValue *RHS, 188 const TargetMachine &TM) const override; 189 }; 190 191 } // end namespace llvm 192 193 #endif // LLVM_CODEGEN_TARGETLOWERINGOBJECTFILEIMPL_H 194