[llvm] e2b134b - [yaml2obj] - Stop using square brackets for unique suffixes.
Georgii Rymar via llvm-commits
llvm-commits at lists.llvm.org
Tue May 19 03:00:09 PDT 2020
Author: Georgii Rymar
Date: 2020-05-19T12:59:13+03:00
New Revision: e2b134b01a6b1a201015c69ef83fe1861dd1139b
URL: https://github.com/llvm/llvm-project/commit/e2b134b01a6b1a201015c69ef83fe1861dd1139b
DIFF: https://github.com/llvm/llvm-project/commit/e2b134b01a6b1a201015c69ef83fe1861dd1139b.diff
LOG: [yaml2obj] - Stop using square brackets for unique suffixes.
For describing section/symbol names we can use unique suffixes,
e.g:
```
- Name: '.foo [1]`
- Name: '.foo [2]`
```
It can be a problem (see https://reviews.llvm.org/D79984#inline-734829),
because `[]` are sometimes used to describe a macros:
```
- Name: "[[a0]]"
```
Seems the better approach is to use something else, like "()".
This patch does it and refactors the code related.
Differential revision: https://reviews.llvm.org/D80123
Added:
Modified:
llvm/include/llvm/ObjectYAML/ELFYAML.h
llvm/lib/ObjectYAML/ELFEmitter.cpp
llvm/test/Object/X86/obj2yaml-dup-section-name.s
llvm/test/tools/llvm-dwarfdump/X86/section_sizes_elf.test
llvm/test/tools/llvm-gsymutil/X86/elf-dwarf.yaml
llvm/test/tools/llvm-objcopy/ELF/strip-dwo-groups.test
llvm/test/tools/llvm-readobj/ELF/stack-sizes.test
llvm/test/tools/obj2yaml/ELF/duplicate-symbol-and-section-names.yaml
llvm/test/tools/obj2yaml/ELF/program-headers.yaml
llvm/test/tools/yaml2obj/ELF/call-graph-profile-section.yaml
llvm/test/tools/yaml2obj/ELF/duplicate-section-names.yaml
llvm/test/tools/yaml2obj/ELF/duplicate-symbol-names.yaml
llvm/test/tools/yaml2obj/ELF/stack-sizes.yaml
llvm/tools/obj2yaml/elf2yaml.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/ObjectYAML/ELFYAML.h b/llvm/include/llvm/ObjectYAML/ELFYAML.h
index 7165caf531ba..15224349a6d6 100644
--- a/llvm/include/llvm/ObjectYAML/ELFYAML.h
+++ b/llvm/include/llvm/ObjectYAML/ELFYAML.h
@@ -26,6 +26,7 @@ namespace llvm {
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
diff --git a/llvm/lib/ObjectYAML/ELFEmitter.cpp b/llvm/lib/ObjectYAML/ELFEmitter.cpp
index acdc3078ffb5..2b1de2fff6f5 100644
--- a/llvm/lib/ObjectYAML/ELFEmitter.cpp
+++ b/llvm/lib/ObjectYAML/ELFEmitter.cpp
@@ -401,8 +401,19 @@ bool ELFState<ELFT>::initImplicitHeader(ContiguousBlobAccumulator &CBA,
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);
diff --git a/llvm/test/Object/X86/obj2yaml-dup-section-name.s b/llvm/test/Object/X86/obj2yaml-dup-section-name.s
index 0c480b420c26..17fc7a4d9003 100644
--- a/llvm/test/Object/X86/obj2yaml-dup-section-name.s
+++ b/llvm/test/Object/X86/obj2yaml-dup-section-name.s
@@ -9,16 +9,16 @@
# 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", at progbits,sym1,comdat
diff --git a/llvm/test/tools/llvm-dwarfdump/X86/section_sizes_elf.test b/llvm/test/tools/llvm-dwarfdump/X86/section_sizes_elf.test
index ad1763faaa32..5b2bb5344b2a 100644
--- a/llvm/test/tools/llvm-dwarfdump/X86/section_sizes_elf.test
+++ b/llvm/test/tools/llvm-dwarfdump/X86/section_sizes_elf.test
@@ -39,7 +39,7 @@ Sections:
- Name: .debug_type
Type: SHT_PROGBITS
Size: 13
- - Name: .debug_type [1]
+ - Name: .debug_type (1)
Type: SHT_PROGBITS
Size: 13
- Name: .debug_foo
diff --git a/llvm/test/tools/llvm-gsymutil/X86/elf-dwarf.yaml b/llvm/test/tools/llvm-gsymutil/X86/elf-dwarf.yaml
index bf964d9bf348..38385717d92f 100644
--- a/llvm/test/tools/llvm-gsymutil/X86/elf-dwarf.yaml
+++ b/llvm/test/tools/llvm-gsymutil/X86/elf-dwarf.yaml
@@ -571,7 +571,7 @@ Symbols:
- 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__
diff --git a/llvm/test/tools/llvm-objcopy/ELF/strip-dwo-groups.test b/llvm/test/tools/llvm-objcopy/ELF/strip-dwo-groups.test
index eed3100933c0..e3bdc357ca0b 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/strip-dwo-groups.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/strip-dwo-groups.test
@@ -55,7 +55,7 @@ Sections:
- 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
diff --git a/llvm/test/tools/llvm-readobj/ELF/stack-sizes.test b/llvm/test/tools/llvm-readobj/ELF/stack-sizes.test
index c315749ba425..16b92bb10ec2 100644
--- a/llvm/test/tools/llvm-readobj/ELF/stack-sizes.test
+++ b/llvm/test/tools/llvm-readobj/ELF/stack-sizes.test
@@ -48,7 +48,7 @@ Sections:
- Size: 0x10
- Size: 0x20
Link: .text
- - Name: '.stack_sizes [1]'
+ - Name: '.stack_sizes (1)'
Type: SHT_PROGBITS
Entries:
- Address: 0x20
@@ -67,9 +67,9 @@ Sections:
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
diff --git a/llvm/test/tools/obj2yaml/ELF/duplicate-symbol-and-section-names.yaml b/llvm/test/tools/obj2yaml/ELF/duplicate-symbol-and-section-names.yaml
index 56c0774af0a9..97f90bc9bf1b 100644
--- a/llvm/test/tools/obj2yaml/ELF/duplicate-symbol-and-section-names.yaml
+++ b/llvm/test/tools/obj2yaml/ELF/duplicate-symbol-and-section-names.yaml
@@ -31,23 +31,23 @@
# 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
@@ -59,23 +59,23 @@ FileHeader:
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.
@@ -84,14 +84,14 @@ Symbols:
# 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:
@@ -109,13 +109,13 @@ Sections:
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.
diff --git a/llvm/test/tools/obj2yaml/ELF/program-headers.yaml b/llvm/test/tools/obj2yaml/ELF/program-headers.yaml
index 740d34971c9d..2a240d1710dd 100644
--- a/llvm/test/tools/obj2yaml/ELF/program-headers.yaml
+++ b/llvm/test/tools/obj2yaml/ELF/program-headers.yaml
@@ -55,7 +55,7 @@
# 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
@@ -123,7 +123,7 @@ ProgramHeaders:
- Type: PT_LOAD
Flags: [ PF_R ]
Sections:
- - Section: '.foo [1]'
+ - Section: '.foo (1)'
- Section: .baz
VAddr: 0x2000
Align: 0x1000
@@ -209,7 +209,7 @@ Sections:
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
Address: 0x1008
Size: 0x8
- - Name: '.foo [1]'
+ - Name: '.foo (1)'
Type: SHT_PROGBITS
Flags: [ SHF_ALLOC ]
Address: 0x2000
diff --git a/llvm/test/tools/yaml2obj/ELF/call-graph-profile-section.yaml b/llvm/test/tools/yaml2obj/ELF/call-graph-profile-section.yaml
index a4ca37bd2aab..7885292a8d6b 100644
--- a/llvm/test/tools/yaml2obj/ELF/call-graph-profile-section.yaml
+++ b/llvm/test/tools/yaml2obj/ELF/call-graph-profile-section.yaml
@@ -142,12 +142,12 @@ Sections:
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
diff --git a/llvm/test/tools/yaml2obj/ELF/duplicate-section-names.yaml b/llvm/test/tools/yaml2obj/ELF/duplicate-section-names.yaml
index e681ff1d1a48..93605b2b92fe 100644
--- a/llvm/test/tools/yaml2obj/ELF/duplicate-section-names.yaml
+++ b/llvm/test/tools/yaml2obj/ELF/duplicate-section-names.yaml
@@ -2,12 +2,16 @@
## containing sections with duplicate names (but
diff erent 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:
@@ -20,17 +24,23 @@ Sections:
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:
@@ -39,11 +49,11 @@ 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
@@ -102,13 +112,13 @@ FileHeader:
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.
@@ -156,16 +166,16 @@ Sections:
- 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)'
diff --git a/llvm/test/tools/yaml2obj/ELF/duplicate-symbol-names.yaml b/llvm/test/tools/yaml2obj/ELF/duplicate-symbol-names.yaml
index a889254e4fca..20c1dcb3af25 100644
--- a/llvm/test/tools/yaml2obj/ELF/duplicate-symbol-names.yaml
+++ b/llvm/test/tools/yaml2obj/ELF/duplicate-symbol-names.yaml
@@ -15,13 +15,13 @@ FileHeader:
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:
@@ -30,9 +30,9 @@ 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
@@ -94,7 +94,7 @@ Sections:
Symbol: foo
- Offset: 0x1
Type: R_X86_64_NONE
- Symbol: 'foo [1]'
+ Symbol: 'foo (1)'
Symbols:
- Name: foo
- - Name: 'foo [1]'
+ - Name: 'foo (1)'
diff --git a/llvm/test/tools/yaml2obj/ELF/stack-sizes.yaml b/llvm/test/tools/yaml2obj/ELF/stack-sizes.yaml
index 12a88bda7034..28ed9dcae005 100644
--- a/llvm/test/tools/yaml2obj/ELF/stack-sizes.yaml
+++ b/llvm/test/tools/yaml2obj/ELF/stack-sizes.yaml
@@ -50,15 +50,15 @@ FileHeader:
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: ""
@@ -287,12 +287,12 @@ FileHeader:
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
diff --git a/llvm/tools/obj2yaml/elf2yaml.cpp b/llvm/tools/obj2yaml/elf2yaml.cpp
index fe3f36f4e6da..8602477a3a4a 100644
--- a/llvm/tools/obj2yaml/elf2yaml.cpp
+++ b/llvm/tools/obj2yaml/elf2yaml.cpp
@@ -129,7 +129,7 @@ ELFDumper<ELFT>::getUniquedSectionName(const Elf_Shdr *Sec) {
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;
@@ -161,7 +161,7 @@ ELFDumper<ELFT>::getUniquedSymbolName(const Elf_Sym *Sym, StringRef StrTable,
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];
More information about the llvm-commits
mailing list