Skip to content

Commit f090e6f

Browse files
committed
[llvm-objdump/llvm-readobj/obj2yaml/yaml2obj] Support DT_PPC_GOT and DT_PPC_OPT
In glibc, DT_PPC_GOT indicates that PowerPC32 Secure PLT ABI is used. I plan to use it in D62464. DT_PPC_OPT currently indicates if a TLSDESC inspired TLS optimization is enabled. Reviewed By: grimar, jhenderson, rupprecht Differential Revision: https://reviews.llvm.org/D62851 llvm-svn: 362569
1 parent fe97754 commit f090e6f

File tree

6 files changed

+137
-23
lines changed

6 files changed

+137
-23
lines changed

llvm/include/llvm/BinaryFormat/DynamicTags.def

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
#define MIPS_DYNAMIC_TAG_DEFINED
2222
#endif
2323

24+
#ifndef PPC_DYNAMIC_TAG
25+
#define PPC_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value)
26+
#define PPC_DYNAMIC_TAG_DEFINED
27+
#endif
28+
2429
#ifndef PPC64_DYNAMIC_TAG
2530
#define PPC64_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value)
2631
#define PPC64_DYNAMIC_TAG_DEFINED
@@ -199,6 +204,10 @@ MIPS_DYNAMIC_TAG(MIPS_RWPLT, 0x70000034) // Points to the base
199204
MIPS_DYNAMIC_TAG(MIPS_RLD_MAP_REL, 0x70000035) // Relative offset of run time loader
200205
// map, used for debugging.
201206

207+
// PPC specific dynamic table entries.
208+
PPC_DYNAMIC_TAG(PPC_GOT, 0x70000000) // Uses Secure PLT ABI.
209+
PPC_DYNAMIC_TAG(PPC_OPT, 0x70000001) // Has TLS optimization.
210+
202211
// PPC64 specific dynamic table entries.
203212
PPC64_DYNAMIC_TAG(PPC64_GLINK, 0x70000000) // Address of 32 bytes before the
204213
// first glink lazy resolver stub.
@@ -225,6 +234,10 @@ DYNAMIC_TAG(FILTER, 0x7FFFFFFF) // Shared object to get values from
225234
#undef HEXAGON_DYNAMIC_TAG
226235
#undef HEXAGON_DYNAMIC_TAG_DEFINED
227236
#endif
237+
#ifdef PPC_DYNAMIC_TAG_DEFINED
238+
#undef PPC_DYNAMIC_TAG
239+
#undef PPC_DYNAMIC_TAG_DEFINED
240+
#endif
228241
#ifdef PPC64_DYNAMIC_TAG_DEFINED
229242
#undef PPC64_DYNAMIC_TAG
230243
#undef PPC64_DYNAMIC_TAG_DEFINED

