1 //===-- llvm/Target/TargetLoweringObjectFile.h - Object Info ----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements classes used to handle lowerings specific to common
11 // object file formats.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_TARGET_TARGETLOWERINGOBJECTFILE_H
16 #define LLVM_TARGET_TARGETLOWERINGOBJECTFILE_H
18 #include "llvm/ADT/ArrayRef.h"
19 #include "llvm/IR/Module.h"
20 #include "llvm/MC/MCObjectFileInfo.h"
21 #include "llvm/MC/SectionKind.h"
24 class MachineModuleInfo;
30 class MCSymbolRefExpr;
36 class TargetLoweringObjectFile : public MCObjectFileInfo {
40 TargetLoweringObjectFile(
41 const TargetLoweringObjectFile&) = delete;
42 void operator=(const TargetLoweringObjectFile&) = delete;
45 bool SupportIndirectSymViaGOTPCRel;
48 MCContext &getContext() const { return *Ctx; }
50 TargetLoweringObjectFile() : MCObjectFileInfo(), Ctx(nullptr), DL(nullptr),
51 SupportIndirectSymViaGOTPCRel(false) {}
53 virtual ~TargetLoweringObjectFile();
55 /// This method must be called before any actual lowering is done. This
56 /// specifies the current context for codegen, and gives the lowering
57 /// implementations a chance to set up their default sections.
58 virtual void Initialize(MCContext &ctx, const TargetMachine &TM);
60 virtual void emitPersonalityValue(MCStreamer &Streamer,
61 const TargetMachine &TM,
62 const MCSymbol *Sym) const;
64 /// Extract the dependent library name from a linker option string. Returns
65 /// StringRef() if the option does not specify a library.
66 virtual StringRef getDepLibFromLinkerOpt(StringRef LinkerOption) const {
70 /// Emit the module flags that the platform cares about.
71 virtual void emitModuleFlags(MCStreamer &Streamer,
72 ArrayRef<Module::ModuleFlagEntry> Flags,
73 Mangler &Mang, const TargetMachine &TM) const {}
75 /// Given a constant with the SectionKind, return a section that it should be
77 virtual const MCSection *getSectionForConstant(SectionKind Kind,
78 const Constant *C) const;
80 /// Classify the specified global variable into a set of target independent
81 /// categories embodied in SectionKind.
82 static SectionKind getKindForGlobal(const GlobalValue *GV,
83 const TargetMachine &TM);
85 /// This method computes the appropriate section to emit the specified global
86 /// variable or function definition. This should not be passed external (or
87 /// available externally) globals.
88 const MCSection *SectionForGlobal(const GlobalValue *GV,
89 SectionKind Kind, Mangler &Mang,
90 const TargetMachine &TM) const;
92 /// This method computes the appropriate section to emit the specified global
93 /// variable or function definition. This should not be passed external (or
94 /// available externally) globals.
95 const MCSection *SectionForGlobal(const GlobalValue *GV,
97 const TargetMachine &TM) const {
98 return SectionForGlobal(GV, getKindForGlobal(GV, TM), Mang, TM);
101 virtual const MCSection *
102 getSectionForJumpTable(const Function &F, Mangler &Mang,
103 const TargetMachine &TM) const;
105 virtual bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
106 const Function &F) const;
108 /// Targets should implement this method to assign a section to globals with
109 /// an explicit section specfied. The implementation of this method can
110 /// assume that GV->hasSection() is true.
111 virtual const MCSection *
112 getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
113 Mangler &Mang, const TargetMachine &TM) const = 0;
115 /// Allow the target to completely override section assignment of a global.
116 virtual const MCSection *getSpecialCasedSectionGlobals(const GlobalValue *GV,
118 Mangler &Mang) const {
122 /// Return an MCExpr to use for a reference to the specified global variable
123 /// from exception handling information.
124 virtual const MCExpr *
125 getTTypeGlobalReference(const GlobalValue *GV, unsigned Encoding,
126 Mangler &Mang, const TargetMachine &TM,
127 MachineModuleInfo *MMI, MCStreamer &Streamer) const;
129 /// Return the MCSymbol for a private symbol with global value name as its
130 /// base, with the specified suffix.
131 MCSymbol *getSymbolWithGlobalValueBase(const GlobalValue *GV,
132 StringRef Suffix, Mangler &Mang,
133 const TargetMachine &TM) const;
135 // The symbol that gets passed to .cfi_personality.
136 virtual MCSymbol *getCFIPersonalitySymbol(const GlobalValue *GV,
138 const TargetMachine &TM,
139 MachineModuleInfo *MMI) const;
142 getTTypeReference(const MCSymbolRefExpr *Sym, unsigned Encoding,
143 MCStreamer &Streamer) const;
145 virtual const MCSection *getStaticCtorSection(unsigned Priority,
146 const MCSymbol *KeySym) const {
147 return StaticCtorSection;
150 virtual const MCSection *getStaticDtorSection(unsigned Priority,
151 const MCSymbol *KeySym) const {
152 return StaticDtorSection;
155 /// \brief Create a symbol reference to describe the given TLS variable when
156 /// emitting the address in debug info.
157 virtual const MCExpr *getDebugThreadLocalSymbol(const MCSymbol *Sym) const;
159 virtual const MCExpr *
160 getExecutableRelativeSymbol(const ConstantExpr *CE, Mangler &Mang,
161 const TargetMachine &TM) const {
165 /// \brief Target supports replacing a data "PC"-relative access to a symbol
166 /// through another symbol, by accessing the later via a GOT entry instead?
167 bool supportIndirectSymViaGOTPCRel() const {
168 return SupportIndirectSymViaGOTPCRel;
171 /// \brief Get the target specific PC relative GOT entry relocation
172 virtual const MCExpr *getIndirectSymViaGOTPCRel(const MCSymbol *Sym,
173 int64_t Offset) const {
178 virtual const MCSection *
179 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
180 Mangler &Mang, const TargetMachine &TM) const = 0;
183 } // end namespace llvm