llvm.org GIT mirror llvm / 3c9a2ee
[yaml2obj][obj2yaml] Support ELF symbol's visibility flags (default/hidden/protected). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210316 91177308-0d34-0410-b5e6-96231b3b80d8 Simon Atanasyan 5 years ago
5 changed file(s) with 146 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
4343 // Just use 64, since it can hold 32-bit values too.
4444 LLVM_YAML_STRONG_TYPEDEF(uint64_t, ELF_SHF)
4545 LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_STT)
46 LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_STV)
4647
4748 // For now, hardcode 64 bits everywhere that 32 or 64 would be needed
4849 // since 64-bit can hold 32-bit values too.
6162 StringRef Section;
6263 llvm::yaml::Hex64 Value;
6364 llvm::yaml::Hex64 Size;
65 ELF_STV Visibility;
6466 };
6567 struct LocalGlobalWeakSymbols {
6668 std::vector Local;
167169 };
168170
169171 template <>
172 struct ScalarEnumerationTraits {
173 static void enumeration(IO &IO, ELFYAML::ELF_STV &Value);
174 };
175
176 template <>
170177 struct ScalarEnumerationTraits {
171178 static void enumeration(IO &IO, ELFYAML::ELF_REL &Value);
172179 };
364364 ECase(STT_COMMON)
365365 ECase(STT_TLS)
366366 ECase(STT_GNU_IFUNC)
367 #undef ECase
368 }
369
370 void ScalarEnumerationTraits::enumeration(
371 IO &IO, ELFYAML::ELF_STV &Value) {
372 #define ECase(X) IO.enumCase(Value, #X, ELF::X);
373 ECase(STV_DEFAULT)
374 ECase(STV_INTERNAL)
375 ECase(STV_HIDDEN)
376 ECase(STV_PROTECTED)
367377 #undef ECase
368378 }
369379
648658 IO.mapOptional("Section", Symbol.Section, StringRef());
649659 IO.mapOptional("Value", Symbol.Value, Hex64(0));
650660 IO.mapOptional("Size", Symbol.Size, Hex64(0));
661 IO.mapOptional("Visibility", Symbol.Visibility, ELFYAML::ELF_STV(0));
651662 }
652663
653664 void MappingTraits::mapping(
0 # RUN: yaml2obj -format=elf %s | llvm-readobj -symbols - | \
1 # RUN: FileCheck --check-prefix OBJ %s
2 # RUN: yaml2obj -format=elf %s | obj2yaml - | FileCheck --check-prefix YAML %s
3
4 # OBJ: Symbol {
5 # OBJ: Name: default1 (36)
6 # OBJ-NEXT: Value: 0x0
7 # OBJ-NEXT: Size: 4
8 # OBJ-NEXT: Binding: Global (0x1)
9 # OBJ-NEXT: Type: Object (0x1)
10 # OBJ-NEXT: Other: 0
11 # OBJ-NEXT: Section: .data (0x1)
12 # OBJ-NEXT: }
13 # OBJ-NEXT: Symbol {
14 # OBJ-NEXT: Name: default2 (27)
15 # OBJ-NEXT: Value: 0x4
16 # OBJ-NEXT: Size: 4
17 # OBJ-NEXT: Binding: Global (0x1)
18 # OBJ-NEXT: Type: Object (0x1)
19 # OBJ-NEXT: Other: 0
20 # OBJ-NEXT: Section: .data (0x1)
21 # OBJ-NEXT: }
22 # OBJ-NEXT: Symbol {
23 # OBJ-NEXT: Name: internal (8)
24 # OBJ-NEXT: Value: 0x8
25 # OBJ-NEXT: Size: 4
26 # OBJ-NEXT: Binding: Global (0x1)
27 # OBJ-NEXT: Type: Object (0x1)
28 # OBJ-NEXT: Other: 1
29 # OBJ-NEXT: Section: .data (0x1)
30 # OBJ-NEXT: }
31 # OBJ-NEXT: Symbol {
32 # OBJ-NEXT: Name: hidden (1)
33 # OBJ-NEXT: Value: 0xC
34 # OBJ-NEXT: Size: 4
35 # OBJ-NEXT: Binding: Global (0x1)
36 # OBJ-NEXT: Type: Object (0x1)
37 # OBJ-NEXT: Other: 2
38 # OBJ-NEXT: Section: .data (0x1)
39 # OBJ-NEXT: }
40 # OBJ-NEXT: Symbol {
41 # OBJ-NEXT: Name: protected (17)
42 # OBJ-NEXT: Value: 0x10
43 # OBJ-NEXT: Size: 4
44 # OBJ-NEXT: Binding: Global (0x1)
45 # OBJ-NEXT: Type: Object (0x1)
46 # OBJ-NEXT: Other: 3
47 # OBJ-NEXT: Section: .data (0x1)
48 # OBJ-NEXT: }
49
50 # YAML: Symbols:
51 # YAML-NEXT: Global:
52 # YAML-NEXT: - Name: default1
53 # YAML-NEXT: Type: STT_OBJECT
54 # YAML-NEXT: Section: .data
55 # YAML-NEXT: Size: 0x0000000000000004
56 # YAML-NEXT: - Name: default2
57 # YAML-NEXT: Type: STT_OBJECT
58 # YAML-NEXT: Section: .data
59 # YAML-NEXT: Value: 0x0000000000000004
60 # YAML-NEXT: Size: 0x0000000000000004
61 # YAML-NEXT: - Name: internal
62 # YAML-NEXT: Type: STT_OBJECT
63 # YAML-NEXT: Section: .data
64 # YAML-NEXT: Value: 0x0000000000000008
65 # YAML-NEXT: Size: 0x0000000000000004
66 # YAML-NEXT: Visibility: STV_INTERNAL
67 # YAML-NEXT: - Name: hidden
68 # YAML-NEXT: Type: STT_OBJECT
69 # YAML-NEXT: Section: .data
70 # YAML-NEXT: Value: 0x000000000000000C
71 # YAML-NEXT: Size: 0x0000000000000004
72 # YAML-NEXT: Visibility: STV_HIDDEN
73 # YAML-NEXT: - Name: protected
74 # YAML-NEXT: Type: STT_OBJECT
75 # YAML-NEXT: Section: .data
76 # YAML-NEXT: Value: 0x0000000000000010
77 # YAML-NEXT: Size: 0x0000000000000004
78 # YAML-NEXT: Visibility: STV_PROTECTED
79
80 ---
81 FileHeader:
82 Class: ELFCLASS32
83 Data: ELFDATA2LSB
84 Type: ET_REL
85 Machine: EM_MIPS
86 Flags: [ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32 ]
87
88 Sections:
89 - Name: .data
90 Type: SHT_PROGBITS
91 Flags: [ SHF_ALLOC, SHF_WRITE ]
92 AddressAlign: 0x04
93 Size: 0x14
94
95 Symbols:
96 Global:
97 - Name: default1
98 Type: STT_OBJECT
99 Visibility: STV_DEFAULT
100 Section: .data
101 Value: 0x00
102 Size: 0x04
103 - Name: default2
104 Type: STT_OBJECT
105 Section: .data
106 Value: 0x04
107 Size: 0x04
108 - Name: internal
109 Type: STT_OBJECT
110 Visibility: STV_INTERNAL
111 Section: .data
112 Value: 0x08
113 Size: 0x04
114 - Name: hidden
115 Type: STT_OBJECT
116 Visibility: STV_HIDDEN
117 Section: .data
118 Value: 0x0C
119 Size: 0x04
120 - Name: protected
121 Type: STT_OBJECT
122 Visibility: STV_PROTECTED
123 Section: .data
124 Value: 0x10
125 Size: 0x04
131131 S.Type = Sym->getType();
132132 S.Value = Sym->st_value;
133133 S.Size = Sym->st_size;
134 S.Visibility = Sym->st_other & 0x3;
134135
135136 ErrorOr NameOrErr = Obj.getSymbolName(Sym);
136137 if (error_code EC = NameOrErr.getError())
303303 Symbol.st_shndx = Index;
304304 } // else Symbol.st_shndex == SHN_UNDEF (== 0), since it was zero'd earlier.
305305 Symbol.st_value = Sym.Value;
306 Symbol.st_other = Sym.Visibility;
306307 Symbol.st_size = Sym.Size;
307308 Syms.push_back(Symbol);
308309 }