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/MC/MCExpr.h" 19 #include "llvm/MC/SectionKind.h" 20 #include "llvm/Target/TargetLoweringObjectFile.h" 21 22 namespace llvm { 23 class MachineModuleInfo; 24 class Mangler; 25 class MCAsmInfo; 26 class MCSection; 27 class MCSectionMachO; 28 class MCSymbol; 29 class MCContext; 30 class GlobalValue; 31 class TargetMachine; 32 33 34 class TargetLoweringObjectFileELF : public TargetLoweringObjectFile { 35 bool UseInitArray; 36 mutable unsigned NextUniqueID = 0; 37 38 protected: 39 MCSymbolRefExpr::VariantKind PLTRelativeVariantKind = 40 MCSymbolRefExpr::VK_None; 41 42 public: TargetLoweringObjectFileELF()43 TargetLoweringObjectFileELF() : UseInitArray(false) {} 44 ~TargetLoweringObjectFileELF()45 ~TargetLoweringObjectFileELF() override {} 46 47 void emitPersonalityValue(MCStreamer &Streamer, const DataLayout &TM, 48 const MCSymbol *Sym) const override; 49 50 /// Given a constant with the SectionKind, return a section that it should be 51 /// placed in. 52 MCSection *getSectionForConstant(const DataLayout &DL, SectionKind Kind, 53 const Constant *C, 54 unsigned &Align) const override; 55 56 MCSection *getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, 57 Mangler &Mang, 58 const TargetMachine &TM) const override; 59 60 MCSection *SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, 61 Mangler &Mang, 62 const TargetMachine &TM) const override; 63 64 MCSection *getSectionForJumpTable(const Function &F, Mangler &Mang, 65 const TargetMachine &TM) const override; 66 67 bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference, 68 const Function &F) const override; 69 70 /// Return an MCExpr to use for a reference to the specified type info global 71 /// variable from exception handling information. 72 const MCExpr * 73 getTTypeGlobalReference(const GlobalValue *GV, unsigned Encoding, 74 Mangler &Mang, const TargetMachine &TM, 75 MachineModuleInfo *MMI, 76 MCStreamer &Streamer) const override; 77 78 // The symbol that gets passed to .cfi_personality. 79 MCSymbol *getCFIPersonalitySymbol(const GlobalValue *GV, Mangler &Mang, 80 const TargetMachine &TM, 81 MachineModuleInfo *MMI) const override; 82 83 void InitializeELF(bool UseInitArray_); 84 MCSection *getStaticCtorSection(unsigned Priority, 85 const MCSymbol *KeySym) const override; 86 MCSection *getStaticDtorSection(unsigned Priority, 87 const MCSymbol *KeySym) const override; 88 89 const MCExpr *lowerRelativeReference(const GlobalValue *LHS, 90 const GlobalValue *RHS, Mangler &Mang, 91 const TargetMachine &TM) const override; 92 }; 93 94 95 96 class TargetLoweringObjectFileMachO : public TargetLoweringObjectFile { 97 public: ~TargetLoweringObjectFileMachO()98 ~TargetLoweringObjectFileMachO() override {} 99 TargetLoweringObjectFileMachO(); 100 101 /// Emit the module flags that specify the garbage collection information. 102 void emitModuleFlags(MCStreamer &Streamer, 103 ArrayRef<Module::ModuleFlagEntry> ModuleFlags, 104 Mangler &Mang, const TargetMachine &TM) const override; 105 106 MCSection *SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, 107 Mangler &Mang, 108 const TargetMachine &TM) const override; 109 110 MCSection *getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, 111 Mangler &Mang, 112 const TargetMachine &TM) const override; 113 114 MCSection *getSectionForConstant(const DataLayout &DL, SectionKind Kind, 115 const Constant *C, 116 unsigned &Align) const override; 117 118 /// The mach-o version of this method defaults to returning a stub reference. 119 const MCExpr * 120 getTTypeGlobalReference(const GlobalValue *GV, unsigned Encoding, 121 Mangler &Mang, const TargetMachine &TM, 122 MachineModuleInfo *MMI, 123 MCStreamer &Streamer) const override; 124 125 // The symbol that gets passed to .cfi_personality. 126 MCSymbol *getCFIPersonalitySymbol(const GlobalValue *GV, Mangler &Mang, 127 const TargetMachine &TM, 128 MachineModuleInfo *MMI) const override; 129 130 /// Get MachO PC relative GOT entry relocation 131 const MCExpr *getIndirectSymViaGOTPCRel(const MCSymbol *Sym, 132 const MCValue &MV, int64_t Offset, 133 MachineModuleInfo *MMI, 134 MCStreamer &Streamer) const override; 135 136 void getNameWithPrefix(SmallVectorImpl<char> &OutName, const GlobalValue *GV, 137 Mangler &Mang, const TargetMachine &TM) const override; 138 }; 139 140 141 142 class TargetLoweringObjectFileCOFF : public TargetLoweringObjectFile { 143 mutable unsigned NextUniqueID = 0; 144 145 public: ~TargetLoweringObjectFileCOFF()146 ~TargetLoweringObjectFileCOFF() override {} 147 148 MCSection *getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, 149 Mangler &Mang, 150 const TargetMachine &TM) const override; 151 152 MCSection *SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, 153 Mangler &Mang, 154 const TargetMachine &TM) const override; 155 156 void getNameWithPrefix(SmallVectorImpl<char> &OutName, const GlobalValue *GV, 157 Mangler &Mang, const TargetMachine &TM) const override; 158 159 MCSection *getSectionForJumpTable(const Function &F, Mangler &Mang, 160 const TargetMachine &TM) const override; 161 162 /// Emit Obj-C garbage collection and linker options. Only linker option 163 /// emission is implemented for COFF. 164 void emitModuleFlags(MCStreamer &Streamer, 165 ArrayRef<Module::ModuleFlagEntry> ModuleFlags, 166 Mangler &Mang, const TargetMachine &TM) const override; 167 168 MCSection *getStaticCtorSection(unsigned Priority, 169 const MCSymbol *KeySym) const override; 170 MCSection *getStaticDtorSection(unsigned Priority, 171 const MCSymbol *KeySym) const override; 172 173 void emitLinkerFlagsForGlobal(raw_ostream &OS, const GlobalValue *GV, 174 const Mangler &Mang) const override; 175 }; 176 177 } // end namespace llvm 178 179 #endif 180