Skip to content

Commit 6da44ad

Browse files
author
George Rimar
committed
[yaml2obj][obj2yaml] - Change how symbol's binding is descibed when parsing/dumping.
Currently, YAML has the following syntax for describing the symbols: Symbols: Local: LocalSymbol1: ... LocalSymbol2: ... ... Global: GlobalSymbol1: ... Weak: ... GNUUnique: I.e. symbols are grouped by their bindings. That is not very convenient, because: It does not allow to set a custom binding, what can be useful for producing broken/special outputs for test cases. Adding a new binding would require to change a syntax (what we observed when added GNUUnique recently). It does not allow to change the order of the symbols in .symtab/.dynsym, i.e. currently all Local symbols are placed first, then Global, Weak and GNUUnique are following, but we are not able to change the order. It is not consistent. Binding is just one of the properties of the symbol, we do not group them by other properties. It makes the code more complex that it can be. This patch shows it can be simplified with the change performed. The patch changes the syntax to just: Symbols: Symbol1: ... Symbol2: ... ... With that, we are able to work with the binding field just like with any other symbol property. Differential revision: https://reviews.llvm.org/D60122 llvm-svn: 357595
1 parent f5b181e commit 6da44ad

File tree

119 files changed

+1409
-1342
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

119 files changed

+1409
-1342
lines changed

llvm/include/llvm/ObjectYAML/ELFYAML.h

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_RSS)
5252
// Just use 64, since it can hold 32-bit values too.
5353
LLVM_YAML_STRONG_TYPEDEF(uint64_t, ELF_SHF)
5454
LLVM_YAML_STRONG_TYPEDEF(uint16_t, ELF_SHN)
55+
LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_STB)
5556
LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_STT)
5657
LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_STV)
5758
LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_STO)
@@ -97,18 +98,12 @@ struct Symbol {
9798
ELF_STT Type;
9899
StringRef Section;
99100
Optional<ELF_SHN> Index;
101+
ELF_STB Binding;
100102
llvm::yaml::Hex64 Value;
101103
llvm::yaml::Hex64 Size;
102104
uint8_t Other;
103105
};
104106

105-
struct SymbolsDef {
106-
std::vector<Symbol> Local;
107-
std::vector<Symbol> Global;
108-
std::vector<Symbol> Weak;
109-
std::vector<Symbol> GNUUnique;
110-
};
111-
112107
struct SectionOrType {
113108
StringRef sectionNameOrType;
114109
};
@@ -289,8 +284,8 @@ struct Object {
289284
// cleaner and nicer if we read them from the YAML as a separate
290285
// top-level key, which automatically ensures that invariants like there
291286
// being a single SHT_SYMTAB section are upheld.
292-
SymbolsDef Symbols;
293-
SymbolsDef DynamicSymbols;
287+
std::vector<Symbol> Symbols;
288+
std::vector<Symbol> DynamicSymbols;
294289
};
295290

296291
} // end namespace ELFYAML
@@ -362,6 +357,10 @@ template <> struct ScalarEnumerationTraits<ELFYAML::ELF_SHN> {
362357
static void enumeration(IO &IO, ELFYAML::ELF_SHN &Value);
363358
};
364359

