40 using namespace dwarf;
50 unsigned Encoding = getPersonalityEncoding();
51 switch (Encoding & 0x70) {
55 return getSymbol(*Mang, GV);
57 return getContext().GetOrCreateSymbol(
StringRef(
"DW.ref.") +
58 getSymbol(*Mang, GV)->
getName());
68 MCSymbol *Label = getContext().GetOrCreateSymbol(NameData);
73 unsigned Flags = ELF::SHF_ALLOC | ELF::SHF_WRITE | ELF::SHF_GROUP;
74 const MCSection *Sec = getContext().getELFSection(NameData,
104 MCSymbol *SSym = getContext().GetOrCreateSymbol(Name.str());
107 MCSymbol *Sym = getSymbol(*Mang, GV);
113 Encoding & ~dwarf::DW_EH_PE_indirect, Streamer);
128 if (Name.
empty() || Name[0] !=
'.')
return K;
131 if (Name ==
".bss" ||
141 if (Name ==
".tdata" ||
147 if (Name ==
".tbss" ||
159 if (Name ==
".init_array")
160 return ELF::SHT_INIT_ARRAY;
162 if (Name ==
".fini_array")
163 return ELF::SHT_FINI_ARRAY;
165 if (Name ==
".preinit_array")
166 return ELF::SHT_PREINIT_ARRAY;
169 return ELF::SHT_NOBITS;
171 return ELF::SHT_PROGBITS;
180 Flags |= ELF::SHF_ALLOC;
183 Flags |= ELF::SHF_EXECINSTR;
186 Flags |= ELF::SHF_WRITE;
189 Flags |= ELF::SHF_TLS;
194 Flags |= ELF::SHF_MERGE;
197 Flags |= ELF::SHF_STRINGS;
211 return getContext().getELFSection(SectionName,
219 if (Kind.
isText())
return ".text.";
221 if (Kind.
isBSS())
return ".bss.";
228 if (Kind.
isDataRel())
return ".data.rel.";
232 return ".data.rel.ro.";
241 bool EmitUniquedSection;
255 MCSymbol *Sym = getSymbol(*Mang, GV);
261 Flags |= ELF::SHF_GROUP;
264 return getContext().getELFSection(Name.
str(),
266 Flags, Kind, 0, Group);
269 if (Kind.
isText())
return TextSection;
281 const char *SizeSpec =
".rodata.str1.";
283 SizeSpec =
".rodata.str2.";
285 SizeSpec =
".rodata.str4.";
291 return getContext().getELFSection(Name, ELF::SHT_PROGBITS,
300 return MergeableConst4Section;
302 return MergeableConst8Section;
304 return MergeableConst16Section;
305 return ReadOnlySection;
308 if (Kind.
isReadOnly())
return ReadOnlySection;
320 if (Kind.
isDataRel())
return DataRelSection;
324 return DataRelROSection;
333 return MergeableConst4Section;
335 return MergeableConst8Section;
337 return MergeableConst16Section;
339 return ReadOnlySection;
343 return DataRelROSection;
350 if (Priority == 65535)
351 return StaticCtorSection;
354 std::string
Name = std::string(
".init_array.") +
utostr(Priority);
355 return getContext().getELFSection(Name, ELF::SHT_INIT_ARRAY,
356 ELF::SHF_ALLOC | ELF::SHF_WRITE,
359 std::string
Name = std::string(
".ctors.") +
utostr(65535 - Priority);
360 return getContext().getELFSection(Name, ELF::SHT_PROGBITS,
361 ELF::SHF_ALLOC |ELF::SHF_WRITE,
370 if (Priority == 65535)
371 return StaticDtorSection;
374 std::string
Name = std::string(
".fini_array.") +
utostr(Priority);
375 return getContext().getELFSection(Name, ELF::SHT_FINI_ARRAY,
376 ELF::SHF_ALLOC | ELF::SHF_WRITE,
379 std::string
Name = std::string(
".dtors.") +
utostr(65535 - Priority);
380 return getContext().getELFSection(Name, ELF::SHT_PROGBITS,
381 ELF::SHF_ALLOC |ELF::SHF_WRITE,
393 getContext().getELFSection(
".init_array", ELF::SHT_INIT_ARRAY,
398 getContext().getELFSection(
".fini_array", ELF::SHT_FINI_ARRAY,
413 unsigned VersionVal = 0;
414 unsigned ImageInfoFlags = 0;
415 MDNode *LinkerOptions = 0;
419 i = ModuleFlags.
begin(), e = ModuleFlags.
end(); i != e; ++i) {
429 if (Key ==
"Objective-C Image Info Version") {
430 VersionVal = cast<ConstantInt>(Val)->getZExtValue();
431 }
else if (Key ==
"Objective-C Garbage Collection" ||
432 Key ==
"Objective-C GC Only" ||
433 Key ==
"Objective-C Is Simulated") {
434 ImageInfoFlags |= cast<ConstantInt>(Val)->getZExtValue();
435 }
else if (Key ==
"Objective-C Image Info Section") {
436 SectionVal = cast<MDString>(Val)->getString();
437 }
else if (Key ==
"Linker Options") {
438 LinkerOptions = cast<MDNode>(Val);
444 for (
unsigned i = 0, e = LinkerOptions->
getNumOperands(); i != e; ++i) {
449 for (
unsigned ii = 0, ie = MDOptions->
getNumOperands(); ii != ie; ++ii) {
451 StrOptions.push_back(MDOption->
getString());
459 if (SectionVal.
empty())
return;
462 unsigned TAA = 0, StubSize = 0;
464 std::string ErrorCode =
466 TAA, TAAParsed, StubSize);
467 if (!ErrorCode.empty())
474 getContext().getMachOSection(Segment, Section, TAA, StubSize,
478 GetOrCreateSymbol(
StringRef(
"L_OBJC_IMAGE_INFO")));
489 unsigned TAA = 0, StubSize = 0;
491 std::string ErrorCode =
493 TAA, TAAParsed, StubSize);
494 if (!ErrorCode.empty()) {
497 "' has an invalid section specifier '" +
503 getContext().getMachOSection(Segment, Section, TAA, StubSize, Kind);
516 "' section type or attributes does not match previous"
517 " section specifier");
538 return ConstTextCoalSection;
539 return DataCoalSection;
545 return CStringSection;
552 return UStringSection;
556 return FourByteConstantSection;
558 return EightByteConstantSection;
560 return SixteenByteConstantSection;
566 return ReadOnlySection;
571 return ConstDataSection;
576 return DataCommonSection;
581 return DataBSSSection;
592 return ConstDataSection;
595 return FourByteConstantSection;
597 return EightByteConstantSection;
599 return SixteenByteConstantSection;
600 return ReadOnlySection;
610 if (!GV)
return false;
617 MCSymbol *Sym = getSymbol(*Mang, GV);
637 Name +=
"$non_lazy_ptr";
641 MCSymbol *SSym = getContext().GetOrCreateSymbol(Name.str());
646 MCSymbol *Sym = getSymbol(*Mang, GV);
668 Name +=
"$non_lazy_ptr";
672 MCSymbol *SSym = getContext().GetOrCreateSymbol(Name.str());
675 MCSymbol *Sym = getSymbol(*Mang, GV);
692 COFF::IMAGE_SCN_MEM_DISCARDABLE;
695 COFF::IMAGE_SCN_MEM_EXECUTE |
696 COFF::IMAGE_SCN_MEM_READ |
697 COFF::IMAGE_SCN_CNT_CODE;
700 COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |
701 COFF::IMAGE_SCN_MEM_READ |
702 COFF::IMAGE_SCN_MEM_WRITE;
705 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
706 COFF::IMAGE_SCN_MEM_READ |
707 COFF::IMAGE_SCN_MEM_WRITE;
710 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
711 COFF::IMAGE_SCN_MEM_READ;
714 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
715 COFF::IMAGE_SCN_MEM_READ |
716 COFF::IMAGE_SCN_MEM_WRITE;
729 Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT;
733 return getContext().getCOFFSection(
Name,
768 Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT;
778 return TLSDataSection;
781 return ReadOnlySection;
793 MDNode *LinkerOptions = 0;
797 i = ModuleFlags.
begin(), e = ModuleFlags.
end(); i != e; ++i) {
801 if (Key ==
"Linker Options") {
802 LinkerOptions = cast<MDNode>(Val);
811 const MCSection *Sec = getDrectveSection();
813 for (
unsigned i = 0, e = LinkerOptions->
getNumOperands(); i != e; ++i) {
815 for (
unsigned ii = 0, ie = MDOptions->
getNumOperands(); ii != ie; ++ii) {
819 std::string Escaped(
" ");
825 Escaped.push_back(
'\"');
827 Escaped.push_back(
'\"');
PointerIntPair< MCSymbol *, 1, bool > StubValueTy
StubValueTy & getHiddenGVStubEntry(MCSymbol *Sym)
StringRef getString() const
bool isMergeableConst() const
virtual const MCSection * SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, Mangler *Mang, const TargetMachine &TM) const
.type _foo, STT_OBJECT # aka
static const MCConstantExpr * Create(int64_t Value, MCContext &Ctx)
virtual void AddBlankLine()
AddBlankLine - Emit a blank line to a .s file to pretty it up.
unsigned getPointerSize(unsigned AS=0) const
virtual const MCExpr * getTTypeGlobalReference(const GlobalValue *GV, Mangler *Mang, MachineModuleInfo *MMI, unsigned Encoding, MCStreamer &Streamer) const
virtual void emitModuleFlags(MCStreamer &Streamer, ArrayRef< Module::ModuleFlagEntry > ModuleFlags, Mangler *Mang, const TargetMachine &TM) const
unsigned getNumOperands() const
getNumOperands - Return number of MDNode operands.
static SectionKind getDataRel()
void getNameWithPrefix(SmallVectorImpl< char > &OutName, const GlobalValue *GV, bool isImplicitlyPrivate, bool UseGlobalPrefix=true)
bool isMergeable2ByteCString() const
bool isReadOnlyWithRel() const
iterator insert(iterator I, const char &Elt)
virtual void emitPersonalityValue(MCStreamer &Streamer, const TargetMachine &TM, const MCSymbol *Sym) const
MDNode - a tuple of other values.
virtual const MCSection * getSectionForConstant(SectionKind Kind) const
bool isMergeableCString() const
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(const char *reason, bool gen_crash_diag=true)
StringRef getName() const
Value * getOperand(unsigned i) const LLVM_READONLY
getOperand - Return specified operand.
unsigned getPointerABIAlignment(unsigned AS=0) const
static SectionKind getBSS()
virtual const MCSection * getSectionForConstant(SectionKind Kind) const
virtual const MCExpr * getTTypeGlobalReference(const GlobalValue *GV, Mangler *Mang, MachineModuleInfo *MMI, unsigned Encoding, MCStreamer &Streamer) const
virtual const MCSection * getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, Mangler *Mang, const TargetMachine &TM) const
const MCExpr * getTTypeReference(const MCSymbolRefExpr *Sym, unsigned Encoding, MCStreamer &Streamer) const
virtual void EmitBytes(StringRef Data)=0
virtual const MCSection * getStaticDtorSection(unsigned Priority=65535) const
static unsigned getCOFFSectionFlags(SectionKind K)
virtual MCSymbol * getCFIPersonalitySymbol(const GlobalValue *GV, Mangler *Mang, MachineModuleInfo *MMI) const
bool isMergeable4ByteCString() const
void SwitchSection(const MCSection *Section, const MCExpr *Subsection=0)
virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV, Mangler *) const
static const char * getCOFFSectionPrefixForUniqueGlobal(SectionKind Kind)
static std::string utostr(uint64_t X, bool isNeg=false)
unsigned getStubSize() const
static SectionKind getThreadData()
virtual void EmitIntValue(uint64_t Value, unsigned Size)
bool isMergeableConst16() const
static const MCSymbolRefExpr * Create(const MCSymbol *Symbol, MCContext &Ctx)
static bool isWeakForLinker(LinkageTypes Linkage)
void append(in_iter S, in_iter E)
Append from an iterator pair.
cl::opt< bool > UseInitArray("use-init-array", cl::desc("Use .init_array instead of .ctors."), cl::init(false))
static std::string ParseSectionSpecifier(StringRef Spec, StringRef &Segment, StringRef &Section, unsigned &TAA, bool &TAAParsed, unsigned &StubSize)
bool hasHiddenVisibility() const
bool isThreadData() const
static SectionKind getELFKindForNamedSection(StringRef Name, SectionKind K)
bool isMergeable1ByteCString() const
void InitializeELF(bool UseInitArray_)
virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value)=0
virtual bool EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute)=0
EmitSymbolAttribute - Add the given Attribute to Symbol.
static bool getDataSections()
static bool getFunctionSections()
const std::string & getSection() const
StubValueTy & getGVStubEntry(MCSymbol *Sym)
virtual const MCSection * getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, Mangler *Mang, const TargetMachine &TM) const
virtual const MCSection * SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, Mangler *Mang, const TargetMachine &TM) const
virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value=0, unsigned ValueSize=1, unsigned MaxBytesToEmit=0)=0
StubValueTy & getGVStubEntry(MCSymbol *Sym)
bool isThreadLocal() const
unsigned getPreferredAlignment(const GlobalVariable *GV) const
bool hasExternalLinkage() const
PointerTy getPointer() const
bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
static SectionKind getThreadBSS()
virtual void EmitLabel(MCSymbol *Symbol)
static SectionKind getDataNoRel()
size_t strlen(const char *s);
bool isMergeableConst8() const
StringRef str() const
Explicit conversion to StringRef.
static cl::opt< AlignMode > Align(cl::desc("Load/store alignment support"), cl::Hidden, cl::init(DefaultAlign), cl::values(clEnumValN(DefaultAlign,"arm-default-align","Generate unaligned accesses only on hardware/OS ""combinations that are known to support them"), clEnumValN(StrictAlign,"arm-strict-align","Disallow all unaligned memory accesses"), clEnumValN(NoStrictAlign,"arm-no-strict-align","Allow unaligned memory accesses"), clEnumValEnd))
virtual const MCSection * SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, Mangler *Mang, const TargetMachine &TM) const
StringRef getName() const
getName - Get the symbol name.
std::string getName(ID id, ArrayRef< Type * > Tys=None)
virtual const MCExpr * getTTypeGlobalReference(const GlobalValue *GV, Mangler *Mang, MachineModuleInfo *MMI, unsigned Encoding, MCStreamer &Streamer) const
virtual void EmitLinkerOptions(ArrayRef< std::string > Kind)
virtual const DataLayout * getDataLayout() const
virtual void emitModuleFlags(MCStreamer &Streamer, ArrayRef< Module::ModuleFlagEntry > ModuleFlags, Mangler *Mang, const TargetMachine &TM) const
emitModuleFlags - Perform code emission for module flags.
virtual const MCSection * getStaticCtorSection(unsigned Priority=65535) const
virtual MCSymbol * getCFIPersonalitySymbol(const GlobalValue *GV, Mangler *Mang, MachineModuleInfo *MMI) const
bool hasLocalLinkage() const
virtual const MCSection * getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, Mangler *Mang, const TargetMachine &TM) const
unsigned getTypeAndAttributes() const
LLVM Value Representation.
bool isMergeableConst4() const
bool isReadOnlyWithRelLocal() const
void EmitSymbolValue(const MCSymbol *Sym, unsigned Size)
static unsigned getELFSectionFlags(SectionKind K)
COFF::SectionCharacteristics Characteristics
static const char * getSectionPrefixForGlobal(SectionKind Kind)
static unsigned getELFSectionType(StringRef Name, SectionKind K)
bool isDataRelLocal() const
bool empty() const
empty - Check if the string is empty.