Skip to content

Commit b75bf87

Browse files
author
George Rimar
committed
[yaml2obj][obj2yaml] - Add support for the architecture specific dynamic tags.
This allows tools to parse/dump the architecture specific tags like DT_MIPS_*, DT_PPC64_* and DT_HEXAGON_* Also fixes a bug in DynamicTags.def which was revealed in this patch. Differential revision: https://reviews.llvm.org/D58667 llvm-svn: 354876
1 parent 40ad3d2 commit b75bf87

File tree

3 files changed

+302
-4
lines changed

3 files changed

+302
-4
lines changed

llvm/include/llvm/BinaryFormat/DynamicTags.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ DYNAMIC_TAG(FILTER, 0x7FFFFFFF) // Shared object to get values from
201201

202202
#ifdef DYNAMIC_TAG_MARKER_DEFINED
203203
#undef DYNAMIC_TAG_MARKER
204+
#undef DYNAMIC_TAG_MARKER_DEFINED
204205
#endif
205206
#ifdef MIPS_DYNAMIC_TAG_DEFINED
206207
#undef MIPS_DYNAMIC_TAG

llvm/lib/ObjectYAML/ELFYAML.cpp

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -662,19 +662,44 @@ void ScalarEnumerationTraits<ELFYAML::ELF_REL>::enumeration(
662662

663663
void ScalarEnumerationTraits<ELFYAML::ELF_DYNTAG>::enumeration(
664664
IO &IO, ELFYAML::ELF_DYNTAG &Value) {
665-
assert(IO.getContext() && "The IO context is not initialized");
665+
const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
666+
assert(Object && "The IO context is not initialized");
666667

667-
// TODO: For simplicity we do not handle target specific flags. They are
668-
// still supported and will be shown as a raw numeric values in the output.
668+
// Disable architecture specific tags by default. We might enable them below.
669669
#define MIPS_DYNAMIC_TAG(name, value)
670670
#define HEXAGON_DYNAMIC_TAG(name, value)
671671
#define PPC64_DYNAMIC_TAG(name, value)
672-
// Also ignore marker tags such as DT_HIOS (maps to DT_VERNEEDNUM), etc.
672+
// Ignore marker tags such as DT_HIOS (maps to DT_VERNEEDNUM), etc.
673673
#define DYNAMIC_TAG_MARKER(name, value)
674674

675675
#define STRINGIFY(X) (#X)
676676
#define DYNAMIC_TAG(X, Y) IO.enumCase(Value, STRINGIFY(DT_##X), ELF::DT_##X);
677+
switch (Object->Header.Machine) {
678+
case ELF::EM_MIPS:
679+
#undef MIPS_DYNAMIC_TAG
680+
#define MIPS_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value)
681+
#include "llvm/BinaryFormat/DynamicTags.def"
682+
#undef MIPS_DYNAMIC_TAG
683+
#define MIPS_DYNAMIC_TAG(name, value)
684+
break;
685+
case ELF::EM_HEXAGON:
686+
#undef HEXAGON_DYNAMIC_TAG
687+
#define HEXAGON_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value)
677688
#include "llvm/BinaryFormat/DynamicTags.def"
689+
#undef HEXAGON_DYNAMIC_TAG
690+
#define HEXAGON_DYNAMIC_TAG(name, value)
691+
break;
692+
case ELF::EM_PPC64:
693+
#undef PPC64_DYNAMIC_TAG
694+
#define PPC64_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value)
695+
#include "llvm/BinaryFormat/DynamicTags.def"
696+
#undef PPC64_DYNAMIC_TAG
697+
#define PPC64_DYNAMIC_TAG(name, value)
698+
break;
699+
default:
700+
#include "llvm/BinaryFormat/DynamicTags.def"
701+
break;
702+
}
678703

679704
#undef MIPS_DYNAMIC_TAG
680705
#undef HEXAGON_DYNAMIC_TAG
Lines changed: 272 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,272 @@
1+
## Check we can use obj2yaml to yamalize the object
2+
## containing architecture specific dynamic tags.
3+
4+
## Check we can handle MIPS specific tags.
5+
# RUN: yaml2obj -docnum=1 %s -o %t1
6+
# RUN: obj2yaml %t1 | FileCheck %s --check-prefix=MIPS
7+
8+
# MIPS: - Tag: DT_MIPS_RLD_VERSION
9+
# MIPS-NEXT: Value: 0x0000000000000001
10+
# MIPS-NEXT: - Tag: DT_MIPS_TIME_STAMP
11+
# MIPS-NEXT: Value: 0x0000000000000002
12+
# MIPS-NEXT: - Tag: DT_MIPS_ICHECKSUM
13+
# MIPS-NEXT: Value: 0x0000000000000003
14+
# MIPS-NEXT: - Tag: DT_MIPS_IVERSION
15+
# MIPS-NEXT: Value: 0x0000000000000004
16+
# MIPS-NEXT: - Tag: DT_MIPS_FLAGS
17+
# MIPS-NEXT: Value: 0x0000000000000005
18+
# MIPS-NEXT: - Tag: DT_MIPS_BASE_ADDRESS
19+
# MIPS-NEXT: Value: 0x0000000000000006
20+
# MIPS-NEXT: - Tag: DT_MIPS_MSYM
21+
# MIPS-NEXT: Value: 0x0000000000000007
22+
# MIPS-NEXT: - Tag: DT_MIPS_CONFLICT
23+
# MIPS-NEXT: Value: 0x0000000000000008
24+
# MIPS-NEXT: - Tag: DT_MIPS_LIBLIST
25+
# MIPS-NEXT: Value: 0x0000000000000009
26+
# MIPS-NEXT: - Tag: DT_MIPS_LOCAL_GOTNO
27+
# MIPS-NEXT: Value: 0x000000000000000A
28+
# MIPS-NEXT: - Tag: DT_MIPS_CONFLICTNO
29+
# MIPS-NEXT: Value: 0x000000000000000B
30+
# MIPS-NEXT: - Tag: DT_MIPS_LIBLISTNO
31+
# MIPS-NEXT: Value: 0x000000000000000C
32+
# MIPS-NEXT: - Tag: DT_MIPS_SYMTABNO
33+
# MIPS-NEXT: Value: 0x000000000000000D
34+
# MIPS-NEXT: - Tag: DT_MIPS_UNREFEXTNO
35+
# MIPS-NEXT: Value: 0x000000000000000E
36+
# MIPS-NEXT: - Tag: DT_MIPS_GOTSYM
37+
# MIPS-NEXT: Value: 0x000000000000000F
38+
# MIPS-NEXT: - Tag: DT_MIPS_HIPAGENO
39+
# MIPS-NEXT: Value: 0x0000000000000010
40+
# MIPS-NEXT: - Tag: DT_MIPS_RLD_MAP
41+
# MIPS-NEXT: Value: 0x0000000000000011
42+
# MIPS-NEXT: - Tag: DT_MIPS_DELTA_CLASS
43+
# MIPS-NEXT: Value: 0x0000000000000012
44+
# MIPS-NEXT: - Tag: DT_MIPS_DELTA_CLASS_NO
45+
# MIPS-NEXT: Value: 0x0000000000000013
46+
# MIPS-NEXT: - Tag: DT_MIPS_DELTA_INSTANCE
47+
# MIPS-NEXT: Value: 0x0000000000000014
48+
# MIPS-NEXT: - Tag: DT_MIPS_DELTA_INSTANCE_NO
49+
# MIPS-NEXT: Value: 0x0000000000000015
50+
# MIPS-NEXT: - Tag: DT_MIPS_DELTA_RELOC
51+
# MIPS-NEXT: Value: 0x0000000000000016
52+
# MIPS-NEXT: - Tag: DT_MIPS_DELTA_RELOC_NO
53+
# MIPS-NEXT: Value: 0x0000000000000017
54+
# MIPS-NEXT: - Tag: DT_MIPS_DELTA_SYM
55+
# MIPS-NEXT: Value: 0x0000000000000018
56+
# MIPS-NEXT: - Tag: DT_MIPS_DELTA_SYM_NO
57+
# MIPS-NEXT: Value: 0x0000000000000019
58+
# MIPS-NEXT: - Tag: DT_MIPS_DELTA_CLASSSYM
59+
# MIPS-NEXT: Value: 0x000000000000001A
60+
# MIPS-NEXT: - Tag: DT_MIPS_DELTA_CLASSSYM_NO
61+
# MIPS-NEXT: Value: 0x000000000000001B
62+
# MIPS-NEXT: - Tag: DT_MIPS_CXX_FLAGS
63+
# MIPS-NEXT: Value: 0x000000000000001C
64+
# MIPS-NEXT: - Tag: DT_MIPS_PIXIE_INIT
65+
# MIPS-NEXT: Value: 0x000000000000001D
66+
# MIPS-NEXT: - Tag: DT_MIPS_SYMBOL_LIB
67+
# MIPS-NEXT: Value: 0x000000000000001E
68+
# MIPS-NEXT: - Tag: DT_MIPS_LOCALPAGE_GOTIDX
69+
# MIPS-NEXT: Value: 0x000000000000001F
70+
# MIPS-NEXT: - Tag: DT_MIPS_LOCAL_GOTIDX
71+
# MIPS-NEXT: Value: 0x0000000000000020
72+
# MIPS-NEXT: - Tag: DT_MIPS_HIDDEN_GOTIDX
73+
# MIPS-NEXT: Value: 0x0000000000000021
74+
# MIPS-NEXT: - Tag: DT_MIPS_PROTECTED_GOTIDX
75+
# MIPS-NEXT: Value: 0x0000000000000022
76+
# MIPS-NEXT: - Tag: DT_MIPS_OPTIONS
77+
# MIPS-NEXT: Value: 0x0000000000000023
78+
# MIPS-NEXT: - Tag: DT_MIPS_INTERFACE
79+
# MIPS-NEXT: Value: 0x0000000000000024
80+
# MIPS-NEXT: - Tag: DT_MIPS_DYNSTR_ALIGN
81+
# MIPS-NEXT: Value: 0x0000000000000025
82+
# MIPS-NEXT: - Tag: DT_MIPS_INTERFACE_SIZE
83+
# MIPS-NEXT: Value: 0x0000000000000026
84+
# MIPS-NEXT: - Tag: DT_MIPS_RLD_TEXT_RESOLVE_ADDR
85+
# MIPS-NEXT: Value: 0x0000000000000027
86+
# MIPS-NEXT: - Tag: DT_MIPS_PERF_SUFFIX
87+
# MIPS-NEXT: Value: 0x0000000000000028
88+
# MIPS-NEXT: - Tag: DT_MIPS_COMPACT_SIZE
89+
# MIPS-NEXT: Value: 0x0000000000000029
90+
# MIPS-NEXT: - Tag: DT_MIPS_GP_VALUE
91+
# MIPS-NEXT: Value: 0x000000000000002A
92+
# MIPS-NEXT: - Tag: DT_MIPS_AUX_DYNAMIC
93+
# MIPS-NEXT: Value: 0x000000000000002B
94+
# MIPS-NEXT: - Tag: DT_MIPS_PLTGOT
95+
# MIPS-NEXT: Value: 0x000000000000002C
96+
# MIPS-NEXT: - Tag: DT_MIPS_RWPLT
97+
# MIPS-NEXT: Value: 0x000000000000002D
98+
# MIPS-NEXT: - Tag: DT_MIPS_RLD_MAP_REL
99+
# MIPS-NEXT: Value: 0x000000000000002E
100+
101+
--- !ELF
102+
FileHeader:
103+
Class: ELFCLASS32
104+
Data: ELFDATA2LSB
105+
Type: ET_REL
106+
Machine: EM_MIPS
107+
Sections:
108+
- Name: .dynamic
109+
Type: SHT_DYNAMIC
110+
Entries:
111+
- Tag: DT_MIPS_RLD_VERSION
112+
Value: 0x0000000000000001
113+
- Tag: DT_MIPS_TIME_STAMP
114+
Value: 0x0000000000000002
115+
- Tag: DT_MIPS_ICHECKSUM
116+
Value: 0x0000000000000003
117+
- Tag: DT_MIPS_IVERSION
118+
Value: 0x0000000000000004
119+
- Tag: DT_MIPS_FLAGS
120+
Value: 0x0000000000000005
121+
- Tag: DT_MIPS_BASE_ADDRESS
122+
Value: 0x0000000000000006
123+
- Tag: DT_MIPS_MSYM
124+
Value: 0x0000000000000007
125+
- Tag: DT_MIPS_CONFLICT
126+
Value: 0x0000000000000008
127+
- Tag: DT_MIPS_LIBLIST
128+
Value: 0x0000000000000009
129+
- Tag: DT_MIPS_LOCAL_GOTNO
130+
Value: 0x000000000000000A
131+
- Tag: DT_MIPS_CONFLICTNO
132+
Value: 0x000000000000000B
133+
- Tag: DT_MIPS_LIBLISTNO
134+
Value: 0x000000000000000C
135+
- Tag: DT_MIPS_SYMTABNO
136+
Value: 0x000000000000000D
137+
- Tag: DT_MIPS_UNREFEXTNO
138+
Value: 0x000000000000000E
139+
- Tag: DT_MIPS_GOTSYM
140+
Value: 0x000000000000000F
141+
- Tag: DT_MIPS_HIPAGENO
142+
Value: 0x0000000000000010
143+
- Tag: DT_MIPS_RLD_MAP
144+
Value: 0x0000000000000011
145+
- Tag: DT_MIPS_DELTA_CLASS
146+
Value: 0x0000000000000012
147+
- Tag: DT_MIPS_DELTA_CLASS_NO
148+
Value: 0x0000000000000013
149+
- Tag: DT_MIPS_DELTA_INSTANCE
150+
Value: 0x0000000000000014
151+
- Tag: DT_MIPS_DELTA_INSTANCE_NO
152+
Value: 0x0000000000000015
153+
- Tag: DT_MIPS_DELTA_RELOC
154+
Value: 0x0000000000000016
155+
- Tag: DT_MIPS_DELTA_RELOC_NO
156+
Value: 0x0000000000000017
157+
- Tag: DT_MIPS_DELTA_SYM
158+
Value: 0x0000000000000018
159+
- Tag: DT_MIPS_DELTA_SYM_NO
160+
Value: 0x0000000000000019
161+
- Tag: DT_MIPS_DELTA_CLASSSYM
162+
Value: 0x000000000000001A
163+
- Tag: DT_MIPS_DELTA_CLASSSYM_NO
164+
Value: 0x000000000000001B
165+
- Tag: DT_MIPS_CXX_FLAGS
166+
Value: 0x000000000000001C
167+
- Tag: DT_MIPS_PIXIE_INIT
168+
Value: 0x000000000000001D
169+
- Tag: DT_MIPS_SYMBOL_LIB
170+
Value: 0x000000000000001E
171+
- Tag: DT_MIPS_LOCALPAGE_GOTIDX
172+
Value: 0x000000000000001F
173+
- Tag: DT_MIPS_LOCAL_GOTIDX
174+
Value: 0x0000000000000020
175+
- Tag: DT_MIPS_HIDDEN_GOTIDX
176+
Value: 0x0000000000000021
177+
- Tag: DT_MIPS_PROTECTED_GOTIDX
178+
Value: 0x0000000000000022
179+
- Tag: DT_MIPS_OPTIONS
180+
Value: 0x0000000000000023
181+
- Tag: DT_MIPS_INTERFACE
182+
Value: 0x0000000000000024
183+
- Tag: DT_MIPS_DYNSTR_ALIGN
184+
Value: 0x0000000000000025
185+
- Tag: DT_MIPS_INTERFACE_SIZE
186+
Value: 0x0000000000000026
187+
- Tag: DT_MIPS_RLD_TEXT_RESOLVE_ADDR
188+
Value: 0x0000000000000027
189+
- Tag: DT_MIPS_PERF_SUFFIX
190+
Value: 0x0000000000000028
191+
- Tag: DT_MIPS_COMPACT_SIZE
192+
Value: 0x0000000000000029
193+
- Tag: DT_MIPS_GP_VALUE
194+
Value: 0x000000000000002A
195+
- Tag: DT_MIPS_AUX_DYNAMIC
196+
Value: 0x000000000000002B
197+
- Tag: DT_MIPS_PLTGOT
198+
Value: 0x000000000000002C
199+
- Tag: DT_MIPS_RWPLT
200+
Value: 0x000000000000002D
201+
- Tag: DT_MIPS_RLD_MAP_REL
202+
Value: 0x000000000000002E
203+
204+
## Check we can handle Hexagon specific tags.
205+
# RUN: yaml2obj -docnum=2 %s -o %t2
206+
# RUN: obj2yaml %t2 | FileCheck %s --check-prefix=HEXAGON
207+
208+
# HEXAGON: - Tag: DT_HEXAGON_SYMSZ
209+
# HEXAGON-NEXT: Value: 0x0000000000000001
210+
# HEXAGON-NEXT: - Tag: DT_HEXAGON_VER
211+
# HEXAGON-NEXT: Value: 0x0000000000000002
212+
# HEXAGON-NEXT: - Tag: DT_HEXAGON_PLT
213+
# HEXAGON-NEXT: Value: 0x0000000000000003
214+
215+
--- !ELF
216+
FileHeader:
217+
Class: ELFCLASS64
218+
Data: ELFDATA2LSB
219+
Type: ET_REL
220+
Machine: EM_HEXAGON
221+
Sections:
222+
- Name: .dynamic
223+
Type: SHT_DYNAMIC
224+
Entries:
225+
- Tag: DT_HEXAGON_SYMSZ
226+
Value: 0x0000000000000001
227+
- Tag: DT_HEXAGON_VER
228+
Value: 0x0000000000000002
229+
- Tag: DT_HEXAGON_PLT
230+
Value: 0x0000000000000003
231+
232+
## Check we can handle PPC64 specific tags.
233+
# RUN: yaml2obj -docnum=3 %s -o %t3
234+
# RUN: obj2yaml %t3 | FileCheck %s --check-prefix=EM_PPC64
235+
236+
# EM_PPC64: - Tag: DT_PPC64_GLINK
237+
# EM_PPC64-NEXT: Value: 0x0000000000000001
238+
239+
--- !ELF
240+
FileHeader:
241+
Class: ELFCLASS64
242+
Data: ELFDATA2LSB
243+
Type: ET_REL
244+
Machine: EM_PPC64
245+
Sections:
246+
- Name: .dynamic
247+
Type: SHT_DYNAMIC
248+
Entries:
249+
- Tag: DT_PPC64_GLINK
250+
Value: 0x0000000000000001
251+
252+
## Check we can't use a tag from a different architecture,
253+
## even if it has the same numeric value as a valid tag.
254+
## Here for EM_PPC64 we are trying to use DT_HEXAGON_SYMSZ
255+
## instead of DT_PPC64_GLINK. They both have value of 0x70000000.
256+
257+
# RUN: not yaml2obj -docnum=4 %s 2>&1 | FileCheck %s --check-prefix=ERR
258+
# ERR: error: invalid hex64 number
259+
# ERR-NEXT: - Tag: DT_HEXAGON_SYMSZ
260+
261+
--- !ELF
262+
FileHeader:
263+
Class: ELFCLASS64
264+
Data: ELFDATA2LSB
265+
Type: ET_REL
266+
Machine: EM_PPC64
267+
Sections:
268+
- Name: .dynamic
269+
Type: SHT_DYNAMIC
270+
Entries:
271+
- Tag: DT_HEXAGON_SYMSZ
272+
Value: 0x0000000000000001

0 commit comments

Comments
 (0)