360+
template <> struct ScalarEnumerationTraits<ELFYAML::ELF_STB> {
361+
static void enumeration(IO &IO, ELFYAML::ELF_STB &Value);
362+
};
363+
365364
template <>
366365
struct ScalarEnumerationTraits<ELFYAML::ELF_STT> {
367366
static void enumeration(IO &IO, ELFYAML::ELF_STT &Value);
@@ -437,10 +436,6 @@ struct MappingTraits<ELFYAML::Symbol> {
437436
static StringRef validate(IO &IO, ELFYAML::Symbol &Symbol);
438437
};
439438

440-
template <> struct MappingTraits<ELFYAML::SymbolsDef> {
441-
static void mapping(IO &IO, ELFYAML::SymbolsDef &Symbols);
442-
};
443-
444439
template <> struct MappingTraits<ELFYAML::DynamicEntry> {
445440
static void mapping(IO &IO, ELFYAML::DynamicEntry &Rel);
446441
};

llvm/lib/ObjectYAML/ELFYAML.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,17 @@ void ScalarEnumerationTraits<ELFYAML::ELF_SHN>::enumeration(
560560
IO.enumFallback<Hex32>(Value);
561561
}
562562

563+
void ScalarEnumerationTraits<ELFYAML::ELF_STB>::enumeration(
564+
IO &IO, ELFYAML::ELF_STB &Value) {
565+
#define ECase(X) IO.enumCase(Value, #X, ELF::X)
566+
ECase(STB_LOCAL);
567+
ECase(STB_GLOBAL);
568+
ECase(STB_WEAK);
569+
ECase(STB_GNU_UNIQUE);
570+
#undef ECase
571+
IO.enumFallback<Hex8>(Value);
572+
}
573+
563574
void ScalarEnumerationTraits<ELFYAML::ELF_STT>::enumeration(
564575
IO &IO, ELFYAML::ELF_STT &Value) {
565576
#define ECase(X) IO.enumCase(Value, #X, ELF::X)
@@ -845,9 +856,9 @@ void MappingTraits<ELFYAML::Symbol>::mapping(IO &IO, ELFYAML::Symbol &Symbol) {
845856
IO.mapOptional("Type", Symbol.Type, ELFYAML::ELF_STT(0));
846857
IO.mapOptional("Section", Symbol.Section, StringRef());
847858
IO.mapOptional("Index", Symbol.Index);
859+
IO.mapOptional("Binding", Symbol.Binding, ELFYAML::ELF_STB(0));
848860
IO.mapOptional("Value", Symbol.Value, Hex64(0));
849861
IO.mapOptional("Size", Symbol.Size, Hex64(0));
850-
851862
MappingNormalization<NormalizedOther, uint8_t> Keys(IO, Symbol.Other);
852863
IO.mapOptional("Visibility", Keys->Visibility, ELFYAML::ELF_STV(0));
853864
IO.mapOptional("Other", Keys->Other, ELFYAML::ELF_STO(0));
@@ -864,14 +875,6 @@ StringRef MappingTraits<ELFYAML::Symbol>::validate(IO &IO,
864875
return StringRef();
865876
}
866877

867-
void MappingTraits<ELFYAML::SymbolsDef>::mapping(IO &IO,
868-
ELFYAML::SymbolsDef &Symbols) {
869-
IO.mapOptional("Local", Symbols.Local);
870-
IO.mapOptional("Global", Symbols.Global);
871-
IO.mapOptional("Weak", Symbols.Weak);
872-
IO.mapOptional("GNUUnique", Symbols.GNUUnique);
873-
}
874-
875878
static void commonSectionMapping(IO &IO, ELFYAML::Section &Section) {
876879
IO.mapOptional("Name", Section.Name, StringRef());
877880
IO.mapRequired("Type", Section.Type);

llvm/test/DebugInfo/invalid-relocations.test

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ Sections:
2828
Symbol: _start
2929
Type: 0xFF
3030
Symbols:
31-
Global:
32-
- Name: _start
33-
Type: STT_FUNC
34-
Section: .text
35-
Value: 0x0
31+
- Name: _start
32+
Type: STT_FUNC
33+
Section: .text
34+
Value: 0x0
35+
Binding: STB_GLOBAL

llvm/test/Object/AArch64/yaml2obj-elf-aarch64-rel.yaml

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,11 @@ Sections:
4343
Addend: 0
4444

4545
Symbols:
46-
Local:
47-
- Name: .text
48-
Type: STT_SECTION
49-
Section: .text
50-
51-
Global:
52-
- Name: main
53-
Type: STT_FUNC
54-
Section: .text
55-
Size: 0x08
46+
- Name: .text
47+
Type: STT_SECTION
48+
Section: .text
49+
- Name: main
50+
Type: STT_FUNC
51+
Section: .text
52+
Size: 0x08
53+
Binding: STB_GLOBAL

llvm/test/Object/AMDGPU/elf64-relocs.yaml

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,11 @@ Sections:
6565
Type: R_AMDGPU_RELATIVE64
6666

6767
Symbols:
68-
Local:
69-
- Name: .text
70-
Type: STT_SECTION
71-
Section: .text
72-
73-
Global:
74-
- Name: main
75-
Type: STT_FUNC
76-
Section: .text
77-
Size: 0x08
68+
- Name: .text
69+
Type: STT_SECTION
70+
Section: .text
71+
- Name: main
72+
Type: STT_FUNC
73+
Section: .text
74+
Size: 0x08
75+
Binding: STB_GLOBAL

llvm/test/Object/Lanai/yaml2obj-elf-lanai-rel.yaml

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,11 @@ Sections:
4949

5050

5151
Symbols:
52-
Local:
53-
- Name: .text
54-
Type: STT_SECTION
55-
Section: .text
56-
57-
Global:
58-
- Name: main
59-
Type: STT_FUNC
60-
Section: .text
61-
Size: 0x08
52+
- Name: .text
53+
Type: STT_SECTION
54+
Section: .text
55+
- Name: main
56+
Type: STT_FUNC
57+
Section: .text
58+
Size: 0x08
59+
Binding: STB_GLOBAL

llvm/test/Object/Mips/abi-flags.yaml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ Sections:
5959
Flags2: 0x0
6060

6161
Symbols:
62-
Local:
63-
- Name: .MIPS.abiflags
64-
Type: STT_SECTION
65-
Section: .MIPS.abiflags
62+
- Name: .MIPS.abiflags
63+
Type: STT_SECTION
64+
Section: .MIPS.abiflags

llvm/test/Object/Mips/elf-abi.yaml

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ Sections:
6262
Size: 4
6363

6464
Symbols:
65-
Global:
66-
- Name: T1
67-
Section: .text
68-
Value: 0
69-
Size: 4
65+
- Name: T1
66+
Section: .text
67+
Value: 0
68+
Size: 4
69+
Binding: STB_GLOBAL
7070

7171
# o64
7272
--- !ELF
@@ -84,11 +84,11 @@ Sections:
8484
Size: 4
8585

8686
Symbols:
87-
Global:
88-
- Name: T1
89-
Section: .text
90-
Value: 0
91-
Size: 4
87+
- Name: T1
88+
Section: .text
89+
Value: 0
90+
Size: 4
91+
Binding: STB_GLOBAL
9292

9393
# eabio32
9494
--- !ELF
@@ -106,11 +106,11 @@ Sections:
106106
Size: 4
107107

108108
Symbols:
109-
Global:
110-
- Name: T1
111-
Section: .text
112-
Value: 0
113-
Size: 4
109+
- Name: T1
110+
Section: .text
111+
Value: 0
112+
Size: 4
113+
Binding: STB_GLOBAL
114114

115115
# eabi64
116116
--- !ELF
@@ -128,9 +128,9 @@ Sections:
128128
Size: 4
129129

130130
Symbols:
131-
Global:
132-
- Name: T1
133-
Section: .text
134-
Value: 0
135-
Size: 4
131+
- Name: T1
132+
Section: .text
133+
Value: 0
134+
Size: 4
135+
Binding: STB_GLOBAL
136136
...

llvm/test/Object/Mips/elf-flags.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ Sections:
4444
Size: 4
4545

4646
Symbols:
47-
Global:
48-
- Name: T1
49-
Section: .text
50-
Value: 0
51-
Size: 4
47+
- Name: T1
48+
Section: .text
49+
Value: 0
50+
Size: 4
51+
Binding: STB_GLOBAL
5252
...

llvm/test/Object/Mips/elf-mips64-rel.yaml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,17 @@ Sections:
9898
Size: 0x0F
9999

100100
Symbols:
101-
Local:
102-
- Name: .text
103-
Type: STT_SECTION
104-
Section: .text
105-
- Name: .rodata
106-
Type: STT_SECTION
107-
Section: .rodata
108-
Global:
109-
- Name: main
110-
Type: STT_FUNC
111-
Section: .text
112-
Size: 0x58
113-
- Name: printf
101+
- Name: .text
102+
Type: STT_SECTION
103+
Section: .text
104+
- Name: .rodata
105+
Type: STT_SECTION
106+
Section: .rodata
107+
- Name: main
108+
Type: STT_FUNC
109+
Section: .text
110+
Size: 0x58
111+
Binding: STB_GLOBAL
112+
- Name: printf
113+
Binding: STB_GLOBAL
114114
...

llvm/test/Object/X86/yaml-elf-x86-rel-broken.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@ Sections:
2828
Symbol: main
2929
Type: 0xFF
3030
Symbols:
31-
Global:
32-
- Name: main
31+
- Name: main
32+
Binding: STB_GLOBAL

llvm/test/Object/X86/yaml2obj-elf-x86-rel.yaml

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,11 @@ Sections:
3030
Type: R_386_32
3131

3232
Symbols:
33-
Local:
34-
- Name: .text
35-
Type: STT_SECTION
36-
Section: .text
37-
38-
Global:
39-
- Name: main
40-
Type: STT_FUNC
41-
Section: .text
42-
Size: 0x08
33+
- Name: .text
34+
Type: STT_SECTION
35+
Section: .text
36+
- Name: main
37+
Type: STT_FUNC
38+
Section: .text
39+
Size: 0x08
40+
Binding: STB_GLOBAL

llvm/test/Object/obj2yaml-invalid-reloc.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@ CHECK-NEXT: - Offset: 0x0000000000000000
2424
CHECK-NEXT: Symbol: ''
2525
CHECK-NEXT: Type: R_X86_64_NONE
2626
CHECK-NEXT: Symbols:
27-
CHECK-NEXT: Local:
2827
CHECK-NEXT: - Name: rb_ary_new_capa
2928
CHECK-NEXT: Type: STT_FUNC
3029
CHECK-NEXT: Section: .text
3130
CHECK-NEXT: Size: 0x0000000000000005
32-
CHECK-NEXT: Global:
3331
CHECK-NEXT: - Name: __dtraceenabled_ruby___array-create
3432
CHECK-NEXT: Index: SHN_ABS
33+
CHECK-NEXT: Binding: STB_GLOBAL
3534
CHECK-NEXT: - Name: '$dtrace1316529.rb_ary_new_capa'
3635
CHECK-NEXT: Type: STT_FUNC
3736
CHECK-NEXT: Section: .text
37+
CHECK-NEXT: Binding: STB_GLOBAL
3838
CHECK-NEXT: Size: 0x0000000000000005
3939
CHECK-NEXT: Visibility: STV_HIDDEN

0 commit comments

Comments
 (0)