Skip to content

Commit 40a156b

Browse files
author
Yuanfang Chen
committedJun 19, 2019
[llvm-readobj] Match GNU output for DT_RPATH and DT_RUNPATH when dumping dynamic symbol table.
Reviewers: jhenderson, grimar, MaskRay, rupprecht, espindola Subscribers: emaste, nemanjai, arichardson, kbarton, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D63347 llvm-svn: 363868
1 parent caf9655 commit 40a156b

File tree

7 files changed

+24
-37
lines changed

7 files changed

+24
-37
lines changed
 

Diff for: ‎lld/test/ELF/new-dtags.test

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
// RUN: llvm-readobj --dynamic-table %t2 | FileCheck --check-prefix=ENABLE %s
1111

1212
// DISABLE: DynamicSection [
13-
// DISABLE: 0x000000000000000F RPATH /somepath
13+
// DISABLE: 0x000000000000000F RPATH Library rpath: [/somepath]
1414
// DISABLE-NOT: RUNPATH
1515
// DISABLE: ]
1616

1717
// ENABLE: DynamicSection [
18-
// ENABLE: 0x000000000000001D RUNPATH /somepath
18+
// ENABLE: 0x000000000000001D RUNPATH Library runpath: [/somepath]
1919
// ENABLE-NOT: RPATH
2020
// ENABLE: ]

Diff for: ‎lld/test/ELF/shared-ppc64.s

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
// CHECK: DynamicSection [
2929
// CHECK-NEXT: Tag Type Name/Value
30-
// CHECK-NEXT: 0x000000000000001D RUNPATH foo:bar
30+
// CHECK-NEXT: 0x000000000000001D RUNPATH Library runpath: [foo:bar]
3131
// CHECK-NEXT: 0x0000000000000001 NEEDED Shared library: [{{.*}}2.so]
3232
// CHECK-NEXT: 0x0000000000000015 DEBUG 0x0
3333
// CHECK-NEXT: 0x0000000000000007 RELA [[RELADDR]]

Diff for: ‎lld/test/ELF/shared.s

+1-1
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@
250250

251251
// CHECK: DynamicSection [
252252
// CHECK-NEXT: Tag Type Name/Value
253-
// CHECK-NEXT: 0x0000001D RUNPATH foo:bar
253+
// CHECK-NEXT: 0x0000001D RUNPATH Library runpath: [foo:bar]
254254
// CHECK-NEXT: 0x00000001 NEEDED Shared library: [{{.*}}2.so]
255255
// CHECK-NEXT: 0x00000015 DEBUG 0x0
256256
// CHECK-NEXT: 0x00000011 REL [[RELADDR]]

Diff for: ‎llvm/test/tools/llvm-readobj/elf-dynamic-malformed.test

+4-4
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,17 @@ ProgramHeaders:
7979
# BAD-STRING-LLVM: 0x000000007FFFFFFD AUXILIARY Auxiliary library: <Invalid offset 0x1>
8080
# BAD-STRING-LLVM: 0x000000007FFFFFFE USED Not needed object: <Invalid offset 0x1>
8181
# BAD-STRING-LLVM: 0x000000000000000E SONAME Library soname: <Invalid offset 0x1>
82-
# BAD-STRING-LLVM: 0x000000000000000F RPATH <Invalid offset 0x1>
83-
# BAD-STRING-LLVM: 0x000000000000001D RUNPATH <Invalid offset 0x1>
82+
# BAD-STRING-LLVM: 0x000000000000000F RPATH Library rpath: <Invalid offset 0x1>
83+
# BAD-STRING-LLVM: 0x000000000000001D RUNPATH Library runpath: <Invalid offset 0x1>
8484