llvm/lib/ObjectYAML/ELFYAML.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,7 @@ void ScalarEnumerationTraits<ELFYAML::ELF_DYNTAG>::enumeration(
683683
#define AARCH64_DYNAMIC_TAG(name, value)
684684
#define MIPS_DYNAMIC_TAG(name, value)
685685
#define HEXAGON_DYNAMIC_TAG(name, value)
686+
#define PPC_DYNAMIC_TAG(name, value)
686687
#define PPC64_DYNAMIC_TAG(name, value)
687688
// Ignore marker tags such as DT_HIOS (maps to DT_VERNEEDNUM), etc.
688689
#define DYNAMIC_TAG_MARKER(name, value)
@@ -711,6 +712,13 @@ void ScalarEnumerationTraits<ELFYAML::ELF_DYNTAG>::enumeration(
711712
#undef HEXAGON_DYNAMIC_TAG
712713
#define HEXAGON_DYNAMIC_TAG(name, value)
713714
break;
715+
case ELF::EM_PPC:
716+
#undef PPC_DYNAMIC_TAG
717+
#define PPC_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value)
718+
#include "llvm/BinaryFormat/DynamicTags.def"
719+
#undef PPC_DYNAMIC_TAG
720+
#define PPC_DYNAMIC_TAG(name, value)
721+
break;
714722
case ELF::EM_PPC64:
715723
#undef PPC64_DYNAMIC_TAG
716724
#define PPC64_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value)
@@ -725,6 +733,7 @@ void ScalarEnumerationTraits<ELFYAML::ELF_DYNTAG>::enumeration(
725733
#undef AARCH64_DYNAMIC_TAG
726734
#undef MIPS_DYNAMIC_TAG
727735
#undef HEXAGON_DYNAMIC_TAG
736+
#undef PPC_DYNAMIC_TAG
728737
#undef PPC64_DYNAMIC_TAG
729738
#undef DYNAMIC_TAG_MARKER
730739
#undef STRINGIFY

llvm/test/tools/llvm-objdump/elf-dynamic-section-machine-specific.test

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Test that hexagon machine-specific tags can be dumped.
1+
## Test that hexagon machine-specific tags can be dumped.
22
# RUN: yaml2obj --docnum=1 -o %t.hex \
33
# RUN: %S/../llvm-readobj/Inputs/elf-dynamic-tags-machine-specific.yaml
44
# RUN: llvm-objdump -p %t.hex | FileCheck %s --check-prefix=HEXAGON
@@ -11,7 +11,7 @@
1111
# HEXAGON-NEXT: <unknown:>0x1234abcd 0x0000000000000001
1212

1313

14-
# Test that MIPS machine-specific tags can be dumped.
14+
## Test that MIPS machine-specific tags can be dumped.
1515
# RUN: yaml2obj --docnum=2 -o %t.mips \
1616
# RUN: %S/../llvm-readobj/Inputs/elf-dynamic-tags-machine-specific.yaml
1717
# RUN: llvm-objdump -p %t.mips | FileCheck %s --check-prefix=MIPS
@@ -66,12 +66,23 @@
6666
# MIPS-NEXT: <unknown:>0x1234abcd 0x0000000000000001
6767

6868

69-
# Test that PPC64 machine-specific tags can be dumped.
69+
## Test that PPC machine-specific tags can be dumped.
7070
# RUN: yaml2obj --docnum=3 -o %t.ppc \
7171
# RUN: %S/../llvm-readobj/Inputs/elf-dynamic-tags-machine-specific.yaml
7272
# RUN: llvm-objdump -p %t.ppc | FileCheck %s --check-prefix=PPC
7373

7474
# PPC: Dynamic Section:
75-
# PPC-NEXT: HASH 0x0000000000001000
76-
# PPC-NEXT: PPC64_GLINK 0x0000000000001000
77-
# PPC-NEXT: <unknown:>0x1234abcd 0x0000000000000001
75+
# PPC-NEXT: PPC_GOT 0x000200c0
76+
# PPC-NEXT: PPC_OPT 0x00000001
77+
# PPC-NEXT: <unknown:>0x1234abcd 0x00000001
78+
79+
80+
## Test that PPC64 machine-specific tags can be dumped.
81+
# RUN: yaml2obj --docnum=4 -o %t.ppc64 \
82+
# RUN: %S/../llvm-readobj/Inputs/elf-dynamic-tags-machine-specific.yaml
83+
# RUN: llvm-objdump -p %t.ppc64 | FileCheck %s --check-prefix=PPC64
84+
85+
# PPC64: Dynamic Section:
86+
# PPC64-NEXT: HASH 0x0000000000001000
87+
# PPC64-NEXT: PPC64_GLINK 0x0000000000001000
88+
# PPC64-NEXT: <unknown:>0x1234abcd 0x0000000000000001

llvm/test/tools/llvm-readobj/Inputs/elf-dynamic-tags-machine-specific.yaml

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,43 @@ ProgramHeaders:
165165
Sections:
166166
- Section: .dynamic
167167

168-
# Third document: PPC64
168+
# Third document: PPC
169+
--- !ELF
170+
FileHeader:
171+
Class: ELFCLASS32
172+
Data: ELFDATA2MSB
173+
Type: ET_EXEC
174+
Machine: EM_PPC
175+
Sections:
176+
- Name: .dynstr
177+
Type: SHT_STRTAB
178+
Address: 0x200
179+
Size: 0x10
180+
Content: "004400550066007700"
181+
- Name: .dynamic
182+
Type: SHT_DYNAMIC
183+
Address: 0x20000
184+
Entries:
185+
- Tag: DT_PPC_GOT
186+
Value: 0x200c0
187+
- Tag: DT_PPC_OPT
188+
Value: 1
189+
- Tag: 0x1234abcd
190+
Value: 0x1
191+
- Tag: DT_NULL
192+
Value: 0
193+
ProgramHeaders:
194+
- Type: PT_LOAD
195+
VAddr: 0x1000
196+
Sections:
197+
- Section: .dynstr
198+
- Section: .dynamic
199+
- Type: PT_DYNAMIC
200+
VAddr: 0x20000
201+
Sections:
202+
- Section: .dynamic
203+
204+
# Fourth document: PPC64
169205
--- !ELF
170206
FileHeader:
171207
Class: ELFCLASS64

llvm/test/tools/llvm-readobj/elf-dynamic-tags-machine-specific.test

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -132,28 +132,49 @@
132132
# GNU-MIPS-NEXT: 0x0000000000000000 (NULL) 0x0
133133

134134

135-
# Test that PPC64 machine-specific tags can be dumped.
135+
# Test that PPC machine-specific tags can be dumped.
136136
# RUN: yaml2obj --docnum=3 %S/Inputs/elf-dynamic-tags-machine-specific.yaml -o %t.ppc
137137
# RUN: llvm-readobj --dynamic-table %t.ppc | FileCheck %s --check-prefix=LLVM-PPC
138138
# RUN: llvm-readelf --dynamic-table %t.ppc | FileCheck %s --check-prefix=GNU-PPC
139139

140140
# LLVM-PPC: DynamicSection [ (4 entries)
141-
# LLVM-PPC-NEXT: Tag Type Name/Value
142-
# LLVM-PPC-NEXT: 0x0000000000000004 HASH 0x1000
143-
# LLVM-PPC-NEXT: 0x0000000070000000 PPC64_GLINK 0x1000
144-
# LLVM-PPC-NEXT: 0x000000001234ABCD unknown 0x1
145-
# LLVM-PPC-NEXT: 0x0000000000000000 NULL 0x0
141+
# LLVM-PPC-NEXT: Tag Type Name/Value
142+
# LLVM-PPC-NEXT: 0x70000000 PPC_GOT 0x200C0
143+
# LLVM-PPC-NEXT: 0x70000001 PPC_OPT 0x1
144+
# LLVM-PPC-NEXT: 0x1234ABCD unknown 0x1
145+
# LLVM-PPC-NEXT: 0x00000000 NULL 0x0
146146
# LLVM-PPC-NEXT: ]
147147

148148
# GNU-PPC: Dynamic section at offset {{.*}} contains 4 entries:
149-
# GNU-PPC-NEXT: Tag Type Name/Value
150-
# GNU-PPC-NEXT: 0x0000000000000004 (HASH) 0x1000
151-
# GNU-PPC-NEXT: 0x0000000070000000 (PPC64_GLINK) 0x1000
152-
# GNU-PPC-NEXT: 0x000000001234abcd (unknown) 0x1
153-
# GNU-PPC-NEXT: 0x0000000000000000 (NULL) 0x0
149+
# GNU-PPC-NEXT: Tag Type Name/Value
150+
# GNU-PPC-NEXT: 0x70000000 (PPC_GOT) 0x200c0
151+
# GNU-PPC-NEXT: 0x70000001 (PPC_OPT) 0x1
152+
# GNU-PPC-NEXT: 0x1234abcd (unknown) 0x1
153+
# GNU-PPC-NEXT: 0x00000000 (NULL) 0x0
154+
155+
156+
# Test that PPC64 machine-specific tags can be dumped.
157+
# RUN: yaml2obj --docnum=4 %S/Inputs/elf-dynamic-tags-machine-specific.yaml -o %t.ppc64
158+
# RUN: llvm-readobj --dynamic-table %t.ppc64 | FileCheck %s --check-prefix=LLVM-PPC64
159+
# RUN: llvm-readelf --dynamic-table %t.ppc64 | FileCheck %s --check-prefix=GNU-PPC64
160+
161+
# LLVM-PPC64: DynamicSection [ (4 entries)
162+
# LLVM-PPC64-NEXT: Tag Type Name/Value
163+
# LLVM-PPC64-NEXT: 0x0000000000000004 HASH 0x1000
164+
# LLVM-PPC64-NEXT: 0x0000000070000000 PPC64_GLINK 0x1000
165+
# LLVM-PPC64-NEXT: 0x000000001234ABCD unknown 0x1
166+
# LLVM-PPC64-NEXT: 0x0000000000000000 NULL 0x0
167+
# LLVM-PPC64-NEXT: ]
168+
169+
# GNU-PPC64: Dynamic section at offset {{.*}} contains 4 entries:
170+
# GNU-PPC64-NEXT: Tag Type Name/Value
171+
# GNU-PPC64-NEXT: 0x0000000000000004 (HASH) 0x1000
172+
# GNU-PPC64-NEXT: 0x0000000070000000 (PPC64_GLINK) 0x1000
173+
# GNU-PPC64-NEXT: 0x000000001234abcd (unknown) 0x1
174+
# GNU-PPC64-NEXT: 0x0000000000000000 (NULL) 0x0
154175

155176
# Test that AARCH64 machine-specific tags can be dumped.
156-
# RUN: yaml2obj --docnum=4 %S/Inputs/elf-dynamic-tags-machine-specific.yaml -o %t.aarch64
177+
# RUN: yaml2obj --docnum=5 %S/Inputs/elf-dynamic-tags-machine-specific.yaml -o %t.aarch64
157178
# RUN: llvm-readobj --dynamic-table %t.aarch64 | FileCheck %s --check-prefix=LLVM-AARCH64
158179
# RUN: llvm-readelf --dynamic-table %t.aarch64 | FileCheck %s --check-prefix=GNU-AARCH64
159180

llvm/test/tools/obj2yaml/dynamic-section-arch-tags.test

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,33 @@ Sections:
229229
- Tag: DT_HEXAGON_PLT
230230
Value: 0x0000000000000003
231231

232-
## Check we can handle PPC64 specific tags.
232+
## Check we can handle PPC specific tags.
233233
# RUN: yaml2obj -docnum=3 %s -o %t3
234-
# RUN: obj2yaml %t3 | FileCheck %s --check-prefix=EM_PPC64
234+
# RUN: obj2yaml %t3 | FileCheck %s --check-prefix=EM_PPC
235+
236+
# EM_PPC: - Tag: DT_PPC_GOT
237+
# EM_PPC-NEXT: Value: 0x0000000000020000
238+
# EM_PPC-NEXT: - Tag: DT_PPC_OPT
239+
# EM_PPC-NEXT: Value: 0x0000000000000001
240+
241+
--- !ELF
242+
FileHeader:
243+
Class: ELFCLASS32
244+
Data: ELFDATA2MSB
245+
Type: ET_REL
246+
Machine: EM_PPC
247+
Sections:
248+
- Name: .dynamic
249+
Type: SHT_DYNAMIC
250+
Entries:
251+
- Tag: DT_PPC_GOT
252+
Value: 0x0000000000020000
253+
- Tag: DT_PPC_OPT
254+
Value: 0x0000000000000001
255+
256+
## Check we can handle PPC64 specific tags.
257+
# RUN: yaml2obj -docnum=4 %s -o %t4
258+
# RUN: obj2yaml %t4 | FileCheck %s --check-prefix=EM_PPC64
235259

236260
# EM_PPC64: - Tag: DT_PPC64_GLINK
237261
# EM_PPC64-NEXT: Value: 0x0000000000000001
@@ -250,7 +274,7 @@ Sections:
250274
Value: 0x0000000000000001
251275

252276
## Check we can handle AARCH64 specific tags.
253-
# RUN: yaml2obj -docnum=4 %s -o %t2
277+
# RUN: yaml2obj -docnum=5 %s -o %t2
254278
# RUN: obj2yaml %t2 | FileCheck %s --check-prefix=AARCH64
255279

256280
# AARCH64: - Tag: DT_AARCH64_BTI_PLT
@@ -278,7 +302,7 @@ Sections:
278302
## Here for EM_PPC64 we are trying to use DT_HEXAGON_SYMSZ
279303
## instead of DT_PPC64_GLINK. They both have value of 0x70000000.
280304

281-
# RUN: not yaml2obj -docnum=5 %s 2>&1 | FileCheck %s --check-prefix=ERR
305+
# RUN: not yaml2obj -docnum=6 %s 2>&1 | FileCheck %s --check-prefix=ERR
282306
# ERR: error: invalid hex64 number
283307
# ERR-NEXT: - Tag: DT_HEXAGON_SYMSZ
284308

0 commit comments

Comments
 (0)