From 037b5be15a421b99066bb284027750a16ddd0fae Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Tue, 9 Nov 2010 22:54:38 +0000 Subject: [PATCH] Revert previous patch. Missed a case. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118645 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/MC/MCContext.h | 1 + include/llvm/MC/MCSectionELF.h | 11 +++++-- lib/MC/ELFObjectWriter.cpp | 6 ++-- lib/MC/MCContext.cpp | 4 +-- lib/MC/MCParser/ELFAsmParser.cpp | 5 +-- lib/MC/MCSectionELF.cpp | 54 +++++++++++++++++++------------- 6 files changed, 50 insertions(+), 31 deletions(-) diff --git a/include/llvm/MC/MCContext.h b/include/llvm/MC/MCContext.h index d3b38360e32..5ddbdae85d4 100644 --- a/include/llvm/MC/MCContext.h +++ b/include/llvm/MC/MCContext.h @@ -140,6 +140,7 @@ namespace llvm { const MCSection *getELFSection(StringRef Section, unsigned Type, unsigned Flags, SectionKind Kind, + bool IsExplicit = false, unsigned EntrySize = 0); const MCSection *getCOFFSection(StringRef Section, unsigned Characteristics, diff --git a/include/llvm/MC/MCSectionELF.h b/include/llvm/MC/MCSectionELF.h index bf07b99b21a..0e4a286e72b 100644 --- a/include/llvm/MC/MCSectionELF.h +++ b/include/llvm/MC/MCSectionELF.h @@ -32,6 +32,10 @@ class MCSectionELF : public MCSection { /// below. unsigned Flags; + /// IsExplicit - Indicates that this section comes from globals with an + /// explicit section specified. + bool IsExplicit; + /// EntrySize - The size of each entry in this section. This size only /// makes sense for sections that contain fixed-sized entries. If a /// section does not contain fixed-sized entries 'EntrySize' will be 0. @@ -40,9 +44,9 @@ class MCSectionELF : public MCSection { private: friend class MCContext; MCSectionELF(StringRef Section, unsigned type, unsigned flags, - SectionKind K, unsigned entrySize) + SectionKind K, bool isExplicit, unsigned entrySize) : MCSection(SV_ELF, K), SectionName(Section), Type(type), Flags(flags), - EntrySize(entrySize) {} + IsExplicit(isExplicit), EntrySize(entrySize) {} ~MCSectionELF(); public: @@ -50,6 +54,9 @@ public: /// should be printed before the section name bool ShouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const; + /// ShouldPrintSectionType - Only prints the section type if supported + bool ShouldPrintSectionType(unsigned Ty) const; + /// HasCommonSymbols - True if this section holds common symbols, this is /// indicated on the ELF object file by a symbol with SHN_COMMON section /// header index. diff --git a/lib/MC/ELFObjectWriter.cpp b/lib/MC/ELFObjectWriter.cpp index 313f2e20085..a0e326db284 100644 --- a/lib/MC/ELFObjectWriter.cpp +++ b/lib/MC/ELFObjectWriter.cpp @@ -1065,7 +1065,7 @@ void ELFObjectWriterImpl::WriteRelocation(MCAssembler &Asm, MCAsmLayout &Layout, RelaSection = Ctx.getELFSection(RelaSectionName, HasRelocationAddend ? ELF::SHT_RELA : ELF::SHT_REL, 0, SectionKind::getReadOnly(), - EntrySize); + false, EntrySize); MCSectionData &RelaSD = Asm.getOrCreateSectionData(*RelaSection); RelaSD.setAlignment(Is64Bit ? 8 : 4); @@ -1164,7 +1164,7 @@ void ELFObjectWriterImpl::CreateMetadataSections(MCAssembler &Asm, const MCSection *SymtabSection = Ctx.getELFSection(".symtab", ELF::SHT_SYMTAB, 0, SectionKind::getReadOnly(), - EntrySize); + false, EntrySize); MCSectionData &SymtabSD = Asm.getOrCreateSectionData(*SymtabSection); SymtabSD.setAlignment(Is64Bit ? 8 : 4); SymbolTableIndex = Asm.size(); @@ -1174,7 +1174,7 @@ void ELFObjectWriterImpl::CreateMetadataSections(MCAssembler &Asm, if (NeedsSymtabShndx) { const MCSection *SymtabShndxSection = Ctx.getELFSection(".symtab_shndx", ELF::SHT_SYMTAB_SHNDX, 0, - SectionKind::getReadOnly(), 4); + SectionKind::getReadOnly(), false, 4); SymtabShndxSD = &Asm.getOrCreateSectionData(*SymtabShndxSection); SymtabShndxSD->setAlignment(4); } diff --git a/lib/MC/MCContext.cpp b/lib/MC/MCContext.cpp index 3b96264be04..9c747d10417 100644 --- a/lib/MC/MCContext.cpp +++ b/lib/MC/MCContext.cpp @@ -151,7 +151,7 @@ getMachOSection(StringRef Segment, StringRef Section, const MCSection *MCContext:: getELFSection(StringRef Section, unsigned Type, unsigned Flags, - SectionKind Kind, unsigned EntrySize) { + SectionKind Kind, bool IsExplicit, unsigned EntrySize) { if (ELFUniquingMap == 0) ELFUniquingMap = new ELFUniqueMapTy(); ELFUniqueMapTy &Map = *(ELFUniqueMapTy*)ELFUniquingMap; @@ -165,7 +165,7 @@ getELFSection(StringRef Section, unsigned Type, unsigned Flags, EntrySize = MCSectionELF::DetermineEntrySize(Kind); } MCSectionELF *Result = new (*this) MCSectionELF(Entry.getKey(), Type, Flags, - Kind, EntrySize); + Kind, IsExplicit, EntrySize); Entry.setValue(Result); return Result; } diff --git a/lib/MC/MCParser/ELFAsmParser.cpp b/lib/MC/MCParser/ELFAsmParser.cpp index 75eee3d4420..d6c4e451259 100644 --- a/lib/MC/MCParser/ELFAsmParser.cpp +++ b/lib/MC/MCParser/ELFAsmParser.cpp @@ -331,7 +331,8 @@ bool ELFAsmParser::ParseDirectiveSection(StringRef, SMLoc) { ? SectionKind::getText() : SectionKind::getDataRel(); getStreamer().SwitchSection(getContext().getELFSection(SectionName, Type, - Flags, Kind, Size)); + Flags, Kind, false, + Size)); return false; } @@ -405,7 +406,7 @@ bool ELFAsmParser::ParseDirectiveIdent(StringRef, SMLoc) { MCSectionELF::SHF_MERGE | MCSectionELF::SHF_STRINGS, SectionKind::getReadOnly(), - 1); + false, 1); static bool First = true; diff --git a/lib/MC/MCSectionELF.cpp b/lib/MC/MCSectionELF.cpp index 5bcf81021d7..133cad1b32c 100644 --- a/lib/MC/MCSectionELF.cpp +++ b/lib/MC/MCSectionELF.cpp @@ -29,6 +29,14 @@ bool MCSectionELF::ShouldOmitSectionDirective(StringRef Name, return false; } +// ShouldPrintSectionType - Only prints the section type if supported +bool MCSectionELF::ShouldPrintSectionType(unsigned Ty) const { + if (IsExplicit && !(Ty == SHT_NOBITS || Ty == SHT_PROGBITS)) + return false; + + return true; +} + void MCSectionELF::PrintSwitchToSection(const MCAsmInfo &MAI, raw_ostream &OS) const { @@ -76,29 +84,31 @@ void MCSectionELF::PrintSwitchToSection(const MCAsmInfo &MAI, OS << '"'; - OS << ','; - - // If comment string is '@', e.g. as on ARM - use '%' instead - if (MAI.getCommentString()[0] == '@') - OS << '%'; - else - OS << '@'; - - if (Type == MCSectionELF::SHT_INIT_ARRAY) - OS << "init_array"; - else if (Type == MCSectionELF::SHT_FINI_ARRAY) - OS << "fini_array"; - else if (Type == MCSectionELF::SHT_PREINIT_ARRAY) - OS << "preinit_array"; - else if (Type == MCSectionELF::SHT_NOBITS) - OS << "nobits"; - else if (Type == MCSectionELF::SHT_PROGBITS) - OS << "progbits"; - - if (EntrySize) { - OS << "," << EntrySize; + if (ShouldPrintSectionType(Type)) { + OS << ','; + + // If comment string is '@', e.g. as on ARM - use '%' instead + if (MAI.getCommentString()[0] == '@') + OS << '%'; + else + OS << '@'; + + if (Type == MCSectionELF::SHT_INIT_ARRAY) + OS << "init_array"; + else if (Type == MCSectionELF::SHT_FINI_ARRAY) + OS << "fini_array"; + else if (Type == MCSectionELF::SHT_PREINIT_ARRAY) + OS << "preinit_array"; + else if (Type == MCSectionELF::SHT_NOBITS) + OS << "nobits"; + else if (Type == MCSectionELF::SHT_PROGBITS) + OS << "progbits"; + + if (EntrySize) { + OS << "," << EntrySize; + } } - + OS << '\n'; } -- 2.34.1