8585
# BAD-STRING-GNU: 0x000000000000000a (STRSZ) 1 (bytes)
8686
# BAD-STRING-GNU: 0x0000000000000001 (NEEDED) Shared library: <Invalid offset 0x1>
8787
# BAD-STRING-GNU: 0x000000007fffffff (FILTER) Filter library: <Invalid offset 0x1>
8888
# BAD-STRING-GNU: 0x000000007ffffffd (AUXILIARY) Auxiliary library: <Invalid offset 0x1>
8989
# BAD-STRING-GNU: 0x000000007ffffffe (USED) Not needed object: <Invalid offset 0x1>
9090
# BAD-STRING-GNU: 0x000000000000000e (SONAME) Library soname: <Invalid offset 0x1>
91-
# BAD-STRING-GNU: 0x000000000000000f (RPATH) <Invalid offset 0x1>
92-
# BAD-STRING-GNU: 0x000000000000001d (RUNPATH) <Invalid offset 0x1>
91+
# BAD-STRING-GNU: 0x000000000000000f (RPATH) Library rpath: <Invalid offset 0x1>
92+
# BAD-STRING-GNU: 0x000000000000001d (RUNPATH) Library runpath: <Invalid offset 0x1>
9393

9494
--- !ELF
9595
FileHeader:

Diff for: ‎llvm/test/tools/llvm-readobj/elf-dynamic-tags.test

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
# LLVM-NEXT: 0x000000000000000C INIT 0x1000
2020
# LLVM-NEXT: 0x000000000000000D FINI 0x1000
2121
# LLVM-NEXT: 0x000000000000000E SONAME Library soname: [U]
22-
# LLVM-NEXT: 0x000000000000000F RPATH f
22+
# LLVM-NEXT: 0x000000000000000F RPATH Library rpath: [f]
2323
# LLVM-NEXT: 0x0000000000000010 SYMBOLIC 0x1234567890ABCDEF
2424
# LLVM-NEXT: 0x0000000000000011 REL 0x1000
2525
# LLVM-NEXT: 0x0000000000000012 RELSZ 16 (bytes)
@@ -33,7 +33,7 @@
3333
# LLVM-NEXT: 0x000000000000001A FINI_ARRAY 0x1000
3434
# LLVM-NEXT: 0x000000000000001B INIT_ARRAYSZ 16 (bytes)
3535
# LLVM-NEXT: 0x000000000000001C FINI_ARRAYSZ 16 (bytes)
36-
# LLVM-NEXT: 0x000000000000001D RUNPATH w
36+
# LLVM-NEXT: 0x000000000000001D RUNPATH Library runpath: [w]
3737
# LLVM-NEXT: 0x000000000000001E FLAGS ORIGIN SYMBOLIC TEXTREL BIND_NOW STATIC_TLS {{$}}
3838
# LLVM-NEXT: 0x0000000000000020 PREINIT_ARRAY 0x1000
3939
# LLVM-NEXT: 0x0000000000000021 PREINIT_ARRAYSZ 16 (bytes)
@@ -84,7 +84,7 @@
8484
# GNU-NEXT: 0x000000000000000c (INIT) 0x1000
8585
# GNU-NEXT: 0x000000000000000d (FINI) 0x1000
8686
# GNU-NEXT: 0x000000000000000e (SONAME) Library soname: [U]
87-
# GNU-NEXT: 0x000000000000000f (RPATH) f
87+
# GNU-NEXT: 0x000000000000000f (RPATH) Library rpath: [f]
8888
# GNU-NEXT: 0x0000000000000010 (SYMBOLIC) 0x1234567890abcdef
8989
# GNU-NEXT: 0x0000000000000011 (REL) 0x1000
9090
# GNU-NEXT: 0x0000000000000012 (RELSZ) 16 (bytes)
@@ -98,7 +98,7 @@
9898
# GNU-NEXT: 0x000000000000001a (FINI_ARRAY) 0x1000
9999
# GNU-NEXT: 0x000000000000001b (INIT_ARRAYSZ) 16 (bytes)
100100
# GNU-NEXT: 0x000000000000001c (FINI_ARRAYSZ) 16 (bytes)
101-
# GNU-NEXT: 0x000000000000001d (RUNPATH) w
101+
# GNU-NEXT: 0x000000000000001d (RUNPATH) Library runpath: [w]
102102
# GNU-NEXT: 0x000000000000001e (FLAGS) ORIGIN SYMBOLIC TEXTREL BIND_NOW STATIC_TLS {{$}}
103103
# GNU-NEXT: 0x0000000000000020 (PREINIT_ARRAY) 0x1000
104104
# GNU-NEXT: 0x0000000000000021 (PREINIT_ARRAYSZ) 16 (bytes)

