From 4c530ee667b91ee9ffbe1d5614efa48c5bde903d Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sat, 25 Jul 2009 18:57:34 +0000 Subject: this is (unfortunately) several changes mixed together: 1. Spell SectionFlags::Writeable as "Writable". 2. Add predicates for deriving SectionFlags from SectionKinds. 3. Sink ELF-specific getSectionPrefixForUniqueGlobal impl into ELFTargetAsmInfo. 4. Fix SectionFlagsForGlobal to know that BSS/ThreadBSS has the BSS bit set (the real fix for PR4619). 5. Fix isSuitableForBSS to not put globals with explicit sections set in BSS (which was the reason #4 wasn't fixed earlier). 6. Remove my previous hack for PR4619. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77085 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/ELFWriter.cpp | 2 +- lib/Target/CellSPU/SPUTargetAsmInfo.cpp | 2 +- lib/Target/DarwinTargetAsmInfo.cpp | 3 +- lib/Target/ELFTargetAsmInfo.cpp | 38 +++++++++++---- lib/Target/PIC16/PIC16AsmPrinter.cpp | 2 +- lib/Target/PIC16/PIC16TargetAsmInfo.cpp | 4 +- lib/Target/PowerPC/PPCTargetAsmInfo.cpp | 2 +- lib/Target/Sparc/SparcTargetAsmInfo.cpp | 4 +- lib/Target/TargetAsmInfo.cpp | 85 +++++++++++---------------------- lib/Target/X86/X86TargetAsmInfo.cpp | 5 +- lib/Target/XCore/XCoreTargetAsmInfo.cpp | 6 +-- 11 files changed, 72 insertions(+), 81 deletions(-) (limited to 'lib') diff --git a/lib/CodeGen/ELFWriter.cpp b/lib/CodeGen/ELFWriter.cpp index 8cbaf6f..45658e0 100644 --- a/lib/CodeGen/ELFWriter.cpp +++ b/lib/CodeGen/ELFWriter.cpp @@ -222,7 +222,7 @@ unsigned ELFWriter::getElfSectionFlags(unsigned Flags) { if (Flags & SectionFlags::Code) ElfSectionFlags |= ELFSection::SHF_EXECINSTR; - if (Flags & SectionFlags::Writeable) + if (Flags & SectionFlags::Writable) ElfSectionFlags |= ELFSection::SHF_WRITE; if (Flags & SectionFlags::Mergeable) ElfSectionFlags |= ELFSection::SHF_MERGE; diff --git a/lib/Target/CellSPU/SPUTargetAsmInfo.cpp b/lib/Target/CellSPU/SPUTargetAsmInfo.cpp index 2868ff7..000ba01 100644 --- a/lib/Target/CellSPU/SPUTargetAsmInfo.cpp +++ b/lib/Target/CellSPU/SPUTargetAsmInfo.cpp @@ -36,7 +36,7 @@ SPULinuxTargetAsmInfo::SPULinuxTargetAsmInfo(const SPUTargetMachine &TM) : // BSS section needs to be emitted as ".section" BSSSection = "\t.section\t.bss"; BSSSection_ = getUnnamedSection("\t.section\t.bss", - SectionFlags::Writeable | SectionFlags::BSS, + SectionFlags::Writable | SectionFlags::BSS, true); SupportsDebugInformation = true; diff --git a/lib/Target/DarwinTargetAsmInfo.cpp b/lib/Target/DarwinTargetAsmInfo.cpp index 2d3c5ff..2d750a5 100644 --- a/lib/Target/DarwinTargetAsmInfo.cpp +++ b/lib/Target/DarwinTargetAsmInfo.cpp @@ -50,7 +50,7 @@ DarwinTargetAsmInfo::DarwinTargetAsmInfo(const TargetMachine &TM) SectionFlags::None); ConstDataSection = getUnnamedSection(".const_data", SectionFlags::None); DataCoalSection = getNamedSection("\t__DATA,__datacoal_nt,coalesced", - SectionFlags::Writeable); + SectionFlags::Writable); // Common settings for all Darwin targets. @@ -127,6 +127,7 @@ bool DarwinTargetAsmInfo::emitUsedDirectiveFor(const GlobalValue* GV, const Section* DarwinTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV, SectionKind::Kind Kind) const { + // FIXME: Use sectionflags:linkonce instead of isWeakForLinker() here. bool isWeak = GV->isWeakForLinker(); bool isNonStatic = TM.getRelocationModel() != Reloc::Static; diff --git a/lib/Target/ELFTargetAsmInfo.cpp b/lib/Target/ELFTargetAsmInfo.cpp index 9dd339e..ea07836 100644 --- a/lib/Target/ELFTargetAsmInfo.cpp +++ b/lib/Target/ELFTargetAsmInfo.cpp @@ -29,20 +29,20 @@ ELFTargetAsmInfo::ELFTargetAsmInfo(const TargetMachine &TM) : TargetAsmInfo(TM) { BSSSection_ = getUnnamedSection("\t.bss", - SectionFlags::Writeable | SectionFlags::BSS); + SectionFlags::Writable | SectionFlags::BSS); ReadOnlySection = getNamedSection("\t.rodata", SectionFlags::None); TLSDataSection = getNamedSection("\t.tdata", - SectionFlags::Writeable | SectionFlags::TLS); + SectionFlags::Writable | SectionFlags::TLS); TLSBSSSection = getNamedSection("\t.tbss", - SectionFlags::Writeable | SectionFlags::TLS | SectionFlags::BSS); + SectionFlags::Writable | SectionFlags::TLS | SectionFlags::BSS); - DataRelSection = getNamedSection("\t.data.rel", SectionFlags::Writeable); + DataRelSection = getNamedSection("\t.data.rel", SectionFlags::Writable); DataRelLocalSection = getNamedSection("\t.data.rel.local", - SectionFlags::Writeable); + SectionFlags::Writable); DataRelROSection = getNamedSection("\t.data.rel.ro", - SectionFlags::Writeable); + SectionFlags::Writable); DataRelROLocalSection = getNamedSection("\t.data.rel.ro.local", - SectionFlags::Writeable); + SectionFlags::Writable); } @@ -145,6 +145,28 @@ unsigned ELFTargetAsmInfo::getFlagsForNamedSection(const char *Name) const { } + +const char * +ELFTargetAsmInfo::getSectionPrefixForUniqueGlobal(SectionKind::Kind Kind) const{ + switch (Kind) { + default: llvm_unreachable("Unknown section kind"); + case SectionKind::Text: return ".gnu.linkonce.t."; + case SectionKind::Data: return ".gnu.linkonce.d."; + case SectionKind::DataRel: return ".gnu.linkonce.d.rel."; + case SectionKind::DataRelLocal: return ".gnu.linkonce.d.rel.local."; + case SectionKind::DataRelRO: return ".gnu.linkonce.d.rel.ro."; + case SectionKind::DataRelROLocal: return ".gnu.linkonce.d.rel.ro.local."; + case SectionKind::BSS: return ".gnu.linkonce.b."; + case SectionKind::ROData: + case SectionKind::RODataMergeConst: + case SectionKind::RODataMergeStr: return ".gnu.linkonce.r."; + case SectionKind::ThreadData: return ".gnu.linkonce.td."; + case SectionKind::ThreadBSS: return ".gnu.linkonce.tb."; + } +} + + + const Section* ELFTargetAsmInfo::MergeableStringSection(const GlobalVariable *GV) const { const TargetData *TD = TM.getTargetData(); @@ -177,7 +199,7 @@ std::string ELFTargetAsmInfo::printSectionFlags(unsigned flags) const { Flags += 'a'; if (flags & SectionFlags::Code) Flags += 'x'; - if (flags & SectionFlags::Writeable) + if (flags & SectionFlags::Writable) Flags += 'w'; if (flags & SectionFlags::Mergeable) Flags += 'M'; diff --git a/lib/Target/PIC16/PIC16AsmPrinter.cpp b/lib/Target/PIC16/PIC16AsmPrinter.cpp index 95d363e..7195551 100644 --- a/lib/Target/PIC16/PIC16AsmPrinter.cpp +++ b/lib/Target/PIC16/PIC16AsmPrinter.cpp @@ -292,7 +292,7 @@ void PIC16AsmPrinter::EmitFunctionFrame(MachineFunction &MF) { const char *SectionName = PAN::getFrameSectionName(CurrentFnName).c_str(); const Section *fPDataSection = TAI->getNamedSection(SectionName, - SectionFlags::Writeable); + SectionFlags::Writable); SwitchToSection(fPDataSection); // Emit function frame label diff --git a/lib/Target/PIC16/PIC16TargetAsmInfo.cpp b/lib/Target/PIC16/PIC16TargetAsmInfo.cpp index 6f4b0c5..dce1b78 100644 --- a/lib/Target/PIC16/PIC16TargetAsmInfo.cpp +++ b/lib/Target/PIC16/PIC16TargetAsmInfo.cpp @@ -38,9 +38,9 @@ PIC16TargetAsmInfo(const PIC16TargetMachine &TM) AsciiDirective = " dt "; AscizDirective = NULL; BSSSection_ = getNamedSection("udata.# UDATA", - SectionFlags::Writeable | SectionFlags::BSS); + SectionFlags::Writable | SectionFlags::BSS); ReadOnlySection = getNamedSection("romdata.# ROMDATA", SectionFlags::None); - DataSection = getNamedSection("idata.# IDATA", SectionFlags::Writeable); + DataSection = getNamedSection("idata.# IDATA", SectionFlags::Writable); SwitchToSectionDirective = ""; // Need because otherwise a .text symbol is emitted by DwarfWriter // in BeginModule, and gpasm cribbs for that .text symbol. diff --git a/lib/Target/PowerPC/PPCTargetAsmInfo.cpp b/lib/Target/PowerPC/PPCTargetAsmInfo.cpp index ebffd69..0a5530e 100644 --- a/lib/Target/PowerPC/PPCTargetAsmInfo.cpp +++ b/lib/Target/PowerPC/PPCTargetAsmInfo.cpp @@ -75,7 +75,7 @@ PPCLinuxTargetAsmInfo::PPCLinuxTargetAsmInfo(const PPCTargetMachine &TM) : // PPC/Linux normally uses named section for BSS. BSSSection_ = getNamedSection("\t.bss", - SectionFlags::Writeable | SectionFlags::BSS, + SectionFlags::Writable | SectionFlags::BSS, /* Override */ true); // Debug Information diff --git a/lib/Target/Sparc/SparcTargetAsmInfo.cpp b/lib/Target/Sparc/SparcTargetAsmInfo.cpp index c13d45c..0087c26 100644 --- a/lib/Target/Sparc/SparcTargetAsmInfo.cpp +++ b/lib/Target/Sparc/SparcTargetAsmInfo.cpp @@ -28,7 +28,7 @@ SparcELFTargetAsmInfo::SparcELFTargetAsmInfo(const TargetMachine &TM): // Sparc normally uses named section for BSS. BSSSection_ = getNamedSection("\t.bss", - SectionFlags::Writeable | SectionFlags::BSS, + SectionFlags::Writable | SectionFlags::BSS, /* Override */ true); } @@ -41,7 +41,7 @@ std::string SparcELFTargetAsmInfo::printSectionFlags(unsigned flags) const { Flags += ",#alloc"; if (flags & SectionFlags::Code) Flags += ",#execinstr"; - if (flags & SectionFlags::Writeable) + if (flags & SectionFlags::Writable) Flags += ",#write"; if (flags & SectionFlags::TLS) Flags += ",#tls"; diff --git a/lib/Target/TargetAsmInfo.cpp b/lib/Target/TargetAsmInfo.cpp index dfb274f..0a4c1b4 100644 --- a/lib/Target/TargetAsmInfo.cpp +++ b/lib/Target/TargetAsmInfo.cpp @@ -122,7 +122,7 @@ TargetAsmInfo::TargetAsmInfo(const TargetMachine &tm) : TM(tm) { DwarfExceptionSection = ".gcc_except_table"; AsmTransCBE = 0; TextSection = getUnnamedSection("\t.text", SectionFlags::Code); - DataSection = getUnnamedSection("\t.data", SectionFlags::Writeable); + DataSection = getUnnamedSection("\t.data", SectionFlags::Writable); } TargetAsmInfo::~TargetAsmInfo() { @@ -160,9 +160,22 @@ unsigned TargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason, } static bool isSuitableForBSS(const GlobalVariable *GV) { - // Leave constant zeros in readonly constant sections, so they can be shared Constant *C = GV->getInitializer(); - return (C->isNullValue() && !GV->isConstant() && !NoZerosInBSS); + + // Must have zero initializer. + if (!C->isNullValue()) + return false; + + // Leave constant zeros in readonly constant sections, so they can be shared. + if (GV->isConstant()) + return false; + + // If the global has an explicit section specified, don't put it in BSS. + if (!GV->getSection().empty()) + return false; + + // Otherwise, put it in BSS unless the target really doesn't want us to. + return !NoZerosInBSS; } static bool isConstantString(const Constant *C) { @@ -183,36 +196,18 @@ static bool isConstantString(const Constant *C) { static unsigned SectionFlagsForGlobal(const GlobalValue *GV, SectionKind::Kind Kind) { + // Decode flags from global and section kind. unsigned Flags = SectionFlags::None; - - // Decode flags from global itself. - switch (Kind) { - case SectionKind::Text: - Flags |= SectionFlags::Code; - break; - case SectionKind::ThreadData: - case SectionKind::ThreadBSS: - Flags |= SectionFlags::TLS; - // FALLS THROUGH - case SectionKind::Data: - case SectionKind::DataRel: - case SectionKind::DataRelLocal: - case SectionKind::DataRelRO: - case SectionKind::DataRelROLocal: - case SectionKind::BSS: - Flags |= SectionFlags::Writeable; - break; - case SectionKind::ROData: - case SectionKind::RODataMergeStr: - case SectionKind::RODataMergeConst: - // No additional flags here - break; - default: - llvm_unreachable("Unexpected section kind!"); - } - if (GV->isWeakForLinker()) Flags |= SectionFlags::Linkonce; + if (SectionKind::isBSS(Kind)) + Flags |= SectionFlags::BSS; + if (SectionKind::isTLS(Kind)) + Flags |= SectionFlags::TLS; + if (SectionKind::isCode(Kind)) + Flags |= SectionFlags::Code; + if (SectionKind::isWritable(Kind)) + Flags |= SectionFlags::Writable; return Flags; } @@ -331,11 +326,6 @@ const Section *TargetAsmInfo::SectionForGlobal(const GlobalValue *GV) const { // FIXME: Use mangler interface (PR4584). std::string Name = Prefix+GV->getNameStr(); - - // Pick up the flags for the uniquing section. - // FIXME: HACK. - Flags |= getFlagsForNamedSection(Name.c_str()); - return getNamedSection(Name.c_str(), Flags); } } @@ -348,10 +338,10 @@ const Section *TargetAsmInfo::SectionForGlobal(const GlobalValue *GV) const { const Section* TargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV, SectionKind::Kind Kind) const { - if (Kind == SectionKind::Text) + if (SectionKind::isCode(Kind)) return getTextSection(); - if (Kind == SectionKind::BSS) + if (SectionKind::isBSS(SectionKind::BSS)) if (const Section *S = getBSSSection_()) return S; @@ -374,27 +364,6 @@ TargetAsmInfo::getSectionForMergableConstant(uint64_t Size, } - - -const char * -TargetAsmInfo::getSectionPrefixForUniqueGlobal(SectionKind::Kind Kind) const { - switch (Kind) { - default: llvm_unreachable("Unknown section kind"); - case SectionKind::Text: return ".gnu.linkonce.t."; - case SectionKind::Data: return ".gnu.linkonce.d."; - case SectionKind::DataRel: return ".gnu.linkonce.d.rel."; - case SectionKind::DataRelLocal: return ".gnu.linkonce.d.rel.local."; - case SectionKind::DataRelRO: return ".gnu.linkonce.d.rel.ro."; - case SectionKind::DataRelROLocal: return ".gnu.linkonce.d.rel.ro.local."; - case SectionKind::BSS: return ".gnu.linkonce.b."; - case SectionKind::ROData: - case SectionKind::RODataMergeConst: - case SectionKind::RODataMergeStr: return ".gnu.linkonce.r."; - case SectionKind::ThreadData: return ".gnu.linkonce.td."; - case SectionKind::ThreadBSS: return ".gnu.linkonce.tb."; - } -} - const Section *TargetAsmInfo::getNamedSection(const char *Name, unsigned Flags, bool Override) const { Section &S = Sections[Name]; diff --git a/lib/Target/X86/X86TargetAsmInfo.cpp b/lib/Target/X86/X86TargetAsmInfo.cpp index 3dc7ec4..e71cd70 100644 --- a/lib/Target/X86/X86TargetAsmInfo.cpp +++ b/lib/Target/X86/X86TargetAsmInfo.cpp @@ -282,7 +282,6 @@ getSectionPrefixForUniqueGlobal(SectionKind::Kind Kind) const { case SectionKind::RODataMergeConst: case SectionKind::RODataMergeStr: return ".rdata$linkonce"; } - return NULL; } std::string X86COFFTargetAsmInfo::printSectionFlags(unsigned flags) const { @@ -290,7 +289,7 @@ std::string X86COFFTargetAsmInfo::printSectionFlags(unsigned flags) const { if (flags & SectionFlags::Code) Flags += 'x'; - if (flags & SectionFlags::Writeable) + if (flags & SectionFlags::Writable) Flags += 'w'; Flags += "\""; @@ -322,7 +321,7 @@ X86WinTargetAsmInfo::X86WinTargetAsmInfo(const X86TargetMachine &TM): AlignmentIsInBytes = true; TextSection = getUnnamedSection("_text", SectionFlags::Code); - DataSection = getUnnamedSection("_data", SectionFlags::Writeable); + DataSection = getUnnamedSection("_data", SectionFlags::Writable); JumpTableDataSection = NULL; SwitchToSectionDirective = ""; diff --git a/lib/Target/XCore/XCoreTargetAsmInfo.cpp b/lib/Target/XCore/XCoreTargetAsmInfo.cpp index 6fc6dc2..9f6727b 100644 --- a/lib/Target/XCore/XCoreTargetAsmInfo.cpp +++ b/lib/Target/XCore/XCoreTargetAsmInfo.cpp @@ -25,8 +25,8 @@ XCoreTargetAsmInfo::XCoreTargetAsmInfo(const XCoreTargetMachine &TM) : ELFTargetAsmInfo(TM) { SupportsDebugInformation = true; TextSection = getUnnamedSection("\t.text", SectionFlags::Code); - DataSection = getNamedSection("\t.dp.data", SectionFlags::Writeable); - BSSSection_ = getNamedSection("\t.dp.bss", SectionFlags::Writeable | + DataSection = getNamedSection("\t.dp.data", SectionFlags::Writable); + BSSSection_ = getNamedSection("\t.dp.bss", SectionFlags::Writable | SectionFlags::BSS); // TLS globals are lowered in the backend to arrays indexed by the current @@ -36,7 +36,7 @@ XCoreTargetAsmInfo::XCoreTargetAsmInfo(const XCoreTargetMachine &TM) TLSBSSSection = BSSSection_; if (TM.getSubtargetImpl()->isXS1A()) - ReadOnlySection = getNamedSection("\t.dp.rodata", SectionFlags::Writeable); + ReadOnlySection = getNamedSection("\t.dp.rodata", SectionFlags::Writable); else ReadOnlySection = getNamedSection("\t.cp.rodata", SectionFlags::None); Data16bitsDirective = "\t.short\t"; -- cgit v1.1