46 using namespace dwarf;
55 unsigned Encoding = getPersonalityEncoding();
57 return getContext().getOrCreateSymbol(
StringRef(
"DW.ref.") +
69 cast<MCSymbolELF>(getContext().getOrCreateSymbol(NameData));
93 MCSymbol *SSym = getSymbolWithGlobalValueBase(GV,
".DW.stub", TM);
105 Encoding & ~dwarf::DW_EH_PE_indirect, Streamer);
124 if (Name.
empty() || Name[0] !=
'.')
return K;
127 if (Name ==
".bss" ||
137 if (Name ==
".tdata" ||
143 if (Name ==
".tbss" ||
160 if (Name ==
".init_array")
163 if (Name ==
".fini_array")
166 if (Name ==
".preinit_array")
209 C->
getName() +
"' cannot be lowered.");
224 Group =
C->getName();
227 return getContext().getELFSection(SectionName,
248 return ".data.rel.ro";
255 unsigned Flags,
unsigned *NextUniqueID) {
256 unsigned EntrySize = 0;
282 Group =
C->getName();
292 cast<GlobalVariable>(GO));
294 std::string SizeSpec =
".rodata.str" +
utostr(EntrySize) +
".";
295 Name = SizeSpec +
utostr(Align);
297 Name =
".rodata.cst";
298 Name +=
utostr(EntrySize);
303 if (
const auto *
F = dyn_cast<Function>(GO)) {
304 const auto &OptionalPrefix =
F->getSectionPrefix();
306 Name += *OptionalPrefix;
309 if (EmitUniqueSection && UniqueSectionNames) {
314 if (EmitUniqueSection && !UniqueSectionNames) {
315 UniqueID = *NextUniqueID;
322 EntrySize, Group, UniqueID);
331 bool EmitUniqueSection =
false;
341 EmitUniqueSection, Flags, &NextUniqueID);
350 if (!EmitUniqueSection)
351 return ReadOnlySection;
359 bool UsesLabelDifference,
const Function &
F)
const {
369 unsigned &Align)
const {
371 return MergeableConst4Section;
373 return MergeableConst8Section;
375 return MergeableConst16Section;
377 return MergeableConst32Section;
379 return ReadOnlySection;
382 return DataRelROSection;
386 bool IsCtor,
unsigned Priority,
399 Name =
".init_array";
402 Name =
".fini_array";
404 if (Priority != 65535) {
415 if (Priority != 65535) {
417 Name +=
utostr(65535 - Priority);
426 unsigned Priority,
const MCSymbol *KeySym)
const {
432 unsigned Priority,
const MCSymbol *KeySym)
const {
459 UseInitArray = UseInitArray_;
507 unsigned VersionVal = 0;
508 unsigned ImageInfoFlags = 0;
509 MDNode *LinkerOptions =
nullptr;
512 for (
const auto &MFE : ModuleFlags) {
520 if (Key ==
"Objective-C Image Info Version") {
521 VersionVal = mdconst::extract<ConstantInt>(Val)->getZExtValue();
522 }
else if (Key ==
"Objective-C Garbage Collection" ||
523 Key ==
"Objective-C GC Only" ||
524 Key ==
"Objective-C Is Simulated" ||
525 Key ==
"Objective-C Class Properties" ||
526 Key ==
"Objective-C Image Swift Version") {
527 ImageInfoFlags |= mdconst::extract<ConstantInt>(Val)->getZExtValue();
528 }
else if (Key ==
"Objective-C Image Info Section") {
529 SectionVal = cast<MDString>(Val)->getString();
530 }
else if (Key ==
"Linker Options") {
531 LinkerOptions = cast<MDNode>(Val);
537 for (
const auto &Option : LinkerOptions->
operands()) {
539 for (
const auto &Piece : cast<MDNode>(Option)->operands())
540 StrOptions.
push_back(cast<MDString>(Piece)->getString());
546 if (SectionVal.
empty())
return;
549 unsigned TAA = 0, StubSize = 0;
551 std::string ErrorCode =
553 TAA, TAAParsed, StubSize);
554 if (!ErrorCode.empty())
564 getOrCreateSymbol(
StringRef(
"L_OBJC_IMAGE_INFO")));
576 "' cannot be lowered.");
583 unsigned TAA = 0, StubSize = 0;
588 std::string ErrorCode =
590 TAA, TAAParsed, StubSize);
591 if (!ErrorCode.empty()) {
594 "' has an invalid section specifier '" +
613 "' section type or attributes does not match previous"
614 " section specifier");
642 cast<GlobalVariable>(GO)) < 32)
650 cast<GlobalVariable>(GO)) < 32)
690 unsigned &Align)
const {
793 MCSymbol *Stub = Ctx.getOrCreateSymbol(Name);
798 StubValueTy(const_cast<MCSymbol *>(Sym),
true );
829 bool CannotUsePrivateLabel =
true;
833 CannotUsePrivateLabel =
882 assert(C &&
"expected GV to have a Comdat!");
888 "' does not exist.");
892 "' is not a key for its COMDAT.");
900 if (
const auto *GA = dyn_cast<GlobalAlias>(ComdatKey))
902 if (ComdatKey == GV) {
903 switch (
C->getSelectionKind()) {
938 COMDATSymName = Sym->
getName();
965 bool EmitUniquedSection;
986 if (EmitUniquedSection)
987 UniqueID = NextUniqueID++;
993 COMDATSymName, Selection, UniqueID);
998 Selection, UniqueID);
1023 bool CannotUsePrivateLabel =
false;
1027 CannotUsePrivateLabel =
true;
1038 if (!EmitUniqueSection)
1052 unsigned UniqueID = NextUniqueID++;
1061 MDNode *LinkerOptions =
nullptr;
1063 for (
const auto &MFE : ModuleFlags) {
1065 if (Key ==
"Linker Options")
1066 LinkerOptions = cast<MDNode>(MFE.Val);
1069 if (LinkerOptions) {
1075 for (
const auto &Option : LinkerOptions->
operands()) {
1076 for (
const auto &Piece : cast<MDNode>(Option)->operands()) {
1078 std::string Directive(
" ");
1079 Directive.append(cast<MDString>(Piece)->getString());
1112 unsigned Priority,
const MCSymbol *KeySym)
const {
1118 unsigned Priority,
const MCSymbol *KeySym)
const {
1141 OS << Flag.substr(1);
void getNameWithPrefix(SmallVectorImpl< char > &OutName, const GlobalValue *GV, const TargetMachine &TM) const override
PointerIntPair< MCSymbol *, 1, bool > StubValueTy
Instances of this class represent a uniqued identifier for a section in the current translation unit...
void push_back(const T &Elt)
A parsed version of the target data layout string in and methods for querying it. ...
static SectionKind getData()
bool isMergeableConst() const
StringRef getPrivateGlobalPrefix() const
MCSection * getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
Targets should implement this method to assign a section to globals with an explicit section specfied...
This represents a section on a Mach-O system (used by Mac OS X).
MCSection * getSectionForJumpTable(const Function &F, const TargetMachine &TM) const override
const MCSymbol & getSymbol() const
void getNameWithPrefix(SmallVectorImpl< char > &Name, const GlobalValue *GV, Mangler &Mang, bool MayAlwaysUsePrivate=false) const
MCSection * getStaticCtorSection(unsigned Priority, const MCSymbol *KeySym) const override
cl::opt< bool > UniqueSectionNames("unique-section-names", cl::desc("Give unique names to every section"), cl::init(true))
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
Reloc::Model getRelocationModel() const
Returns the code generation relocation model.
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
void EmitSymbolValue(const MCSymbol *Sym, unsigned Size, bool IsSectionRelative=false)
Special case of EmitValue that avoids the client having to pass in a MCExpr for MCSymbols.
.type _foo, STT_OBJECT # aka
This represents an "assembler immediate".
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
void emitLinkerFlagsForGlobal(raw_ostream &OS, const GlobalValue *GV) const override
virtual void AddBlankLine()
AddBlankLine - Emit a blank line to a .s file to pretty it up.
MCSection * ConstDataSection
MCSymbol * getCFIPersonalitySymbol(const GlobalValue *GV, const TargetMachine &TM, MachineModuleInfo *MMI) const override
void Initialize(MCContext &Ctx, const TargetMachine &TM) override
This method must be called before any actual lowering is done.
MCSection * SixteenByteConstantSection
MCSymbol * getSymbol(const GlobalValue *GV) const
MCSection * TextSection
Section directive for standard text.
MCSection * StaticCtorSection
This section contains the static constructor pointer list.
MCSection * ConstTextCoalSection
virtual void EmitBytes(StringRef Data)
Emit the bytes in Data into the output.
Mangler & getMangler() const
MCSection * DataCoalSection
Type * getValueType() const
static void checkMachOComdat(const GlobalValue *GV)
bool isMergeable2ByteCString() const
MCSymbol * getCFIPersonalitySymbol(const GlobalValue *GV, const TargetMachine &TM, MachineModuleInfo *MMI) const override
bool isReadOnlyWithRel() const
The data referenced by the COMDAT must be the same size.
MCSection * getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
Targets should implement this method to assign a section to globals with an explicit section specfied...
virtual bool isSectionAtomizableBySymbols(const MCSection &Section) const
True if the section is atomized using the symbols in it.
void emitPersonalityValue(MCStreamer &Streamer, const DataLayout &TM, const MCSymbol *Sym) const override
MCSection * getSectionForConstant(const DataLayout &DL, SectionKind Kind, const Constant *C, unsigned &Align) const override
Given a constant with the SectionKind, return a section that it should be placed in.
MCSection * getSectionForJumpTable(const Function &F, const TargetMachine &TM) const override
const MCExpr * getIndirectSymViaGOTPCRel(const MCSymbol *Sym, const MCValue &MV, int64_t Offset, MachineModuleInfo *MMI, MCStreamer &Streamer) const override
Get MachO PC relative GOT entry relocation.
static bool isThumb(const MCSubtargetInfo &STI)
bool isMergeableCString() const
char getGlobalPrefix() const
MCSectionCOFF * getCOFFSection(StringRef Section, unsigned Characteristics, SectionKind Kind, StringRef COMDATSymName, int Selection, unsigned UniqueID=GenericSectionID, const char *BeginSymName=nullptr)
StringRef getName() const
Return a constant reference to the value's name.
MCSectionCOFF * getAssociativeCOFFSection(MCSectionCOFF *Sec, const MCSymbol *KeySym, unsigned UniqueID=GenericSectionID)
Gets or creates a section equivalent to Sec that is associated with the section containing KeySym...
const Triple & getTargetTriple() const
Adds a requirement that another module flag be present and have a specified value after linking is pe...
MCSection * SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
bool hasDLLExportStorageClass() const
static SectionKind getBSS()
struct fuzzer::@269 Flags
unsigned getPointerABIAlignment(unsigned AS=0) const
Layout pointer alignment FIXME: The defaults need to be removed once all of the backends/clients are ...
const MCAsmInfo * getMCAsmInfo() const
Return target specific asm information.
MCSection * SectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const
This method computes the appropriate section to emit the specified global variable or function defini...
virtual void Initialize(MCContext &ctx, const TargetMachine &TM)
This method must be called before any actual lowering is done.
Base class for the full range of assembler expressions which are needed for parsing.
const MCExpr * getTTypeReference(const MCSymbolRefExpr *Sym, unsigned Encoding, MCStreamer &Streamer) const
const Module * getModule() const
StringRef getInstrProfCoverageSectionName(bool AddSegment)
Return the name of the section containing function coverage mapping data.
The linker may choose any COMDAT.
MCSection * EightByteConstantSection
S_MOD_TERM_FUNC_POINTERS - Section with only function pointers for termination.
StringRef getName() const
MCSection * TLSDataSection
Section directive for Thread Local data. ELF, MachO and COFF.
bool hasPrivateLinkage() const
static const GlobalValue * getComdatGVForCOFF(const GlobalValue *GV)
MCSection * SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
Context object for machine code objects.
bool isMergeable4ByteCString() const
bool isMergeableConst32() const
MCSection * DataCommonSection
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
static const MCBinaryExpr * createSub(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
PointerTy getPointer() const
MCSectionMachO * getMachOSection(StringRef Segment, StringRef Section, unsigned TypeAndAttributes, unsigned Reserved2, SectionKind K, const char *BeginSymName=nullptr)
Return the MCSection for the specified mach-o section.
MCSection * StaticDtorSection
This section contains the static destructor pointer list.
MCSection * getStaticDtorSection(unsigned Priority, const MCSymbol *KeySym) const override
S_ATTR_NO_DEAD_STRIP - No dead stripping.
StringRef getSection() const
Get the custom section of this global if it has one.
void Initialize(MCContext &Ctx, const TargetMachine &TM) override
This method must be called before any actual lowering is done.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
static std::string utostr(uint64_t X, bool isNeg=false)
unsigned getStubSize() const
ArchType getArch() const
getArch - Get the parsed architecture type of this triple.
static SectionKind getThreadData()
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
MCContext & getContext() const
const Triple & getTargetTriple() const
virtual void EmitIntValue(uint64_t Value, unsigned Size)
Special case of EmitValue that avoids the client having to pass in a MCExpr for constant integers...
MCSection * DataSection
Section directive for standard data.
bool isMergeableConst16() const
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
void getNameWithPrefix(SmallVectorImpl< char > &OutName, const GlobalValue *GV, const TargetMachine &TM) const override
Flag
These should be considered private to the implementation of the MCInstrDesc class.
static bool isWeakForLinker(LinkageTypes Linkage)
Whether the definition of this global may be replaced at link time.
This class is intended to be used as a base class for asm properties and features specific to the tar...
No other Module may specify this COMDAT.
Streaming machine code generation interface.
static std::string ParseSectionSpecifier(StringRef Spec, StringRef &Segment, StringRef &Section, unsigned &TAA, bool &TAAParsed, unsigned &StubSize)
Parse the section specifier indicated by "Spec".
bool isWindowsGNUEnvironment() const
PointerIntPair - This class implements a pair of a pointer and small integer.
const Comdat * getComdat() const
This is an important base class in LLVM.
virtual void SwitchSection(MCSection *Section, const MCExpr *Subsection=nullptr)
Set the current section where code is being emitted to Section.
const MCExpr * getTTypeGlobalReference(const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM, MachineModuleInfo *MMI, MCStreamer &Streamer) const override
Return an MCExpr to use for a reference to the specified type info global variable from exception han...
This file contains the declarations for the subclasses of Constant, which represent the different fla...
bool hasAttribute(unsigned Value) const
bool isThreadData() const
static SectionKind getELFKindForNamedSection(StringRef Name, SectionKind K)
bool isMergeable1ByteCString() const
void InitializeELF(bool UseInitArray_)
virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value=0, unsigned ValueSize=1, unsigned MaxBytesToEmit=0)
Emit some number of copies of Value until the byte alignment ByteAlignment is reached.
virtual bool EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute)=0
Add the given Attribute to Symbol.
SectionKind - This is a simple POD value that classifies the properties of a section.
MCSection * UStringSection
MCSection * getDrectveSection() const
SelectionKind getSelectionKind() const
MCSection * getSectionForConstant(const DataLayout &DL, SectionKind Kind, const Constant *C, unsigned &Align) const override
Given a constant with the SectionKind, return a section that it should be placed in.
Ty & getObjFileInfo()
Keep track of various per-function pieces of information for backends that would like to do so...
The data referenced by the COMDAT must be the same.
bool isExecuteOnly() const
bool isThreadLocal() const
If the value is "Thread Local", its value isn't shared by the threads.
bool getFunctionSections() const
Return true if functions should be emitted into their own section, corresponding to -ffunction-sectio...
const MCSymbolRefExpr * getSymB() const
StubValueTy & getGVStubEntry(MCSymbol *Sym)
static const char * getCOFFSectionNameForUniqueGlobal(SectionKind Kind)
StubValueTy & getGVStubEntry(MCSymbol *Sym)
MCSection * getStaticDtorSection(unsigned Priority, const MCSymbol *KeySym) const override
virtual const MCExpr * getTTypeGlobalReference(const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM, MachineModuleInfo *MMI, MCStreamer &Streamer) const
Return an MCExpr to use for a reference to the specified global variable from exception handling info...
bool isThreadLocal() const
unsigned getPreferredAlignment(const GlobalVariable *GV) const
Returns the preferred alignment of the specified global.
Triple - Helper class for working with autoconf configuration names.
bool getDataSections() const
Return true if data objects should be emitted into their own section, corresponds to -fdata-sections...
const MCExpr * getTTypeGlobalReference(const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM, MachineModuleInfo *MMI, MCStreamer &Streamer) const override
The mach-o version of this method defaults to returning a stub reference.
bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference, const Function &F) const override
bool hasExternalLinkage() const
bool hasGlobalUnnamedAddr() const
static SectionKind getThreadBSS()
bool isFunctionTy() const
True if this is an instance of FunctionType.
virtual void EmitLabel(MCSymbol *Symbol)
Emit a label for Symbol into the current section.
static bool canUsePrivateLabel(const MCAsmInfo &AsmInfo, const MCSection &Section)
Module.h This file contains the declarations for the Module class.
static SectionKind getMetadata()
MCSection * DataBSSSection
static const Comdat * getELFComdat(const GlobalValue *GV)
The linker will choose the largest COMDAT.
bool getUniqueSectionNames() const
bool isMergeableConst8() const
static MCSectionELF * selectELFSectionForGlobal(MCContext &Ctx, const GlobalObject *GO, SectionKind Kind, Mangler &Mang, const TargetMachine &TM, bool EmitUniqueSection, unsigned Flags, unsigned *NextUniqueID)
static GCRegistry::Add< ShadowStackGC > C("shadow-stack","Very portable GC for uncooperative code generators")
Pass this value as the UniqueID during section creation to get the generic section with the given nam...
TargetLoweringObjectFileMachO()
const GlobalObject * getBaseObject() const
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
static StringRef getSectionPrefixForGlobal(SectionKind Kind)
Return the section prefix name used by options FunctionsSections and DataSections.
MCSection * FourByteConstantSection
MachineModuleInfoELF - This is a MachineModuleInfoImpl implementation for ELF targets.
const MCExpr * lowerRelativeReference(const GlobalValue *LHS, const GlobalValue *RHS, const TargetMachine &TM) const override
PointerType * getType() const
Global values are always pointers.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
StringRef getName() const
getName - Get the symbol name.
MCSection * getStaticCtorSection(unsigned Priority, const MCSymbol *KeySym) const override
virtual void EmitLinkerOptions(ArrayRef< std::string > Kind)
Emit the given list Options of strings as linker options into the output.
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
void getNameWithPrefix(raw_ostream &OS, const GlobalValue *GV, bool CannotUsePrivateLabel) const
Print the appropriate prefix and the specified global variable's name.
MCSection * SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
bool isWindowsCygwinEnvironment() const
static int getSelectionForCOFF(const GlobalValue *GV)
COFFYAML::WeakExternalCharacteristics Characteristics
virtual void emitELFSize(MCSymbol *Symbol, const MCExpr *Value)
Emit an ELF .size directive.
static unsigned getCOFFSectionFlags(SectionKind K, const TargetMachine &TM)
This represents a section on linux, lots of unix variants and some bare metal systems.
op_range operands() const
MachineModuleInfoMachO - This is a MachineModuleInfoImpl implementation for MachO targets...
void emitModuleFlags(MCStreamer &Streamer, ArrayRef< Module::ModuleFlagEntry > ModuleFlags, const TargetMachine &TM) const override
Emit Obj-C garbage collection and linker options.
bool hasLocalLinkage() const
MCSymbol * getSymbolWithGlobalValueBase(const GlobalValue *GV, StringRef Suffix, const TargetMachine &TM) const
Return the MCSymbol for a private symbol with global value name as its base, with the specified suffi...
MCSection * TLSBSSSection
Section directive for Thread Local uninitialized data.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
MCSection * TextCoalSection
int64_t getConstant() const
A raw_ostream that writes to an std::string.
MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags)
unsigned getTypeAndAttributes() const
static MCSectionELF * getStaticStructorSection(MCContext &Ctx, bool UseInitArray, bool IsCtor, unsigned Priority, const MCSymbol *KeySym)
Module * getParent()
Get the module that this global value is contained inside of...
MCSection * CStringSection
bool isMergeableConst4() const
bool isKnownWindowsMSVCEnvironment() const
Checks if the environment is MSVC.
bool isWindowsItaniumEnvironment() const
MCSection * getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
Targets should implement this method to assign a section to globals with an explicit section specfied...
This class implements an extremely fast bulk output stream that can only output to a stream...
bool SupportIndirectSymViaGOTPCRel
Primary interface to the complete machine description for the target machine.
MCSection * BSSSection
Section that is default initialized to zero.
StringRef - Represent a constant reference to a string, i.e.
MCSection * ReadOnlySection
Section that is readonly and can contain arbitrary initialized data.
static unsigned getELFSectionFlags(SectionKind K)
static SectionKind getKindForGlobal(const GlobalObject *GO, const TargetMachine &TM)
Classify the specified global variable into a set of target independent categories embodied in Sectio...
void emitModuleFlags(MCStreamer &Streamer, ArrayRef< Module::ModuleFlagEntry > ModuleFlags, const TargetMachine &TM) const override
Emit the module flags that specify the garbage collection information.
S_MOD_INIT_FUNC_POINTERS - Section with only function pointers for initialization.
unsigned getPointerSize(unsigned AS=0) const
Layout pointer size FIXME: The defaults need to be removed once all of the backends/clients are updat...
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
static SectionKind getReadOnly()
static unsigned getELFSectionType(StringRef Name, SectionKind K)
This class can be derived from and used by targets to hold private target-specific information for ea...
GlobalValue * getNamedValue(StringRef Name) const
Return the global value in the module with the specified name, of arbitrary type. ...
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx)
This class contains meta information specific to a module.
This file describes how to lower LLVM code to machine code.