namespace ELFYAML {
StringRef dropUniqueSuffix(StringRef S);
+std::string appendUniqueSuffix(StringRef Name, const Twine& Msg);
// 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
return true;
}
+constexpr StringRef SuffixStart = " (";
+constexpr char SuffixEnd = ')';
+
+std::string llvm::ELFYAML::appendUniqueSuffix(StringRef Name,
+ const Twine &Msg) {
+ return (Name + SuffixStart + Msg + Twine(SuffixEnd)).str();
+}
+
StringRef llvm::ELFYAML::dropUniqueSuffix(StringRef S) {
- size_t SuffixPos = S.rfind(" [");
+ if (S.empty() || S.back() != SuffixEnd)
+ return S;
+
+ size_t SuffixPos = S.rfind(SuffixStart);
if (SuffixPos == StringRef::npos)
return S;
return S.substr(0, SuffixPos);
# CHECK: - Name: .text.foo{{$}}
# CHECK: - Name: .rela.text.foo{{$}}
# CHECK: Info: .text.foo{{$}}
-# CHECK: - Name: '.group [1]'
+# CHECK: - Name: '.group (1)'
# CHECK: Members:
-# CHECK: - SectionOrType: '.text.foo [1]'
-# CHECK: - SectionOrType: '.rela.text.foo [1]'
-# CHECK: - Name: '.text.foo [1]'
-# CHECK: - Name: '.rela.text.foo [1]'
-# CHECK: Info: '.text.foo [1]'
+# CHECK: - SectionOrType: '.text.foo (1)'
+# CHECK: - SectionOrType: '.rela.text.foo (1)'
+# CHECK: - Name: '.text.foo (1)'
+# CHECK: - Name: '.rela.text.foo (1)'
+# CHECK: Info: '.text.foo (1)'
# CHECK: Symbols:
# CHECK: Section: .group{{$}}
-# CHECK: Section: '.group [1]'
+# CHECK: Section: '.group (1)'
.section .text.foo,"axG",@progbits,sym1,comdat
- Name: .debug_type
Type: SHT_PROGBITS
Size: 13
- - Name: .debug_type [1]
+ - Name: .debug_type (1)
Type: SHT_PROGBITS
Size: 13
- Name: .debug_foo
- Name: main.cpp
Type: STT_FILE
Index: SHN_ABS
- - Name: 'crtstuff.c [1]'
+ - Name: 'crtstuff.c (1)'
Type: STT_FILE
Index: SHN_ABS
- Name: __FRAME_END__
- Name: .text.group1
Type: SHT_PROGBITS
Flags: [ SHF_ALLOC, SHF_EXECINSTR, SHF_GROUP ]
- - Name: '.group [1]'
+ - Name: '.group (1)'
Type: SHT_GROUP
Link: .symtab
Info: group2
- Size: 0x10
- Size: 0x20
Link: .text
- - Name: '.stack_sizes [1]'
+ - Name: '.stack_sizes (1)'
Type: SHT_PROGBITS
Entries:
- Address: 0x20
Addend: 16
Symbol: .text
Type: R_X86_64_64
- - Name: '.rela.stack_sizes [1]'
+ - Name: '.rela.stack_sizes (1)'
Type: SHT_RELA
- Info: '.stack_sizes [1]'
+ Info: '.stack_sizes (1)'
Relocations:
- Offset: 0
Symbol: separate_text_section_baz
# CASE1-NEXT: Sections:
# CASE1-NEXT: - Name: .foo
# CASE1-NEXT: Type: SHT_PROGBITS
-# CASE1-NEXT: - Name: '.foo [1]'
+# CASE1-NEXT: - Name: '.foo (1)'
# CASE1-NEXT: Type: SHT_PROGBITS
-# CASE1-NEXT: - Name: '.foo [2]'
+# CASE1-NEXT: - Name: '.foo (2)'
# CASE1-NEXT: Type: SHT_PROGBITS
# CASE1-NEXT: - Name: .bar
# CASE1-NEXT: Type: SHT_PROGBITS
-# CASE1-NEXT: - Name: '.bar [1]'
+# CASE1-NEXT: - Name: '.bar (1)'
# CASE1-NEXT: Type: SHT_PROGBITS
-# CASE1-NEXT: - Name: '.bar [2]'
+# CASE1-NEXT: - Name: '.bar (2)'
# CASE1-NEXT: Type: SHT_PROGBITS
# CASE1-NEXT: Symbols:
# CASE1-NEXT: - Name: localfoo
-# CASE1-NEXT: - Name: 'localfoo [1]'
-# CASE1-NEXT: - Name: 'localfoo [2]'
+# CASE1-NEXT: - Name: 'localfoo (1)'
+# CASE1-NEXT: - Name: 'localfoo (2)'
# CASE1-NEXT: - Name: localbar
-# CASE1-NEXT: - Name: 'localbar [1]'
-# CASE1-NEXT: - Name: 'localbar [2]'
+# CASE1-NEXT: - Name: 'localbar (1)'
+# CASE1-NEXT: - Name: 'localbar (2)'
# CASE1-NEXT: ...
--- !ELF
Sections:
- Name: .foo
Type: SHT_PROGBITS
- - Name: '.foo [555]'
+ - Name: '.foo (555)'
Type: SHT_PROGBITS
- - Name: '.foo [random_tag]'
+ - Name: '.foo (random_tag)'
Type: SHT_PROGBITS
- Name: .bar
Type: SHT_PROGBITS
- - Name: '.bar [666]'
+ - Name: '.bar (666)'
Type: SHT_PROGBITS
- - Name: '.bar [random_tag]'
+ - Name: '.bar (random_tag)'
Type: SHT_PROGBITS
Symbols:
- - Name: 'localfoo [111]'
- - Name: 'localfoo [222]'
- - Name: 'localfoo [random_tag]'
- - Name: 'localbar [333]'
- - Name: 'localbar [444]'
- - Name: 'localbar [random_tag]'
+ - Name: 'localfoo (111)'
+ - Name: 'localfoo (222)'
+ - Name: 'localfoo (random_tag)'
+ - Name: 'localbar (333)'
+ - Name: 'localbar (444)'
+ - Name: 'localbar (random_tag)'
## Check we can refer to symbols with the same
## name from relocations.
# RUN: obj2yaml %t2 | FileCheck %s --check-prefix=CASE2
# CASE2: Relocations:
-# CASE2-NEXT: - Symbol: 'foo [1]'
+# CASE2-NEXT: - Symbol: 'foo (1)'
# CASE2-NEXT: Type: R_X86_64_PC32
# CASE2-NEXT: - Offset: 0x0000000000000004
# CASE2-NEXT: Symbol: foo
# CASE2-NEXT: Type: R_X86_64_PC32
# CASE2-NEXT: Symbols:
# CASE2-NEXT: - Name: foo
-# CASE2-NEXT: - Name: 'foo [1]'
+# CASE2-NEXT: - Name: 'foo (1)'
--- !ELF
FileHeader:
Link: .symtab
Relocations:
- Type: R_X86_64_PC32
- Symbol: 'foo [1]'
+ Symbol: 'foo (1)'
- Type: R_X86_64_PC32
Offset: 4
Symbol: foo
Symbols:
- Name: foo
- - Name: 'foo [1]'
+ - Name: 'foo (1)'
## Check obj2yaml does not add a suffix to a name if the
## symbol is in .symtab and .dynsym at the same time.
# YAML-NEXT: - Type: PT_LOAD
# YAML-NEXT: Flags: [ PF_R ]
# YAML-NEXT: Sections:
-# YAML-NEXT: - Section: '.foo [1]'
+# YAML-NEXT: - Section: '.foo (1)'
# YAML-NEXT: - Section: .baz
# YAML-NEXT: VAddr: 0x0000000000002000
# YAML-NEXT: Align: 0x0000000000001000
- Type: PT_LOAD
Flags: [ PF_R ]
Sections:
- - Section: '.foo [1]'
+ - Section: '.foo (1)'
- Section: .baz
VAddr: 0x2000
Align: 0x1000
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
Address: 0x1008
Size: 0x8
- - Name: '.foo [1]'
+ - Name: '.foo (1)'
Type: SHT_PROGBITS
Flags: [ SHF_ALLOC ]
Address: 0x2000
Weight: 10
## Case 2: Test we can refer to symbols with suffixes.
- From: foo
- To: 'foo [1]'
+ To: 'foo (1)'
Weight: 30
Symbols:
- Name: foo
- Name: bar
- - Name: 'foo [1]'
+ - Name: 'foo (1)'
## Check we can describe SHT_LLVM_CALL_GRAPH_PROFILE sections using the "Content" tag.
# RUN: yaml2obj --docnum=5 %s -o %t.content
## containing sections with duplicate names (but different name suffixes).
# RUN: yaml2obj --docnum=1 %s -o %t1
-# RUN: llvm-readobj -s %t1 | FileCheck %s --check-prefix=CASE1
+# RUN: llvm-readelf -sections %t1 | FileCheck %s --check-prefix=CASE1
-# CASE1: Name: .foo1 (
-# CASE1: Name: .foo (
-# CASE1: Name: .foo (
-# CASE1: Name: .foo2 (
+# CASE1: [Nr] Name Type
+# CASE1: [ 1] .foo1 PROGBITS
+# CASE1-NEXT: [ 2] .foo PROGBITS
+# CASE1-NEXT: [ 3] .foo PROGBITS
+# CASE1-NEXT: [ 4] .foo2 PROGBITS
+# CASE1-NEXT: [ 5] .foo2 ( PROGBITS
+# CASE1-NEXT: [ 6] .foo2 ) PROGBITS
+# CASE1-NEXT: [ 7] .foo2 PROGBITS
--- !ELF
FileHeader:
Type: SHT_PROGBITS
- Name: .foo
Type: SHT_PROGBITS
- - Name: '.foo [1]'
+ - Name: '.foo (1)'
Type: SHT_PROGBITS
- Name: .foo2
Type: SHT_PROGBITS
+ - Name: '.foo2 ('
+ Type: SHT_PROGBITS
+ - Name: '.foo2 )'
+ Type: SHT_PROGBITS
+ - Name: '.foo2 ()'
+ Type: SHT_PROGBITS
## Check that yaml2obj reports an error in case we have
## sections with equal names and suffixes.
# RUN: not yaml2obj --docnum=2 %s 2>&1 | FileCheck %s --check-prefix=CASE2
-# CASE2: error: repeated section/fill name: '.foo [1]' at YAML section/fill number 2
-# CASE2: error: repeated section/fill name: '.foo [1]' at YAML section/fill number 3
+# CASE2: error: repeated section/fill name: '.foo (1)' at YAML section/fill number 2
+# CASE2: error: repeated section/fill name: '.foo (1)' at YAML section/fill number 3
--- !ELF
FileHeader:
Type: ET_REL
Machine: EM_X86_64
Sections:
- - Name: '.foo [1]'
+ - Name: '.foo (1)'
Type: SHT_PROGBITS
- - Name: '.foo [1]'
+ - Name: '.foo (1)'
Type: SHT_PROGBITS
- - Name: '.foo [1]'
+ - Name: '.foo (1)'
Type: SHT_PROGBITS
## Check that yaml2obj reports an error in case we have
Sections:
- Name: .foo
Type: SHT_PROGBITS
- - Name: '.foo [1]'
+ - Name: '.foo (1)'
Type: SHT_PROGBITS
Symbols:
- Name: foo
Section: .foo
- Name: bar
- Section: '.foo [1]'
+ Section: '.foo (1)'
## Check that yaml2obj can produce SHT_GROUP sections that
## reference sections and symbols with name suffixes.
- SectionOrType: .text.foo
- Name: .text.foo
Type: SHT_PROGBITS
- - Name: '.group [1]'
+ - Name: '.group (1)'
Type: SHT_GROUP
- Info: 'foo [1]'
+ Info: 'foo (1)'
Members:
- SectionOrType: GRP_COMDAT
- - SectionOrType: '.text.foo [1]'
- - Name: '.text.foo [1]'
+ - SectionOrType: '.text.foo (1)'
+ - Name: '.text.foo (1)'
Type: SHT_PROGBITS
Symbols:
- Name: foo
Section: .text.foo
- - Name: 'foo [1]'
- Section: '.text.foo [1]'
+ - Name: 'foo (1)'
+ Section: '.text.foo (1)'
Machine: EM_X86_64
Symbols:
- Name: localfoo
- - Name: 'localfoo [1]'
+ - Name: 'localfoo (1)'
## Check that yaml2obj reports an error when we have
## symbols with equal names and suffixes.
# RUN: not yaml2obj --docnum=2 %s 2>&1| FileCheck %s --check-prefix=CASE2
-# CASE2-COUNT-2: error: repeated symbol name: 'localfoo [1]'
+# CASE2-COUNT-2: error: repeated symbol name: 'localfoo (1)'
--- !ELF
FileHeader:
Type: ET_REL
Machine: EM_X86_64
Symbols:
- - Name: 'localfoo [1]'
- - Name: 'localfoo [1]'
- - Name: 'localfoo [1]'
+ - Name: 'localfoo (1)'
+ - Name: 'localfoo (1)'
+ - Name: 'localfoo (1)'
## Check that yaml2obj reports an error when we have
## symbols without suffixes in the names and their
Symbol: foo
- Offset: 0x1
Type: R_X86_64_NONE
- Symbol: 'foo [1]'
+ Symbol: 'foo (1)'
Symbols:
- Name: foo
- - Name: 'foo [1]'
+ - Name: 'foo (1)'
Machine: EM_X86_64
Sections:
## Valid.
- - Name: '.stack_sizes [1]'
+ - Name: '.stack_sizes (1)'
Type: SHT_PROGBITS
Content: "100000000000000020"
## Truncated.
- - Name: '.stack_sizes [2]'
+ - Name: '.stack_sizes (2)'
Type: SHT_PROGBITS
Content: "1000000000000000"
## Empty.
- - Name: '.stack_sizes [3]'
+ - Name: '.stack_sizes (3)'
Type: SHT_PROGBITS
Content: ""
Type: ET_EXEC
Machine: EM_X86_64
Sections:
- - Name: '.stack_sizes [1]'
+ - Name: '.stack_sizes (1)'
Type: SHT_PROGBITS
Entries:
- Address: 0x10
Size: 0x20
- - Name: '.stack_sizes [2]'
+ - Name: '.stack_sizes (2)'
Type: SHT_PROGBITS
Entries:
- Address: 0x30
auto It = UsedSectionNames.insert({Name, 0});
if (!It.second)
- Ret = (Name + " [" + Twine(++It.first->second) + "]").str();
+ Ret = ELFYAML::appendUniqueSuffix(Name, Twine(++It.first->second));
else
Ret = std::string(Name);
return Ret;
auto It = UsedSymbolNames.insert({Name, 0});
if (!It.second)
SymbolNames[Index] =
- (Name + " [" + Twine(++It.first->second) + "]").str();
+ ELFYAML::appendUniqueSuffix(Name, Twine(++It.first->second));
else
SymbolNames[Index] = std::string(Name);
return SymbolNames[Index];