Index: include/llvm/ObjectYAML/ELFYAML.h =================================================================== --- include/llvm/ObjectYAML/ELFYAML.h +++ include/llvm/ObjectYAML/ELFYAML.h @@ -25,6 +25,8 @@ namespace llvm { namespace ELFYAML { +StringRef dropUniqueSuffix(StringRef S); + // These types are invariant across 32/64-bit ELF, so for simplicity just // directly give them their exact sizes. We don't need to worry about // endianness because these are just the types in the YAMLIO structures, Index: lib/ObjectYAML/ELFEmitter.cpp =================================================================== --- lib/ObjectYAML/ELFEmitter.cpp +++ lib/ObjectYAML/ELFEmitter.cpp @@ -340,7 +340,7 @@ return true; } -static StringRef dropUniqueSuffix(StringRef S) { +StringRef llvm::ELFYAML::dropUniqueSuffix(StringRef S) { size_t SuffixPos = S.rfind(" ["); if (SuffixPos == StringRef::npos) return S; @@ -371,7 +371,8 @@ assert(Sec && "It can't be null unless it is an implicit section. But all " "implicit sections should already have been handled above."); - SHeader.sh_name = DotShStrtab.getOffset(dropUniqueSuffix(Sec->Name)); + SHeader.sh_name = + DotShStrtab.getOffset(ELFYAML::dropUniqueSuffix(Sec->Name)); SHeader.sh_type = Sec->Type; if (Sec->Flags) SHeader.sh_flags = *Sec->Flags; @@ -472,7 +473,7 @@ if (Sym.NameIndex) Symbol.st_name = *Sym.NameIndex; else if (!Sym.Name.empty()) - Symbol.st_name = Strtab.getOffset(dropUniqueSuffix(Sym.Name)); + Symbol.st_name = Strtab.getOffset(ELFYAML::dropUniqueSuffix(Sym.Name)); Symbol.setBindingAndType(Sym.Binding, Sym.Type); if (!Sym.Section.empty()) @@ -962,7 +963,7 @@ if (Name.empty()) continue; - DotShStrtab.add(dropUniqueSuffix(Name)); + DotShStrtab.add(ELFYAML::dropUniqueSuffix(Name)); if (!SN2I.addName(Name, I)) reportError("repeated section name: '" + Name + "' at YAML section number " + Twine(I)); @@ -987,12 +988,12 @@ template void ELFState::finalizeStrings() { // Add the regular symbol names to .strtab section. for (const ELFYAML::Symbol &Sym : Doc.Symbols) - DotStrtab.add(dropUniqueSuffix(Sym.Name)); + DotStrtab.add(ELFYAML::dropUniqueSuffix(Sym.Name)); DotStrtab.finalize(); // Add the dynamic symbol names to .dynstr section. for (const ELFYAML::Symbol &Sym : Doc.DynamicSymbols) - DotDynstr.add(dropUniqueSuffix(Sym.Name)); + DotDynstr.add(ELFYAML::dropUniqueSuffix(Sym.Name)); // SHT_GNU_verdef and SHT_GNU_verneed sections might also // add strings to .dynstr section. Index: lib/ObjectYAML/ELFYAML.cpp =================================================================== --- lib/ObjectYAML/ELFYAML.cpp +++ lib/ObjectYAML/ELFYAML.cpp @@ -1151,6 +1151,7 @@ if (!IO.outputting()) { StringRef Name; IO.mapOptional("Name", Name, StringRef()); + Name = ELFYAML::dropUniqueSuffix(Name); if (ELFYAML::StackSizesSection::nameMatches(Name)) Section = std::make_unique(); Index: test/tools/llvm-readobj/stack-sizes.test =================================================================== --- test/tools/llvm-readobj/stack-sizes.test +++ test/tools/llvm-readobj/stack-sizes.test @@ -44,14 +44,15 @@ Size: 16 - Name: .stack_sizes Type: SHT_PROGBITS -## 2 stack size entries. Each consists of an address (subject to relocation) -## followed by a ULEB for the size. - Content: "000000000000000010000000000000000020" + Entries: + - Size: 0x10 + - Size: 0x20 Link: .text - Name: '.stack_sizes [1]' Type: SHT_PROGBITS -## One stack size entry. - Content: "200000000000000008" + Entries: + - Address: 0x20 + Size: 0x8 Link: .text.baz - Name: .rela.stack_sizes Type: SHT_RELA @@ -127,7 +128,11 @@ Size: 16 - Name: .stack_sizes Type: SHT_PROGBITS - Content: "100000000000000010200000000000000020" + Entries: + - Address: 0x10 + Size: 0x10 + - Address: 0x20 + Size: 0x20 Link: .text Symbols: - Name: foo @@ -215,7 +220,8 @@ Flags: [SHF_ALLOC] - Name: .stack_sizes Type: SHT_PROGBITS - Content: "000000000000000008" + Entries: + - Size: 0x8 Link: .text2 - Name: .rela.stack_sizes Type: SHT_RELA @@ -328,7 +334,8 @@ - Name: .stack_sizes Type: SHT_PROGBITS Link: .text - Content: "000000000000000008" + Entries: + - Size: 0x8 - Name: .rela.stack_sizes Type: SHT_RELA Info: .stack_sizes @@ -373,7 +380,8 @@ - Name: .stack_sizes Type: SHT_PROGBITS Link: .text - Content: "000000000000000008" + Entries: + - Size: 0x1 ## Check that we handle multiple object files, separately and when they ## are in an archive. This also checks whether we have blank lines between the @@ -589,7 +597,9 @@ Size: 16 - Name: .stack_sizes Type: SHT_PROGBITS - Content: "100000000000000010" + Entries: + - Address: 0x10 + Size: 0x10 Link: .text Symbols: - Name: _Z3foof