43 using namespace dwarf;
52 unsigned Encoding = getPersonalityEncoding();
54 return getContext().getOrCreateSymbol(
StringRef(
"DW.ref.") +
67 cast<MCSymbolELF>(getContext().getOrCreateSymbol(NameData));
94 MCSymbol *SSym = getSymbolWithGlobalValueBase(GV,
".DW.stub", Mang, TM);
106 Encoding & ~dwarf::DW_EH_PE_indirect, Streamer);
121 if (Name.
empty() || Name[0] !=
'.')
return K;
124 if (Name ==
".bss" ||
134 if (Name ==
".tdata" ||
140 if (Name ==
".tbss" ||
152 if (Name ==
".init_array")
155 if (Name ==
".fini_array")
158 if (Name ==
".preinit_array")
198 C->
getName() +
"' cannot be lowered.");
214 Group = C->getName();
217 return getContext().getELFSection(SectionName,
238 return ".data.rel.local";
242 return ".data.rel.ro.local";
244 return ".data.rel.ro";
251 unsigned Flags,
unsigned *NextUniqueID) {
252 unsigned EntrySize = 0;
276 Group = C->getName();
288 std::string SizeSpec =
".rodata.str" +
utostr(EntrySize) +
".";
289 Name = SizeSpec +
utostr(Align);
291 Name =
".rodata.cst";
292 Name +=
utostr(EntrySize);
297 if (EmitUniqueSection && UniqueSectionNames) {
301 unsigned UniqueID = ~0;
302 if (EmitUniqueSection && !UniqueSectionNames) {
303 UniqueID = *NextUniqueID;
307 EntrySize, Group, UniqueID);
317 bool EmitUniqueSection =
false;
327 EmitUniqueSection, Flags, &NextUniqueID);
336 if (!EmitUniqueSection)
337 return ReadOnlySection;
345 bool UsesLabelDifference,
const Function &
F)
const {
357 return MergeableConst4Section;
359 return MergeableConst8Section;
361 return MergeableConst16Section;
363 return ReadOnlySection;
367 return DataRelROSection;
371 bool IsCtor,
unsigned Priority,
384 Name =
".init_array";
387 Name =
".fini_array";
389 if (Priority != 65535) {
400 if (Priority != 65535) {
402 Name +=
utostr(65535 - Priority);
411 unsigned Priority,
const MCSymbol *KeySym)
const {
417 unsigned Priority,
const MCSymbol *KeySym)
const {
424 UseInitArray = UseInitArray_;
428 StaticCtorSection = getContext().getELFSection(
430 StaticDtorSection = getContext().getELFSection(
448 unsigned VersionVal = 0;
449 unsigned ImageInfoFlags = 0;
450 MDNode *LinkerOptions =
nullptr;
454 i = ModuleFlags.
begin(), e = ModuleFlags.
end(); i != e; ++i) {
464 if (Key ==
"Objective-C Image Info Version") {
465 VersionVal = mdconst::extract<ConstantInt>(Val)->getZExtValue();
466 }
else if (Key ==
"Objective-C Garbage Collection" ||
467 Key ==
"Objective-C GC Only" ||
468 Key ==
"Objective-C Is Simulated" ||
469 Key ==
"Objective-C Image Swift Version") {
470 ImageInfoFlags |= mdconst::extract<ConstantInt>(Val)->getZExtValue();
471 }
else if (Key ==
"Objective-C Image Info Section") {
472 SectionVal = cast<MDString>(Val)->
getString();
473 }
else if (Key ==
"Linker Options") {
474 LinkerOptions = cast<MDNode>(Val);
480 for (
unsigned i = 0, e = LinkerOptions->
getNumOperands(); i != e; ++i) {
485 for (
unsigned ii = 0, ie = MDOptions->
getNumOperands(); ii != ie; ++ii) {
487 StrOptions.push_back(MDOption->
getString());
495 if (SectionVal.
empty())
return;
498 unsigned TAA = 0, StubSize = 0;
500 std::string ErrorCode =
502 TAA, TAAParsed, StubSize);
503 if (!ErrorCode.empty())
513 getOrCreateSymbol(
StringRef(
"L_OBJC_IMAGE_INFO")));
525 "' cannot be lowered.");
533 unsigned TAA = 0, StubSize = 0;
538 std::string ErrorCode =
540 TAA, TAAParsed, StubSize);
541 if (!ErrorCode.empty()) {
544 "' has an invalid section specifier '" +
563 "' section type or attributes does not match previous"
564 " section specifier");
746 MCSymbol *Stub = Ctx.getOrCreateSymbol(Name);
751 StubValueTy(const_cast<MCSymbol *>(Sym),
true );
807 assert(C &&
"expected GV to have a Comdat!");
813 "' does not exist.");
817 "' is not a key for its COMDAT.");
825 if (
const auto *GA = dyn_cast<GlobalAlias>(ComdatKey))
826 ComdatKey = GA->getBaseObject();
827 if (ComdatKey == GV) {
828 switch (C->getSelectionKind()) {
864 COMDATSymName = Sym->
getName();
894 bool EmitUniquedSection;
918 COMDATSymName, Selection);
951 CannotUsePrivateLabel =
true;
962 if (!EmitUniqueSection)
985 MDNode *LinkerOptions =
nullptr;
989 i = ModuleFlags.
begin(), e = ModuleFlags.
end(); i != e; ++i) {
993 if (Key ==
"Linker Options") {
994 LinkerOptions = cast<MDNode>(Val);
1005 for (
unsigned i = 0, e = LinkerOptions->
getNumOperands(); i != e; ++i) {
1007 for (
unsigned ii = 0, ie = MDOptions->
getNumOperands(); ii != ie; ++ii) {
1010 std::string Directive(
" ");
1011 Directive.append(MDOption->
getString());
1018 unsigned Priority,
const MCSymbol *KeySym)
const {
1024 unsigned Priority,
const MCSymbol *KeySym)
const {
1047 OS << Flag.substr(1);
PointerIntPair< MCSymbol *, 1, bool > StubValueTy
StubValueTy & getHiddenGVStubEntry(MCSymbol *Sym)
Instances of this class represent a uniqued identifier for a section in the current translation unit...
void push_back(const T &Elt)
bool isMergeableConst() const
MCSectionMachO - This represents a section on a Mach-O system (used by Mac OS X). ...
MCSection * getSectionForConstant(SectionKind Kind, const Constant *C) const override
Given a constant with the SectionKind, return a section that it should be placed in.
const MCSymbol & getSymbol() const
void getNameWithPrefix(SmallVectorImpl< char > &Name, const GlobalValue *GV, Mangler &Mang, bool MayAlwaysUsePrivate=false) const
const MCExpr * getTTypeGlobalReference(const GlobalValue *GV, unsigned Encoding, Mangler &Mang, 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...
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)
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".
static MCSectionELF * selectELFSectionForGlobal(MCContext &Ctx, const GlobalValue *GV, SectionKind Kind, Mangler &Mang, const TargetMachine &TM, bool EmitUniqueSection, unsigned Flags, unsigned *NextUniqueID)
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
virtual void AddBlankLine()
AddBlankLine - Emit a blank line to a .s file to pretty it up.
MCSection * ConstDataSection
MCSection * SixteenByteConstantSection
MCSectionELF * getELFSection(StringRef Section, unsigned Type, unsigned Flags)
unsigned getNumOperands() const
Return number of MDNode operands.
MCSection * TextSection
Section directive for standard text.
void emitPersonalityValue(MCStreamer &Streamer, const TargetMachine &TM, const MCSymbol *Sym) const override
MCSection * ConstTextCoalSection
virtual void EmitBytes(StringRef Data)
Emit the bytes in Data into the output.
MCSection * DataCoalSection
Type * getValueType() const
static void checkMachOComdat(const GlobalValue *GV)
bool isMergeable2ByteCString() const
MCSection * getSectionForJumpTable(const Function &F, Mangler &Mang, const TargetMachine &TM) const override
const char * getPrivateGlobalPrefix() const
bool isReadOnlyWithRel() const
The data referenced by the COMDAT must be the same size.
const char * getSection() const
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.
const MCExpr * getTTypeGlobalReference(const GlobalValue *GV, unsigned Encoding, Mangler &Mang, const TargetMachine &TM, MachineModuleInfo *MMI, MCStreamer &Streamer) const override
The mach-o version of this method defaults to returning a stub reference.
bool isMergeableCString() const
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(const char *reason, bool gen_crash_diag=true)
Reports a serious error, calling any installed error handler.
char getGlobalPrefix() const
StringRef getName() const
Return a constant reference to the value's name.
virtual void emitELFSize(MCSymbolELF *Symbol, const MCExpr *Value)
Emit an ELF .size directive.
Adds a requirement that another module flag be present and have a specified value after linking is pe...
bool hasDLLExportStorageClass() const
static SectionKind getBSS()
unsigned getPointerABIAlignment(unsigned AS=0) const
Layout pointer alignment FIXME: The defaults need to be removed once all of the backends/clients are ...
MCSymbol * getCFIPersonalitySymbol(const GlobalValue *GV, Mangler &Mang, const TargetMachine &TM, MachineModuleInfo *MMI) const override
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
MCSection * StaticDtorSection
This section contains the static destructor pointer list.
The linker may choose any COMDAT.
static unsigned getCOFFSectionFlags(SectionKind K)
MCSection * EightByteConstantSection
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)
Context object for machine code objects.
bool isMergeable4ByteCString() const
MCSection * DataCommonSection
MCSection * getSectionForJumpTable(const Function &F, Mangler &Mang, const TargetMachine &TM) const override
static const MCBinaryExpr * createSub(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
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 * getStaticDtorSection(unsigned Priority, const MCSymbol *KeySym) const override
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
MCSection * getSectionForConstant(SectionKind Kind, const Constant *C) const override
Given a constant with the SectionKind, return a section that it should be placed in.
static SectionKind getThreadData()
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
MCContext & getContext() const
MCSymbol * getSymbolWithGlobalValueBase(const GlobalValue *GV, StringRef Suffix, Mangler &Mang, const TargetMachine &TM) const
Return the MCSymbol for a private symbol with global value name as its base, with the specified suffi...
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
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.
No other Module may specify this COMDAT.
Streaming machine code generation interface.
MCSection * SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, Mangler &Mang, const TargetMachine &TM) const override
static std::string ParseSectionSpecifier(StringRef Spec, StringRef &Segment, StringRef &Section, unsigned &TAA, bool &TAAParsed, unsigned &StubSize)
ParseSectionSpecifier - 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.
bool hasHiddenVisibility() const
This file contains the declarations for the subclasses of Constant, which represent the different fla...
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
Ty & getObjFileInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
The data referenced by the COMDAT must be the same.
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 * StaticCtorSection
This section contains the static constructor pointer list.
MCSymbol * getSymbol(const GlobalValue *GV, Mangler &Mang) const
MCSection * getStaticDtorSection(unsigned Priority, const MCSymbol *KeySym) const override
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...
bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference, const Function &F) const override
StringRef getString() const
bool hasExternalLinkage() const
const MDOperand & getOperand(unsigned I) const
PointerTy getPointer() const
bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
static SectionKind getThreadBSS()
bool isFunctionTy() const
isFunctionTy - True if this is an instance of FunctionType.
virtual void EmitLabel(MCSymbol *Symbol)
Emit a label for Symbol into the current section.
MCSymbol * getCFIPersonalitySymbol(const GlobalValue *GV, Mangler &Mang, const TargetMachine &TM, MachineModuleInfo *MMI) const override
const DataLayout * getDataLayout() const
Deprecated in 3.7, will be removed in 3.8.
static SectionKind getDataNoRel()
Module.h This file contains the declarations for the Module class.
MCSection * DataBSSSection
static const Comdat * getELFComdat(const GlobalValue *GV)
The linker will choose the largest COMDAT.
bool getUniqueSectionNames() const
bool isMergeableConst8() const
static cl::opt< AlignMode > Align(cl::desc("Load/store alignment support"), cl::Hidden, cl::init(NoStrictAlign), cl::values(clEnumValN(StrictAlign,"aarch64-strict-align","Disallow all unaligned memory accesses"), clEnumValN(NoStrictAlign,"aarch64-no-strict-align","Allow unaligned memory accesses"), clEnumValEnd))
MCSection * getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, Mangler &Mang, const TargetMachine &TM) const override
Targets should implement this method to assign a section to globals with an explicit section specfied...
TargetLoweringObjectFileMachO()
MCSection * SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, Mangler &Mang, const TargetMachine &TM) const override
static StringRef getSectionPrefixForGlobal(SectionKind Kind)
Return the section prefix name used by options FunctionsSections and DataSections.
iterator insert(iterator I, T &&Elt)
virtual const MCExpr * getTTypeGlobalReference(const GlobalValue *GV, unsigned Encoding, Mangler &Mang, 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...
MCSection * FourByteConstantSection
MachineModuleInfoELF - This is a MachineModuleInfoImpl implementation for ELF targets.
void emitModuleFlags(MCStreamer &Streamer, ArrayRef< Module::ModuleFlagEntry > ModuleFlags, Mangler &Mang, const TargetMachine &TM) const override
Emit the module flags that specify the garbage collection information.
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...
MCSectionCOFF * getAssociativeCOFFSection(MCSectionCOFF *Sec, const MCSymbol *KeySym)
Gets or creates a section equivalent to Sec that is associated with the section containing KeySym...
void getNameWithPrefix(raw_ostream &OS, const GlobalValue *GV, bool CannotUsePrivateLabel) const
Print the appropriate prefix and the specified global variable's name.
bool isWindowsCygwinEnvironment() const
static int getSelectionForCOFF(const GlobalValue *GV)
COFFYAML::WeakExternalCharacteristics Characteristics
MCSection * getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, Mangler &Mang, const TargetMachine &TM) const override
Targets should implement this method to assign a section to globals with an explicit section specfied...
void emitModuleFlags(MCStreamer &Streamer, ArrayRef< Module::ModuleFlagEntry > ModuleFlags, Mangler &Mang, const TargetMachine &TM) const override
Emit Obj-C garbage collection and linker options.
MCSectionELF - This represents a section on linux, lots of unix variants and some bare metal systems...
MachineModuleInfoMachO - This is a MachineModuleInfoImpl implementation for MachO targets...
MCSectionCOFF * getCOFFSection(StringRef Section, unsigned Characteristics, SectionKind Kind, StringRef COMDATSymName, int Selection, const char *BeginSymName=nullptr)
bool hasLocalLinkage() const
MCSection * TLSBSSSection
Section directive for Thread Local uninitialized data.
MCSection * TextCoalSection
int64_t getConstant() const
const ARM::ArchExtKind Kind
A raw_ostream that writes to an std::string.
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
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.
bool isReadOnlyWithRelLocal() const
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)
void emitLinkerFlagsForGlobal(raw_ostream &OS, const GlobalValue *GV, const Mangler &Mang) const override
MCSection * SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, Mangler &Mang, const TargetMachine &TM) const override
unsigned getPointerSize(unsigned AS=0) const
Layout pointer size FIXME: The defaults need to be removed once all of the backends/clients are updat...
void getNameWithPrefix(SmallVectorImpl< char > &OutName, const GlobalValue *GV, bool CannotUsePrivateLabel, Mangler &Mang, const TargetMachine &TM) const override
static SectionKind getReadOnly()
static unsigned getELFSectionType(StringRef Name, SectionKind K)
bool isDataRelLocal() const
MachineModuleInfoImpl - This class can be derived from and used by targets to hold private target-spe...
MCSection * getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, Mangler &Mang, const TargetMachine &TM) const override
Targets should implement this method to assign a section to globals with an explicit section specfied...
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)
MachineModuleInfo - This class contains meta information specific to a module.
This file describes how to lower LLVM code to machine code.
bool empty() const
empty - Check if the string is empty.