X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FTarget%2FELFTargetAsmInfo.cpp;h=8f6e96e2751dfec4bba4b7343b2aa5e7dfa1a8fc;hb=87c411b5cc254a8d169b834f3487657a8dc1e17a;hp=624b95c7b6c162e643545d7665d0c968a507c83a;hpb=72bb40229ec455d6c39f0c1482ca6621e41a380a;p=oota-llvm.git diff --git a/lib/Target/ELFTargetAsmInfo.cpp b/lib/Target/ELFTargetAsmInfo.cpp index 624b95c7b6c..8f6e96e2751 100644 --- a/lib/Target/ELFTargetAsmInfo.cpp +++ b/lib/Target/ELFTargetAsmInfo.cpp @@ -35,6 +35,37 @@ ELFTargetAsmInfo::ELFTargetAsmInfo(const TargetMachine &TM) TLSBSSSection = getNamedSection("\t.tbss", SectionFlags::Writeable | SectionFlags::TLS | SectionFlags::BSS); + DataRelSection = getNamedSection("\t.data.rel", SectionFlags::Writeable); + DataRelLocalSection = getNamedSection("\t.data.rel.local", + SectionFlags::Writeable); + DataRelROSection = getNamedSection("\t.data.rel.ro", + SectionFlags::Writeable); + DataRelROLocalSection = getNamedSection("\t.data.rel.ro.local", + SectionFlags::Writeable); +} + +SectionKind::Kind +ELFTargetAsmInfo::SectionKindForGlobal(const GlobalValue *GV) const { + SectionKind::Kind Kind = TargetAsmInfo::SectionKindForGlobal(GV); + + if (Kind != SectionKind::Data) + return Kind; + + // Decide, whether we need data.rel stuff + const GlobalVariable* GVar = dyn_cast(GV); + if (GVar->hasInitializer()) { + Constant *C = GVar->getInitializer(); + bool isConstant = GVar->isConstant(); + unsigned Reloc = RelocBehaviour(); + if (Reloc != Reloc::None && C->ContainsRelocations(Reloc)) + return (C->ContainsRelocations(Reloc::Global) ? + (isConstant ? + SectionKind::DataRelRO : SectionKind::DataRel) : + (isConstant ? + SectionKind::DataRelROLocal : SectionKind::DataRelLocal)); + } + + return Kind; } const Section* @@ -49,14 +80,16 @@ ELFTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const { case Function::DLLExportLinkage: case Function::ExternalLinkage: return TextSection; - case Function::WeakLinkage: - case Function::LinkOnceLinkage: + case Function::WeakAnyLinkage: + case Function::WeakODRLinkage: + case Function::LinkOnceAnyLinkage: + case Function::LinkOnceODRLinkage: std::string Name = UniqueSectionForGlobal(GV, Kind); unsigned Flags = SectionFlagsForGlobal(GV, Name.c_str()); return getNamedSection(Name.c_str(), Flags); } } else if (const GlobalVariable *GVar = dyn_cast(GV)) { - if (GVar->mayBeOverridden()) { + if (GVar->isWeakForLinker()) { std::string Name = UniqueSectionForGlobal(GVar, Kind); unsigned Flags = SectionFlagsForGlobal(GVar, Name.c_str()); return getNamedSection(Name.c_str(), Flags); @@ -65,6 +98,14 @@ ELFTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const { case SectionKind::Data: case SectionKind::SmallData: return DataSection; + case SectionKind::DataRel: + return DataRelSection; + case SectionKind::DataRelLocal: + return DataRelLocalSection; + case SectionKind::DataRelRO: + return DataRelROSection; + case SectionKind::DataRelROLocal: + return DataRelROLocalSection; case SectionKind::BSS: case SectionKind::SmallBSS: // ELF targets usually have BSS sections @@ -110,7 +151,7 @@ ELFTargetAsmInfo::MergeableConstSection(const Type *Ty) const { // FIXME: string here is temporary, until stuff will fully land in. // We cannot use {Four,Eight,Sixteen}ByteConstantSection here, since it's // currently directly used by asmprinter. - unsigned Size = TD->getTypePaddedSize(Ty); + unsigned Size = TD->getTypeAllocSize(Ty); if (Size == 4 || Size == 8 || Size == 16) { std::string Name = ".rodata.cst" + utostr(Size); @@ -128,7 +169,7 @@ ELFTargetAsmInfo::MergeableStringSection(const GlobalVariable *GV) const { Constant *C = cast(GV)->getInitializer(); const Type *Ty = cast(C->getType())->getElementType(); - unsigned Size = TD->getTypePaddedSize(Ty); + unsigned Size = TD->getTypeAllocSize(Ty); if (Size <= 16) { assert(getCStringSection() && "Should have string section prefix");