Skip to content

Commit

Permalink
[llvm-readobj] Match GNU output for DT_RPATH and DT_RUNPATH when dump…
Browse files Browse the repository at this point in the history
…ing 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
  • Loading branch information
Yuanfang Chen committed Jun 19, 2019
1 parent caf9655 commit 40a156b
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 37 deletions.
4 changes: 2 additions & 2 deletions lld/test/ELF/new-dtags.test
Expand Up @@ -10,11 +10,11 @@
// RUN: llvm-readobj --dynamic-table %t2 | FileCheck --check-prefix=ENABLE %s

// DISABLE: DynamicSection [
// DISABLE: 0x000000000000000F RPATH /somepath
// DISABLE: 0x000000000000000F RPATH Library rpath: [/somepath]
// DISABLE-NOT: RUNPATH
// DISABLE: ]

// ENABLE: DynamicSection [
// ENABLE: 0x000000000000001D RUNPATH /somepath
// ENABLE: 0x000000000000001D RUNPATH Library runpath: [/somepath]
// ENABLE-NOT: RPATH
// ENABLE: ]
2 changes: 1 addition & 1 deletion lld/test/ELF/shared-ppc64.s
Expand Up @@ -27,7 +27,7 @@

// CHECK: DynamicSection [
// CHECK-NEXT: Tag Type Name/Value
// CHECK-NEXT: 0x000000000000001D RUNPATH foo:bar
// CHECK-NEXT: 0x000000000000001D RUNPATH Library runpath: [foo:bar]
// CHECK-NEXT: 0x0000000000000001 NEEDED Shared library: [{{.*}}2.so]
// CHECK-NEXT: 0x0000000000000015 DEBUG 0x0
// CHECK-NEXT: 0x0000000000000007 RELA [[RELADDR]]
Expand Down
2 changes: 1 addition & 1 deletion lld/test/ELF/shared.s
Expand Up @@ -250,7 +250,7 @@

// CHECK: DynamicSection [
// CHECK-NEXT: Tag Type Name/Value
// CHECK-NEXT: 0x0000001D RUNPATH foo:bar
// CHECK-NEXT: 0x0000001D RUNPATH Library runpath: [foo:bar]
// CHECK-NEXT: 0x00000001 NEEDED Shared library: [{{.*}}2.so]
// CHECK-NEXT: 0x00000015 DEBUG 0x0
// CHECK-NEXT: 0x00000011 REL [[RELADDR]]
Expand Down
8 changes: 4 additions & 4 deletions llvm/test/tools/llvm-readobj/elf-dynamic-malformed.test
Expand Up @@ -79,17 +79,17 @@ ProgramHeaders:
# BAD-STRING-LLVM: 0x000000007FFFFFFD AUXILIARY Auxiliary library: <Invalid offset 0x1>
# BAD-STRING-LLVM: 0x000000007FFFFFFE USED Not needed object: <Invalid offset 0x1>
# BAD-STRING-LLVM: 0x000000000000000E SONAME Library soname: <Invalid offset 0x1>
# BAD-STRING-LLVM: 0x000000000000000F RPATH <Invalid offset 0x1>
# BAD-STRING-LLVM: 0x000000000000001D RUNPATH <Invalid offset 0x1>
# BAD-STRING-LLVM: 0x000000000000000F RPATH Library rpath: <Invalid offset 0x1>
# BAD-STRING-LLVM: 0x000000000000001D RUNPATH Library runpath: <Invalid offset 0x1>

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