Diff for: ‎llvm/test/tools/llvm-readobj/rpath.test

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
RUN: llvm-readobj --dynamic-table %p/Inputs/rpath.exe.elf-x86_64 \
22
RUN: | FileCheck %s
33

4-
CHECK: 0x000000000000000F RPATH /usr/local/lib
4+
CHECK: 0x000000000000000F RPATH Library rpath: [/usr/local/lib]

Diff for: ‎llvm/tools/llvm-readobj/ELFDumper.cpp

+11-24
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,6 @@ template <typename ELFT> class ELFDumper : public ObjDumper {
206206
void loadDynamicTable(const ELFFile<ELFT> *Obj);
207207
void parseDynamicTable();
208208

209-
void printDynamicString(uint64_t Offset, raw_ostream &OS,
210-
bool WithBracket = true) const;
211209
StringRef getSymbolVersion(StringRef StrTab, const Elf_Sym *symb,
212210
bool &IsDefault) const;
213211
void LoadVersionMap() const;
@@ -1790,22 +1788,6 @@ void printFlags(T Value, ArrayRef<EnumEntry<TFlag>> Flags, raw_ostream &OS) {
17901788
}
17911789
}
17921790

1793-
template <class ELFT>
1794-
void ELFDumper<ELFT>::printDynamicString(uint64_t Value,
1795-
raw_ostream &OS,
1796-
bool WithBracket) const {
1797-
if (DynamicStringTable.empty())
1798-
OS << "<String table is empty or was not found> ";
1799-
else if (Value < DynamicStringTable.size()) {
1800-
if (WithBracket)
1801-
OS << "[";
1802-
OS << StringRef(DynamicStringTable.data() + Value);
1803-
if (WithBracket)
1804-
OS << "]";
1805-
} else
1806-
OS << "<Invalid offset 0x" << utohexstr(Value) << ">";
1807-
}
1808-
18091791
template <class ELFT>
18101792
void ELFDumper<ELFT>::printDynamicEntry(raw_ostream &OS, uint64_t Type,
18111793
uint64_t Value) const {
@@ -1952,22 +1934,27 @@ void ELFDumper<ELFT>::printDynamicEntry(raw_ostream &OS, uint64_t Type,
19521934
case DT_SONAME:
19531935
case DT_AUXILIARY:
19541936
case DT_USED:
1955-
case DT_FILTER: {
1937+
case DT_FILTER:
1938+
case DT_RPATH:
1939+
case DT_RUNPATH: {
19561940
const std::map<uint64_t, const char*> TagNames = {
19571941
{DT_NEEDED, "Shared library"},
19581942
{DT_SONAME, "Library soname"},
19591943
{DT_AUXILIARY, "Auxiliary library"},
19601944
{DT_USED, "Not needed object"},
19611945
{DT_FILTER, "Filter library"},
1946+
{DT_RPATH, "Library rpath"},
1947+
{DT_RUNPATH, "Library runpath"},
19621948
};
19631949
OS << TagNames.at(Type) << ": ";
1964-
printDynamicString(Value, OS);
1950+
if (DynamicStringTable.empty())
1951+
OS << "<String table is empty or was not found> ";
1952+
else if (Value < DynamicStringTable.size())
1953+
OS << "[" << StringRef(DynamicStringTable.data() + Value) << "]";
1954+
else
1955+
OS << "<Invalid offset 0x" << utohexstr(Value) << ">";
19651956
break;
19661957
}
1967-
case DT_RPATH:
1968-
case DT_RUNPATH:
1969-
printDynamicString(Value, OS, false);
1970-
break;
19711958
case DT_FLAGS:
19721959
printFlags(Value, makeArrayRef(ElfDynamicDTFlags), OS);
19731960
break;

0 commit comments

Comments
 (0)
Please sign in to comment.