File indexing completed on 2026-05-10 08:43:38
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef LLVM_CODEGEN_TARGETLOWERINGOBJECTFILEIMPL_H
0015 #define LLVM_CODEGEN_TARGETLOWERINGOBJECTFILEIMPL_H
0016
0017 #include "llvm/ADT/SmallPtrSet.h"
0018 #include "llvm/BinaryFormat/XCOFF.h"
0019 #include "llvm/MC/MCExpr.h"
0020 #include "llvm/Target/TargetLoweringObjectFile.h"
0021
0022 namespace llvm {
0023
0024 class GlobalValue;
0025 class MachineModuleInfo;
0026 class MachineFunction;
0027 class MCContext;
0028 class MCExpr;
0029 class MCSection;
0030 class MCSymbol;
0031 class Module;
0032 class TargetMachine;
0033
0034 class TargetLoweringObjectFileELF : public TargetLoweringObjectFile {
0035 bool UseInitArray = false;
0036 mutable unsigned NextUniqueID = 1;
0037 SmallPtrSet<GlobalObject *, 2> Used;
0038
0039 protected:
0040 MCSymbolRefExpr::VariantKind PLTRelativeVariantKind =
0041 MCSymbolRefExpr::VK_None;
0042
0043 public:
0044 TargetLoweringObjectFileELF();
0045 ~TargetLoweringObjectFileELF() override = default;
0046
0047 void Initialize(MCContext &Ctx, const TargetMachine &TM) override;
0048
0049 void getModuleMetadata(Module &M) override;
0050
0051
0052 void emitModuleMetadata(MCStreamer &Streamer, Module &M) const override;
0053
0054 void emitPersonalityValue(MCStreamer &Streamer, const DataLayout &DL,
0055 const MCSymbol *Sym,
0056 const MachineModuleInfo *MMI) const override;
0057
0058 virtual void emitPersonalityValueImpl(MCStreamer &Streamer,
0059 const DataLayout &DL,
0060 const MCSymbol *Sym,
0061 const MachineModuleInfo *MMI) const;
0062
0063 void emitLinkerDirectives(MCStreamer &Streamer, Module &M) const override;
0064
0065
0066
0067 MCSection *getSectionForConstant(const DataLayout &DL, SectionKind Kind,
0068 const Constant *C,
0069 Align &Alignment) const override;
0070
0071 MCSection *getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind,
0072 const TargetMachine &TM) const override;
0073
0074 MCSection *SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind,
0075 const TargetMachine &TM) const override;
0076
0077 MCSection *getSectionForJumpTable(const Function &F,
0078 const TargetMachine &TM) const override;
0079 MCSection *getSectionForLSDA(const Function &F, const MCSymbol &FnSym,
0080 const TargetMachine &TM) const override;
0081
0082 MCSection *
0083 getSectionForMachineBasicBlock(const Function &F,
0084 const MachineBasicBlock &MBB,
0085 const TargetMachine &TM) const override;
0086
0087 MCSection *
0088 getUniqueSectionForFunction(const Function &F,
0089 const TargetMachine &TM) const override;
0090
0091 bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
0092 const Function &F) const override;
0093
0094
0095
0096 const MCExpr *getTTypeGlobalReference(const GlobalValue *GV,
0097 unsigned Encoding,
0098 const TargetMachine &TM,
0099 MachineModuleInfo *MMI,
0100 MCStreamer &Streamer) const override;
0101
0102
0103 MCSymbol *getCFIPersonalitySymbol(const GlobalValue *GV,
0104 const TargetMachine &TM,
0105 MachineModuleInfo *MMI) const override;
0106
0107 void InitializeELF(bool UseInitArray_);
0108 MCSection *getStaticCtorSection(unsigned Priority,
0109 const MCSymbol *KeySym) const override;
0110 MCSection *getStaticDtorSection(unsigned Priority,
0111 const MCSymbol *KeySym) const override;
0112
0113 const MCExpr *lowerRelativeReference(const GlobalValue *LHS,
0114 const GlobalValue *RHS,
0115 const TargetMachine &TM) const override;
0116
0117 const MCExpr *lowerDSOLocalEquivalent(const DSOLocalEquivalent *Equiv,
0118 const TargetMachine &TM) const override;
0119
0120 MCSection *getSectionForCommandLines() const override;
0121 };
0122
0123 class TargetLoweringObjectFileMachO : public TargetLoweringObjectFile {
0124 public:
0125 TargetLoweringObjectFileMachO();
0126 ~TargetLoweringObjectFileMachO() override = default;
0127
0128 void Initialize(MCContext &Ctx, const TargetMachine &TM) override;
0129
0130 MCSection *getStaticDtorSection(unsigned Priority,
0131 const MCSymbol *KeySym) const override;
0132
0133
0134 void emitModuleMetadata(MCStreamer &Streamer, Module &M) const override;
0135
0136 void emitLinkerDirectives(MCStreamer &Streamer, Module &M) const override;
0137
0138 MCSection *SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind,
0139 const TargetMachine &TM) const override;
0140
0141 MCSection *getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind,
0142 const TargetMachine &TM) const override;
0143
0144 MCSection *getSectionForConstant(const DataLayout &DL, SectionKind Kind,
0145 const Constant *C,
0146 Align &Alignment) const override;
0147
0148
0149 const MCExpr *getTTypeGlobalReference(const GlobalValue *GV,
0150 unsigned Encoding,
0151 const TargetMachine &TM,
0152 MachineModuleInfo *MMI,
0153 MCStreamer &Streamer) const override;
0154
0155
0156 MCSymbol *getCFIPersonalitySymbol(const GlobalValue *GV,
0157 const TargetMachine &TM,
0158 MachineModuleInfo *MMI) const override;
0159
0160
0161 const MCExpr *getIndirectSymViaGOTPCRel(const GlobalValue *GV,
0162 const MCSymbol *Sym,
0163 const MCValue &MV, int64_t Offset,
0164 MachineModuleInfo *MMI,
0165 MCStreamer &Streamer) const override;
0166
0167 void getNameWithPrefix(SmallVectorImpl<char> &OutName, const GlobalValue *GV,
0168 const TargetMachine &TM) const override;
0169
0170 MCSection *getSectionForCommandLines() const override;
0171 };
0172
0173 class TargetLoweringObjectFileCOFF : public TargetLoweringObjectFile {
0174 mutable unsigned NextUniqueID = 0;
0175 const TargetMachine *TM = nullptr;
0176
0177 public:
0178 ~TargetLoweringObjectFileCOFF() override = default;
0179
0180 void Initialize(MCContext &Ctx, const TargetMachine &TM) override;
0181 MCSection *getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind,
0182 const TargetMachine &TM) const override;
0183
0184 MCSection *SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind,
0185 const TargetMachine &TM) const override;
0186
0187 void getNameWithPrefix(SmallVectorImpl<char> &OutName, const GlobalValue *GV,
0188 const TargetMachine &TM) const override;
0189
0190 MCSection *getSectionForJumpTable(const Function &F,
0191 const TargetMachine &TM) const override;
0192
0193 bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
0194 const Function &F) const override;
0195
0196
0197 void emitModuleMetadata(MCStreamer &Streamer, Module &M) const override;
0198
0199 void emitLinkerDirectives(MCStreamer &Streamer, Module &M) const override;
0200
0201 MCSection *getStaticCtorSection(unsigned Priority,
0202 const MCSymbol *KeySym) const override;
0203 MCSection *getStaticDtorSection(unsigned Priority,
0204 const MCSymbol *KeySym) const override;
0205
0206 const MCExpr *lowerRelativeReference(const GlobalValue *LHS,
0207 const GlobalValue *RHS,
0208 const TargetMachine &TM) const override;
0209
0210
0211
0212 MCSection *getSectionForConstant(const DataLayout &DL, SectionKind Kind,
0213 const Constant *C,
0214 Align &Alignment) const override;
0215 };
0216
0217 class TargetLoweringObjectFileWasm : public TargetLoweringObjectFile {
0218 mutable unsigned NextUniqueID = 0;
0219 SmallPtrSet<GlobalObject *, 2> Used;
0220
0221 public:
0222 TargetLoweringObjectFileWasm() = default;
0223 ~TargetLoweringObjectFileWasm() override = default;
0224
0225 void getModuleMetadata(Module &M) override;
0226
0227 MCSection *getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind,
0228 const TargetMachine &TM) const override;
0229
0230 MCSection *SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind,
0231 const TargetMachine &TM) const override;
0232
0233 bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
0234 const Function &F) const override;
0235
0236 void InitializeWasm();
0237 MCSection *getStaticCtorSection(unsigned Priority,
0238 const MCSymbol *KeySym) const override;
0239 MCSection *getStaticDtorSection(unsigned Priority,
0240 const MCSymbol *KeySym) const override;
0241
0242 const MCExpr *lowerRelativeReference(const GlobalValue *LHS,
0243 const GlobalValue *RHS,
0244 const TargetMachine &TM) const override;
0245 };
0246
0247 class TargetLoweringObjectFileXCOFF : public TargetLoweringObjectFile {
0248 public:
0249 TargetLoweringObjectFileXCOFF() = default;
0250 ~TargetLoweringObjectFileXCOFF() override = default;
0251
0252 static bool ShouldEmitEHBlock(const MachineFunction *MF);
0253 static bool ShouldSetSSPCanaryBitInTB(const MachineFunction *MF);
0254
0255 static MCSymbol *getEHInfoTableSymbol(const MachineFunction *MF);
0256
0257 void Initialize(MCContext &Ctx, const TargetMachine &TM) override;
0258
0259 bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
0260 const Function &F) const override;
0261
0262 MCSection *getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind,
0263 const TargetMachine &TM) const override;
0264
0265 MCSection *getStaticCtorSection(unsigned Priority,
0266 const MCSymbol *KeySym) const override;
0267 MCSection *getStaticDtorSection(unsigned Priority,
0268 const MCSymbol *KeySym) const override;
0269
0270 const MCExpr *lowerRelativeReference(const GlobalValue *LHS,
0271 const GlobalValue *RHS,
0272 const TargetMachine &TM) const override;
0273
0274 MCSection *SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind,
0275 const TargetMachine &TM) const override;
0276
0277 MCSection *getSectionForJumpTable(const Function &F,
0278 const TargetMachine &TM) const override;
0279
0280
0281
0282 MCSection *getSectionForConstant(const DataLayout &DL, SectionKind Kind,
0283 const Constant *C,
0284 Align &Alignment) const override;
0285
0286 static XCOFF::StorageClass getStorageClassForGlobal(const GlobalValue *GV);
0287
0288 MCSection *
0289 getSectionForFunctionDescriptor(const Function *F,
0290 const TargetMachine &TM) const override;
0291 MCSection *getSectionForTOCEntry(const MCSymbol *Sym,
0292 const TargetMachine &TM) const override;
0293
0294
0295
0296 MCSection *
0297 getSectionForExternalReference(const GlobalObject *GO,
0298 const TargetMachine &TM) const override;
0299
0300
0301 MCSymbol *getTargetSymbol(const GlobalValue *GV,
0302 const TargetMachine &TM) const override;
0303
0304 MCSymbol *getFunctionEntryPointSymbol(const GlobalValue *Func,
0305 const TargetMachine &TM) const override;
0306
0307
0308
0309
0310
0311 MCSection *getSectionForLSDA(const Function &F, const MCSymbol &FnSym,
0312 const TargetMachine &TM) const override;
0313 };
0314
0315 class TargetLoweringObjectFileGOFF : public TargetLoweringObjectFile {
0316 public:
0317 TargetLoweringObjectFileGOFF();
0318 ~TargetLoweringObjectFileGOFF() override = default;
0319
0320 MCSection *SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind,
0321 const TargetMachine &TM) const override;
0322 MCSection *getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind,
0323 const TargetMachine &TM) const override;
0324 MCSection *getSectionForLSDA(const Function &F, const MCSymbol &FnSym,
0325 const TargetMachine &TM) const override;
0326 };
0327
0328 }
0329
0330 #endif