--- !ELF
FileHeader:
Expand Down
8 changes: 4 additions & 4 deletions llvm/test/tools/llvm-readobj/elf-dynamic-tags.test
Expand Up @@ -19,7 +19,7 @@
# LLVM-NEXT: 0x000000000000000C INIT 0x1000
# LLVM-NEXT: 0x000000000000000D FINI 0x1000
# LLVM-NEXT: 0x000000000000000E SONAME Library soname: [U]
# LLVM-NEXT: 0x000000000000000F RPATH f
# LLVM-NEXT: 0x000000000000000F RPATH Library rpath: [f]
# LLVM-NEXT: 0x0000000000000010 SYMBOLIC 0x1234567890ABCDEF
# LLVM-NEXT: 0x0000000000000011 REL 0x1000
# LLVM-NEXT: 0x0000000000000012 RELSZ 16 (bytes)
Expand All @@ -33,7 +33,7 @@
# LLVM-NEXT: 0x000000000000001A FINI_ARRAY 0x1000
# LLVM-NEXT: 0x000000000000001B INIT_ARRAYSZ 16 (bytes)
# LLVM-NEXT: 0x000000000000001C FINI_ARRAYSZ 16 (bytes)
# LLVM-NEXT: 0x000000000000001D RUNPATH w
# LLVM-NEXT: 0x000000000000001D RUNPATH Library runpath: [w]
# LLVM-NEXT: 0x000000000000001E FLAGS ORIGIN SYMBOLIC TEXTREL BIND_NOW STATIC_TLS {{$}}
# LLVM-NEXT: 0x0000000000000020 PREINIT_ARRAY 0x1000
# LLVM-NEXT: 0x0000000000000021 PREINIT_ARRAYSZ 16 (bytes)
Expand Down Expand Up @@ -84,7 +84,7 @@
# GNU-NEXT: 0x000000000000000c (INIT) 0x1000
# GNU-NEXT: 0x000000000000000d (FINI) 0x1000
# GNU-NEXT: 0x000000000000000e (SONAME) Library soname: [U]
# GNU-NEXT: 0x000000000000000f (RPATH) f
# GNU-NEXT: 0x000000000000000f (RPATH) Library rpath: [f]
# GNU-NEXT: 0x0000000000000010 (SYMBOLIC) 0x1234567890abcdef
# GNU-NEXT: 0x0000000000000011 (REL) 0x1000
# GNU-NEXT: 0x0000000000000012 (RELSZ) 16 (bytes)
Expand All @@ -98,7 +98,7 @@
# GNU-NEXT: 0x000000000000001a (FINI_ARRAY) 0x1000
# GNU-NEXT: 0x000000000000001b (INIT_ARRAYSZ) 16 (bytes)
# GNU-NEXT: 0x000000000000001c (FINI_ARRAYSZ) 16 (bytes)
# GNU-NEXT: 0x000000000000001d (RUNPATH) w
# GNU-NEXT: 0x000000000000001d (RUNPATH) Library runpath: [w]
# GNU-NEXT: 0x000000000000001e (FLAGS) ORIGIN SYMBOLIC TEXTREL BIND_NOW STATIC_TLS {{$}}
# GNU-NEXT: 0x0000000000000020 (PREINIT_ARRAY) 0x1000
# GNU-NEXT: 0x0000000000000021 (PREINIT_ARRAYSZ) 16 (bytes)
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/tools/llvm-readobj/rpath.test
@@ -1,4 +1,4 @@
RUN: llvm-readobj --dynamic-table %p/Inputs/rpath.exe.elf-x86_64 \
RUN: | FileCheck %s

CHECK: 0x000000000000000F RPATH /usr/local/lib
CHECK: 0x000000000000000F RPATH Library rpath: [/usr/local/lib]
35 changes: 11 additions & 24 deletions llvm/tools/llvm-readobj/ELFDumper.cpp
Expand Up @@ -206,8 +206,6 @@ template <typename ELFT> class ELFDumper : public ObjDumper {
void loadDynamicTable(const ELFFile<ELFT> *Obj);
void parseDynamicTable();

void printDynamicString(uint64_t Offset, raw_ostream &OS,
bool WithBracket = true) const;
StringRef getSymbolVersion(StringRef StrTab, const Elf_Sym *symb,
bool &IsDefault) const;
void LoadVersionMap() const;
Expand Down Expand Up @@ -1790,22 +1788,6 @@ void printFlags(T Value, ArrayRef<EnumEntry<TFlag>> Flags, raw_ostream &OS) {
}
}

template <class ELFT>
void ELFDumper<ELFT>::printDynamicString(uint64_t Value,
raw_ostream &OS,
bool WithBracket) const {
if (DynamicStringTable.empty())
OS << "<String table is empty or was not found> ";
else if (Value < DynamicStringTable.size()) {
if (WithBracket)
OS << "[";
OS << StringRef(DynamicStringTable.data() + Value);
if (WithBracket)
OS << "]";
} else
OS << "<Invalid offset 0x" << utohexstr(Value) << ">";
}

template <class ELFT>
void ELFDumper<ELFT>::printDynamicEntry(raw_ostream &OS, uint64_t Type,
uint64_t Value) const {
Expand Down Expand Up @@ -1952,22 +1934,27 @@ void ELFDumper<ELFT>::printDynamicEntry(raw_ostream &OS, uint64_t Type,
case DT_SONAME:
case DT_AUXILIARY:
case DT_USED:
case DT_FILTER: {
case DT_FILTER:
case DT_RPATH:
case DT_RUNPATH: {
const std::map<uint64_t, const char*> TagNames = {
{DT_NEEDED, "Shared library"},
{DT_SONAME, "Library soname"},
{DT_AUXILIARY, "Auxiliary library"},
{DT_USED, "Not needed object"},
{DT_FILTER, "Filter library"},
{DT_RPATH, "Library rpath"},
{DT_RUNPATH, "Library runpath"},
};
OS << TagNames.at(Type) << ": ";
printDynamicString(Value, OS);
if (DynamicStringTable.empty())
OS << "<String table is empty or was not found> ";
else if (Value < DynamicStringTable.size())
OS << "[" << StringRef(DynamicStringTable.data() + Value) << "]";
else
OS << "<Invalid offset 0x" << utohexstr(Value) << ">";
break;
}
case DT_RPATH:
case DT_RUNPATH:
printDynamicString(Value, OS, false);
break;
case DT_FLAGS:
printFlags(Value, makeArrayRef(ElfDynamicDTFlags), OS);
break;
Expand Down

0 comments on commit 40a156b

Please sign in to comment.