[llvm] [llvm-readobj][ELF] Test multivalued rpath entries and alter the output for readobj to emphasize the single valued nature of NEEDED, SONAME, USED etc. (PR #96562)
Fred Grim via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 24 14:43:22 PDT 2024
https://github.com/feg208 created https://github.com/llvm/llvm-project/pull/96562
In the context of #95976 it became clear that the output for readobj implied multi valued entries in several cases in the elf headers that the documentation only allowed for a single value. DT_NEEDED is the example here where the value is an offset into the string table without any sort of separator that could give you multiple entries. This patch alters the LLVM output so that the single valued nature is emphasized. For example the output was:
```
DynamicSection [ (35 entries)
Tag Type Name/Value
0x000000000000001D RUNPATH Library runpath: [$ORIGIN/../lib:]
0x0000000000000001 NEEDED Shared library: [libm.so.6]
0x0000000000000001 NEEDED Shared library: [libz.so.1]
0x0000000000000001 NEEDED Shared library: [libzstd.so.1]
```
and is now
```
Tag Type Name/Value
0x000000000000001D RUNPATH Library runpath: [$ORIGIN/../lib:]
0x0000000000000001 NEEDED Shared library: libm.so.6
0x0000000000000001 NEEDED Shared library: libz.so.1
0x0000000000000001 NEEDED Shared library: libzstd.so.1
```
This pr also tests that multi-valued rpaths are handled correctly in the JSON case (i.e. they become proper lists) like:
```
{
"Tag": 15,
"Type": "RPATH",
"Value": 9,
"Path": [
"x",
"w",
"U"
]
},
```
when separated by :
>From 67b651c6a018edf1f4fcd59bd837d50d5b00c5c2 Mon Sep 17 00:00:00 2001
From: Fred Grim <fgrim at apple.com>
Date: Mon, 24 Jun 2024 14:32:46 -0700
Subject: [PATCH] [llvm-readobj][ELF] Test multivalued rpath entries and alter
the output for readobj to emphasize the single valued nature of NEEDED,
SONAME, USED etc.
In the context of #95976 it became clear that the output for readobj
implied multi valued entries in several cases in the elf headers that
the documentation only allowed for a single value. DT_NEEDED is the
example here where the value is an offset into the string table without
any sort of separator that could give you multiple entries. This patch
alters the LLVM output so that the single valued nature is emphasized.
For example the output was:
```
DynamicSection [ (35 entries)
Tag Type Name/Value
0x000000000000001D RUNPATH Library runpath: [$ORIGIN/../lib:]
0x0000000000000001 NEEDED Shared library: [libm.so.6]
0x0000000000000001 NEEDED Shared library: [libz.so.1]
0x0000000000000001 NEEDED Shared library: [libzstd.so.1]
```
and is now
```
Tag Type Name/Value
0x000000000000001D RUNPATH Library runpath: [$ORIGIN/../lib:]
0x0000000000000001 NEEDED Shared library: libm.so.6
0x0000000000000001 NEEDED Shared library: libz.so.1
0x0000000000000001 NEEDED Shared library: libzstd.so.1
```
This pr also tests that multi-valued rpaths are handled correctly in the
JSON case (i.e. they become proper lists) like:
```
{
"Tag": 15,
"Type": "RPATH",
"Value": 9,
"Path": [
"x",
"w",
"U"
]
},
```
when separated by :
---
.../llvm-readobj/ELF/dynamic-malformed.test | 54 ++++++-------
.../tools/llvm-readobj/ELF/dynamic-tags.test | 78 ++++++++++---------
.../test/tools/llvm-readobj/ELF/loadname.test | 4 +-
llvm/tools/llvm-readobj/ELFDumper.cpp | 17 ++--
4 files changed, 77 insertions(+), 76 deletions(-)
diff --git a/llvm/test/tools/llvm-readobj/ELF/dynamic-malformed.test b/llvm/test/tools/llvm-readobj/ELF/dynamic-malformed.test
index d160ea87208c3..05be15775e9e7 100644
--- a/llvm/test/tools/llvm-readobj/ELF/dynamic-malformed.test
+++ b/llvm/test/tools/llvm-readobj/ELF/dynamic-malformed.test
@@ -100,15 +100,15 @@ ProgramHeaders:
# BAD-STRING-LLVM-NEXT: 0x0000000000000005 STRTAB 0x1000
# BAD-STRING-LLVM-NEXT: 0x000000000000000A STRSZ 1 (bytes)
# BAD-STRING-LLVM-NEXT: warning: '[[FILE]]': string table at offset 0xb0: unable to read the string at 0xb2: it goes past the end of the table (0xb1)
-# BAD-STRING-LLVM-NEXT: 0x0000000000000001 NEEDED Shared library: [<?>]
+# BAD-STRING-LLVM-NEXT: 0x0000000000000001 NEEDED Shared library: <?>
# BAD-STRING-LLVM-NEXT: warning: '[[FILE]]': string table at offset 0xb0: unable to read the string at 0xb3: it goes past the end of the table (0xb1)
-# BAD-STRING-LLVM-NEXT: 0x000000007FFFFFFF FILTER Filter library: [<?>]
+# BAD-STRING-LLVM-NEXT: 0x000000007FFFFFFF FILTER Filter library: <?>
# BAD-STRING-LLVM-NEXT: warning: '[[FILE]]': string table at offset 0xb0: unable to read the string at 0xb4: it goes past the end of the table (0xb1)
-# BAD-STRING-LLVM-NEXT: 0x000000007FFFFFFD AUXILIARY Auxiliary library: [<?>]
+# BAD-STRING-LLVM-NEXT: 0x000000007FFFFFFD AUXILIARY Auxiliary library: <?>
# BAD-STRING-LLVM-NEXT: warning: '[[FILE]]': string table at offset 0xb0: unable to read the string at 0xb5: it goes past the end of the table (0xb1)
-# BAD-STRING-LLVM-NEXT: 0x000000007FFFFFFE USED Not needed object: [<?>]
+# BAD-STRING-LLVM-NEXT: 0x000000007FFFFFFE USED Not needed object: <?>
## Note: there is no "string table at offset 0xb0..." warning here, because it was printed earlier.
-# BAD-STRING-LLVM-NEXT: 0x000000000000000E SONAME Library soname: [<?>]
+# BAD-STRING-LLVM-NEXT: 0x000000000000000E SONAME Library soname: <?>
# BAD-STRING-LLVM-NEXT: warning: '[[FILE]]': string table at offset 0xb0: unable to read the string at 0xb7: it goes past the end of the table (0xb1)
# BAD-STRING-LLVM-NEXT: 0x000000000000000F RPATH Library rpath: [<?>]
# BAD-STRING-LLVM-NEXT: warning: '[[FILE]]': string table at offset 0xb0: unable to read the string at 0xb8: it goes past the end of the table (0xb1)
@@ -121,15 +121,15 @@ ProgramHeaders:
# BAD-STRING-GNU-NEXT: 0x0000000000000005 (STRTAB) 0x1000
# BAD-STRING-GNU-NEXT: 0x000000000000000a (STRSZ) 1 (bytes)
# BAD-STRING-GNU-NEXT: warning: '[[FILE]]': string table at offset 0xb0: unable to read the string at 0xb2: it goes past the end of the table (0xb1)
-# BAD-STRING-GNU-NEXT: 0x0000000000000001 (NEEDED) Shared library: [<?>]
+# BAD-STRING-GNU-NEXT: 0x0000000000000001 (NEEDED) Shared library: <?>
# BAD-STRING-GNU-NEXT: warning: '[[FILE]]': string table at offset 0xb0: unable to read the string at 0xb3: it goes past the end of the table (0xb1)
-# BAD-STRING-GNU-NEXT: 0x000000007fffffff (FILTER) Filter library: [<?>]
+# BAD-STRING-GNU-NEXT: 0x000000007fffffff (FILTER) Filter library: <?>
# BAD-STRING-GNU-NEXT: warning: '[[FILE]]': string table at offset 0xb0: unable to read the string at 0xb4: it goes past the end of the table (0xb1)
-# BAD-STRING-GNU-NEXT: 0x000000007ffffffd (AUXILIARY) Auxiliary library: [<?>]
+# BAD-STRING-GNU-NEXT: 0x000000007ffffffd (AUXILIARY) Auxiliary library: <?>
# BAD-STRING-GNU-NEXT: warning: '[[FILE]]': string table at offset 0xb0: unable to read the string at 0xb5: it goes past the end of the table (0xb1)
-# BAD-STRING-GNU-NEXT: 0x000000007ffffffe (USED) Not needed object: [<?>]
+# BAD-STRING-GNU-NEXT: 0x000000007ffffffe (USED) Not needed object: <?>
# BAD-STRING-GNU-NEXT: warning: '[[FILE]]': string table at offset 0xb0: unable to read the string at 0xb6: it goes past the end of the table (0xb1)
-# BAD-STRING-GNU-NEXT: 0x000000000000000e (SONAME) Library soname: [<?>]
+# BAD-STRING-GNU-NEXT: 0x000000000000000e (SONAME) Library soname: <?>
# BAD-STRING-GNU-NEXT: warning: '[[FILE]]': string table at offset 0xb0: unable to read the string at 0xb7: it goes past the end of the table (0xb1)
# BAD-STRING-GNU-NEXT: 0x000000000000000f (RPATH) Library rpath: [<?>]
# BAD-STRING-GNU-NEXT: warning: '[[FILE]]': string table at offset 0xb0: unable to read the string at 0xb8: it goes past the end of the table (0xb1)
@@ -199,8 +199,8 @@ ProgramHeaders:
# BAD-STRTAB-ERR2: warning: '[[FILE]]': unable to parse DT_STRTAB: virtual address is not in any segment: 0x2000000
# BAD-STRTAB-LLVM: LoadName: <Not found>
# BAD-STRTAB: warning: '[[FILE]]': string table was not found
-# BAD-STRTAB-LLVM-NEXT: 0x0000000000000001 NEEDED Shared library: [<?>]
-# BAD-STRTAB-GNU-NEXT: 0x0000000000000001 (NEEDED) Shared library: [<?>]
+# BAD-STRTAB-LLVM-NEXT: 0x0000000000000001 NEEDED Shared library: <?>
+# BAD-STRTAB-GNU-NEXT: 0x0000000000000001 (NEEDED) Shared library: <?>
# BAD-STRTAB: NeededLibraries [
# BAD-STRTAB: <?>
# BAD-STRTAB: ]
@@ -313,15 +313,15 @@ ProgramHeaders:
# NOT-TERMINATED-LLVM: warning: '[[FILE]]': string table at offset 0xb0: unable to read the string at 0xb4: the string table is not null-terminated
# NOT-TERMINATED: warning: '[[FILE]]': string table at offset 0xb0: unable to read the string at 0xb0: the string table is not null-terminated
-# NOT-TERMINATED-NEXT: {{[(]?}}NEEDED{{[)]?}} Shared library: [<?>]
+# NOT-TERMINATED-NEXT: {{[(]?}}NEEDED{{[)]?}} Shared library: <?>
# NOT-TERMINATED-NEXT: warning: '[[FILE]]': string table at offset 0xb0: unable to read the string at 0xb1: the string table is not null-terminated
-# NOT-TERMINATED-NEXT: {{[(]?}}FILTER{{[)]?}} Filter library: [<?>]
+# NOT-TERMINATED-NEXT: {{[(]?}}FILTER{{[)]?}} Filter library: <?>
# NOT-TERMINATED-NEXT: warning: '[[FILE]]': string table at offset 0xb0: unable to read the string at 0xb2: the string table is not null-terminated
-# NOT-TERMINATED-NEXT: {{[(]?}}AUXILIARY{{[)]?}} Auxiliary library: [<?>]
+# NOT-TERMINATED-NEXT: {{[(]?}}AUXILIARY{{[)]?}} Auxiliary library: <?>
# NOT-TERMINATED-NEXT: warning: '[[FILE]]': string table at offset 0xb0: unable to read the string at 0xb3: the string table is not null-terminated
-# NOT-TERMINATED-NEXT: {{[(]?}}USED{{[)]?}} Not needed object: [<?>]
+# NOT-TERMINATED-NEXT: {{[(]?}}USED{{[)]?}} Not needed object: <?>
# NOT-TERMINATED-GNU-NEXT: warning: '[[FILE]]': string table at offset 0xb0: unable to read the string at 0xb4: the string table is not null-terminated
-# NOT-TERMINATED-NEXT: {{[(]?}}SONAME{{[)]?}} Library soname: [<?>]
+# NOT-TERMINATED-NEXT: {{[(]?}}SONAME{{[)]?}} Library soname: <?>
# NOT-TERMINATED-NEXT: warning: '[[FILE]]': string table at offset 0xb0: unable to read the string at 0xb5: the string table is not null-terminated
# NOT-TERMINATED-NEXT: {{[(]?}}RPATH{{[)]?}} Library rpath: [<?>]
# NOT-TERMINATED-GREQ-NEXT: warning: '[[FILE]]': string table at offset 0xb0: unable to read the string at 0xb6: the string table is not null-terminated
@@ -390,11 +390,11 @@ ProgramHeaders:
## as normal. Since the file ends with a zero byte, strings are dumped, but if it didn't,
## we'd get <?> printed instead. The important bit is that we don't get the past the end warning.
-# BEFORE-THE-EOF: {{[(]?}}NEEDED{{[)]?}} Shared library: [test.soabc]
-# BEFORE-THE-EOF-NEXT: {{[(]?}}FILTER{{[)]?}} Filter library: [est.soabc]
-# BEFORE-THE-EOF-NEXT: {{[(]?}}AUXILIARY{{[)]?}} Auxiliary library: [st.soabc]
-# BEFORE-THE-EOF-NEXT: {{[(]?}}USED{{[)]?}} Not needed object: [t.soabc]
-# BEFORE-THE-EOF-NEXT: {{[(]?}}SONAME{{[)]?}} Library soname: [.soabc]
+# BEFORE-THE-EOF: {{[(]?}}NEEDED{{[)]?}} Shared library: test.soabc
+# BEFORE-THE-EOF-NEXT: {{[(]?}}FILTER{{[)]?}} Filter library: est.soabc
+# BEFORE-THE-EOF-NEXT: {{[(]?}}AUXILIARY{{[)]?}} Auxiliary library: st.soabc
+# BEFORE-THE-EOF-NEXT: {{[(]?}}USED{{[)]?}} Not needed object: t.soabc
+# BEFORE-THE-EOF-NEXT: {{[(]?}}SONAME{{[)]?}} Library soname: .soabc
# BEFORE-THE-EOF-NEXT: {{[(]?}}RPATH{{[)]?}} Library rpath: [soabc]
# BEFORE-THE-EOF-NEXT: {{[(]?}}RUNPATH{{[)]?}} Library runpath: [oabc]
# BEFORE-THE-EOF-NEXT: {{[(]?}}NULL{{[)]?}} 0x0
@@ -406,11 +406,11 @@ ProgramHeaders:
# PAST-THE-EOF: warning: '[[FILE]]': the dynamic string table at 0xb0 goes past the end of the file (0x2c0) with DT_STRSZ = 0x211
# PAST-THE-EOF: warning: '[[FILE]]': string table was not found
-# PAST-THE-EOF: {{[(]?}}NEEDED{{[)]?}} Shared library: [<?>]
-# PAST-THE-EOF-NEXT: {{[(]?}}FILTER{{[)]?}} Filter library: [<?>]
-# PAST-THE-EOF-NEXT: {{[(]?}}AUXILIARY{{[)]?}} Auxiliary library: [<?>]
-# PAST-THE-EOF-NEXT: {{[(]?}}USED{{[)]?}} Not needed object: [<?>]
-# PAST-THE-EOF-NEXT: {{[(]?}}SONAME{{[)]?}} Library soname: [<?>]
+# PAST-THE-EOF: {{[(]?}}NEEDED{{[)]?}} Shared library: <?>
+# PAST-THE-EOF-NEXT: {{[(]?}}FILTER{{[)]?}} Filter library: <?>
+# PAST-THE-EOF-NEXT: {{[(]?}}AUXILIARY{{[)]?}} Auxiliary library: <?>
+# PAST-THE-EOF-NEXT: {{[(]?}}USED{{[)]?}} Not needed object: <?>
+# PAST-THE-EOF-NEXT: {{[(]?}}SONAME{{[)]?}} Library soname: <?>
# PAST-THE-EOF-NEXT: {{[(]?}}RPATH{{[)]?}} Library rpath: [<?>]
# PAST-THE-EOF-NEXT: {{[(]?}}RUNPATH{{[)]?}} Library runpath: [<?>]
# PAST-THE-EOF-NEXT: {{[(]?}}NULL{{[)]?}} 0x0
diff --git a/llvm/test/tools/llvm-readobj/ELF/dynamic-tags.test b/llvm/test/tools/llvm-readobj/ELF/dynamic-tags.test
index d05eed0f89cc6..e25f64ca22027 100644
--- a/llvm/test/tools/llvm-readobj/ELF/dynamic-tags.test
+++ b/llvm/test/tools/llvm-readobj/ELF/dynamic-tags.test
@@ -13,7 +13,7 @@
# LLVM64:DynamicSection [ (61 entries)
# LLVM64-NEXT: Tag Type Name/Value
-# LLVM64-NEXT: 0x0000000000000001 NEEDED Shared library: [D]
+# LLVM64-NEXT: 0x0000000000000001 NEEDED Shared library: D
# LLVM64-NEXT: 0x0000000000000002 PLTRELSZ 16 (bytes)
# LLVM64-NEXT: 0x0000000000000003 PLTGOT 0x1000
# LLVM64-NEXT: 0x0000000000000004 HASH 0x1000
@@ -26,8 +26,8 @@
# LLVM64-NEXT: 0x000000000000000B SYMENT 2439 (bytes)
# LLVM64-NEXT: 0x000000000000000C INIT 0x1000
# LLVM64-NEXT: 0x000000000000000D FINI 0x1000
-# LLVM64-NEXT: 0x000000000000000E SONAME Library soname: [U]
-# LLVM64-NEXT: 0x000000000000000F RPATH Library rpath: [f]
+# LLVM64-NEXT: 0x000000000000000E SONAME Library soname: U
+# LLVM64-NEXT: 0x000000000000000F RPATH Library rpath: [x:w:U]
# LLVM64-NEXT: 0x0000000000000010 SYMBOLIC 0x1234567890ABCDEF
# LLVM64-NEXT: 0x0000000000000011 REL 0x1000
# LLVM64-NEXT: 0x0000000000000012 RELSZ 16 (bytes)
@@ -67,9 +67,9 @@
# LLVM64-NEXT: 0x000000006FFFFFFD VERDEFNUM 0
# LLVM64-NEXT: 0x000000006FFFFFFE VERNEED 0x1000
# LLVM64-NEXT: 0x000000006FFFFFFF VERNEEDNUM 0
-# LLVM64-NEXT: 0x000000007FFFFFFD AUXILIARY Auxiliary library: [D]
-# LLVM64-NEXT: 0x000000007FFFFFFE USED Not needed object: [U]
-# LLVM64-NEXT: 0x000000007FFFFFFF FILTER Filter library: [U]
+# LLVM64-NEXT: 0x000000007FFFFFFD AUXILIARY Auxiliary library: D
+# LLVM64-NEXT: 0x000000007FFFFFFE USED Not needed object: U
+# LLVM64-NEXT: 0x000000007FFFFFFF FILTER Filter library: U
# LLVM64-NEXT: 0x0000000012345678 <unknown:>0x12345678 0x8765432187654321
# LLVM64-NEXT: 0x000000006ABCDEF0 <unknown:>0x6abcdef0 0x9988776655443322
# LLVM64-NEXT: 0x0000000076543210 <unknown:>0x76543210 0x5555666677778888
@@ -78,7 +78,7 @@
# GNU64:Dynamic section at offset {{.*}} contains 61 entries:
# GNU64-NEXT: Tag Type Name/Value
-# GNU64-NEXT: 0x0000000000000001 (NEEDED) Shared library: [D]
+# GNU64-NEXT: 0x0000000000000001 (NEEDED) Shared library: D
# GNU64-NEXT: 0x0000000000000002 (PLTRELSZ) 16 (bytes)
# GNU64-NEXT: 0x0000000000000003 (PLTGOT) 0x1000
# GNU64-NEXT: 0x0000000000000004 (HASH) 0x1000
@@ -91,8 +91,8 @@
# GNU64-NEXT: 0x000000000000000b (SYMENT) 2439 (bytes)
# GNU64-NEXT: 0x000000000000000c (INIT) 0x1000
# GNU64-NEXT: 0x000000000000000d (FINI) 0x1000
-# GNU64-NEXT: 0x000000000000000e (SONAME) Library soname: [U]
-# GNU64-NEXT: 0x000000000000000f (RPATH) Library rpath: [f]
+# GNU64-NEXT: 0x000000000000000e (SONAME) Library soname: U
+# GNU64-NEXT: 0x000000000000000f (RPATH) Library rpath: [x:w:U]
# GNU64-NEXT: 0x0000000000000010 (SYMBOLIC) 0x1234567890abcdef
# GNU64-NEXT: 0x0000000000000011 (REL) 0x1000
# GNU64-NEXT: 0x0000000000000012 (RELSZ) 16 (bytes)
@@ -132,9 +132,9 @@
# GNU64-NEXT: 0x000000006ffffffd (VERDEFNUM) 0
# GNU64-NEXT: 0x000000006ffffffe (VERNEED) 0x1000
# GNU64-NEXT: 0x000000006fffffff (VERNEEDNUM) 0
-# GNU64-NEXT: 0x000000007ffffffd (AUXILIARY) Auxiliary library: [D]
-# GNU64-NEXT: 0x000000007ffffffe (USED) Not needed object: [U]
-# GNU64-NEXT: 0x000000007fffffff (FILTER) Filter library: [U]
+# GNU64-NEXT: 0x000000007ffffffd (AUXILIARY) Auxiliary library: D
+# GNU64-NEXT: 0x000000007ffffffe (USED) Not needed object: U
+# GNU64-NEXT: 0x000000007fffffff (FILTER) Filter library: U
# GNU64-NEXT: 0x0000000012345678 (<unknown:>0x12345678) 0x8765432187654321
# GNU64-NEXT: 0x000000006abcdef0 (<unknown:>0x6abcdef0) 0x9988776655443322
# GNU64-NEXT: 0x0000000076543210 (<unknown:>0x76543210) 0x5555666677778888
@@ -216,9 +216,11 @@
# JSON64-NEXT: {
# JSON64-NEXT: "Tag": 15,
# JSON64-NEXT: "Type": "RPATH",
-# JSON64-NEXT: "Value": 5,
+# JSON64-NEXT: "Value": 9,
# JSON64-NEXT: "Path": [
-# JSON64-NEXT: "f"
+# JSON64-NEXT: "x",
+# JSON64-NEXT: "w",
+# JSON64-NEXT: "U"
# JSON64-NEXT: ]
# JSON64-NEXT: },
# JSON64-NEXT: {
@@ -506,7 +508,7 @@ Sections:
Type: SHT_STRTAB
Address: 0x1000
Size: 0x10
- Content: "004400550066007700"
+ Content: "004400550066007700783A773A5500"
- Name: .dynamic
Type: SHT_DYNAMIC
Address: 0x1010
@@ -540,7 +542,7 @@ Sections:
- Tag: DT_SONAME
Value: 0x3
- Tag: DT_RPATH
- Value: 0x5
+ Value: 0x9
- Tag: DT_SYMBOLIC
Value: [[SYMBOLIC=0x1234567890abcdef]]
- Tag: DT_REL
@@ -659,7 +661,7 @@ ProgramHeaders:
# LLVM32:DynamicSection [ (61 entries)
# LLVM32-NEXT: Tag Type Name/Value
-# LLVM32-NEXT: 0x00000001 NEEDED Shared library: [D]
+# LLVM32-NEXT: 0x00000001 NEEDED Shared library: D
# LLVM32-NEXT: 0x00000002 PLTRELSZ 16 (bytes)
# LLVM32-NEXT: 0x00000003 PLTGOT 0x1000
# LLVM32-NEXT: 0x00000004 HASH 0x1000
@@ -672,8 +674,8 @@ ProgramHeaders:
# LLVM32-NEXT: 0x0000000B SYMENT 2439 (bytes)
# LLVM32-NEXT: 0x0000000C INIT 0x1000
# LLVM32-NEXT: 0x0000000D FINI 0x1000
-# LLVM32-NEXT: 0x0000000E SONAME Library soname: [U]
-# LLVM32-NEXT: 0x0000000F RPATH Library rpath: [f]
+# LLVM32-NEXT: 0x0000000E SONAME Library soname: U
+# LLVM32-NEXT: 0x0000000F RPATH Library rpath: [x:w:U]
# LLVM32-NEXT: 0x00000010 SYMBOLIC 0x12345678
# LLVM32-NEXT: 0x00000011 REL 0x1000
# LLVM32-NEXT: 0x00000012 RELSZ 16 (bytes)
@@ -713,9 +715,9 @@ ProgramHeaders:
# LLVM32-NEXT: 0x6FFFFFFD VERDEFNUM 0
# LLVM32-NEXT: 0x6FFFFFFE VERNEED 0x1000
# LLVM32-NEXT: 0x6FFFFFFF VERNEEDNUM 0
-# LLVM32-NEXT: 0x7FFFFFFD AUXILIARY Auxiliary library: [D]
-# LLVM32-NEXT: 0x7FFFFFFE USED Not needed object: [U]
-# LLVM32-NEXT: 0x7FFFFFFF FILTER Filter library: [U]
+# LLVM32-NEXT: 0x7FFFFFFD AUXILIARY Auxiliary library: D
+# LLVM32-NEXT: 0x7FFFFFFE USED Not needed object: U
+# LLVM32-NEXT: 0x7FFFFFFF FILTER Filter library: U
# LLVM32-NEXT: 0x12345678 <unknown:>0x12345678 0x87654321
# LLVM32-NEXT: 0x6ABCDEF0 <unknown:>0x6abcdef0 0x99887766
# LLVM32-NEXT: 0x76543210 <unknown:>0x76543210 0x55556666
@@ -724,7 +726,7 @@ ProgramHeaders:
# GNU32:Dynamic section at offset 0x84 contains 61 entries:
# GNU32-NEXT: Tag Type Name/Value
-# GNU32-NEXT: 0x00000001 (NEEDED) Shared library: [D]
+# GNU32-NEXT: 0x00000001 (NEEDED) Shared library: D
# GNU32-NEXT: 0x00000002 (PLTRELSZ) 16 (bytes)
# GNU32-NEXT: 0x00000003 (PLTGOT) 0x1000
# GNU32-NEXT: 0x00000004 (HASH) 0x1000
@@ -737,8 +739,8 @@ ProgramHeaders:
# GNU32-NEXT: 0x0000000b (SYMENT) 2439 (bytes)
# GNU32-NEXT: 0x0000000c (INIT) 0x1000
# GNU32-NEXT: 0x0000000d (FINI) 0x1000
-# GNU32-NEXT: 0x0000000e (SONAME) Library soname: [U]
-# GNU32-NEXT: 0x0000000f (RPATH) Library rpath: [f]
+# GNU32-NEXT: 0x0000000e (SONAME) Library soname: U
+# GNU32-NEXT: 0x0000000f (RPATH) Library rpath: [x:w:U]
# GNU32-NEXT: 0x00000010 (SYMBOLIC) 0x12345678
# GNU32-NEXT: 0x00000011 (REL) 0x1000
# GNU32-NEXT: 0x00000012 (RELSZ) 16 (bytes)
@@ -778,9 +780,9 @@ ProgramHeaders:
# GNU32-NEXT: 0x6ffffffd (VERDEFNUM) 0
# GNU32-NEXT: 0x6ffffffe (VERNEED) 0x1000
# GNU32-NEXT: 0x6fffffff (VERNEEDNUM) 0
-# GNU32-NEXT: 0x7ffffffd (AUXILIARY) Auxiliary library: [D]
-# GNU32-NEXT: 0x7ffffffe (USED) Not needed object: [U]
-# GNU32-NEXT: 0x7fffffff (FILTER) Filter library: [U]
+# GNU32-NEXT: 0x7ffffffd (AUXILIARY) Auxiliary library: D
+# GNU32-NEXT: 0x7ffffffe (USED) Not needed object: U
+# GNU32-NEXT: 0x7fffffff (FILTER) Filter library: U
# GNU32-NEXT: 0x12345678 (<unknown:>0x12345678) 0x87654321
# GNU32-NEXT: 0x6abcdef0 (<unknown:>0x6abcdef0) 0x99887766
# GNU32-NEXT: 0x76543210 (<unknown:>0x76543210) 0x55556666
@@ -854,7 +856,7 @@ Sections:
# PHENTSIZE-LLVM: DynamicSection [ (61 entries)
# PHENTSIZE-LLVM-NEXT: Tag Type Name/Value
-# PHENTSIZE-LLVM-NEXT: 0x0000000000000001 NEEDED Shared library: [<?>]
+# PHENTSIZE-LLVM-NEXT: 0x0000000000000001 NEEDED Shared library: <?>
# PHENTSIZE-LLVM-NEXT: 0x0000000000000002 PLTRELSZ 16 (bytes)
# PHENTSIZE-LLVM-NEXT: 0x0000000000000003 PLTGOT 0x1000
# PHENTSIZE-LLVM-NEXT: 0x0000000000000004 HASH 0x1000
@@ -867,7 +869,7 @@ Sections:
# PHENTSIZE-LLVM-NEXT: 0x000000000000000B SYMENT 2439 (bytes)
# PHENTSIZE-LLVM-NEXT: 0x000000000000000C INIT 0x1000
# PHENTSIZE-LLVM-NEXT: 0x000000000000000D FINI 0x1000
-# PHENTSIZE-LLVM-NEXT: 0x000000000000000E SONAME Library soname: [<?>]
+# PHENTSIZE-LLVM-NEXT: 0x000000000000000E SONAME Library soname: <?>
# PHENTSIZE-LLVM-NEXT: 0x000000000000000F RPATH Library rpath: [<?>]
# PHENTSIZE-LLVM-NEXT: 0x0000000000000010 SYMBOLIC 0x1234567890ABCDEF
# PHENTSIZE-LLVM-NEXT: 0x0000000000000011 REL 0x1000
@@ -908,9 +910,9 @@ Sections:
# PHENTSIZE-LLVM-NEXT: 0x000000006FFFFFFD VERDEFNUM 0
# PHENTSIZE-LLVM-NEXT: 0x000000006FFFFFFE VERNEED 0x1000
# PHENTSIZE-LLVM-NEXT: 0x000000006FFFFFFF VERNEEDNUM 0
-# PHENTSIZE-LLVM-NEXT: 0x000000007FFFFFFD AUXILIARY Auxiliary library: [<?>]
-# PHENTSIZE-LLVM-NEXT: 0x000000007FFFFFFE USED Not needed object: [<?>]
-# PHENTSIZE-LLVM-NEXT: 0x000000007FFFFFFF FILTER Filter library: [<?>]
+# PHENTSIZE-LLVM-NEXT: 0x000000007FFFFFFD AUXILIARY Auxiliary library: <?>
+# PHENTSIZE-LLVM-NEXT: 0x000000007FFFFFFE USED Not needed object: <?>
+# PHENTSIZE-LLVM-NEXT: 0x000000007FFFFFFF FILTER Filter library: <?>
# PHENTSIZE-LLVM-NEXT: 0x0000000012345678 <unknown:>0x12345678 0x8765432187654321
# PHENTSIZE-LLVM-NEXT: 0x000000006ABCDEF0 <unknown:>0x6abcdef0 0x9988776655443322
# PHENTSIZE-LLVM-NEXT: 0x0000000076543210 <unknown:>0x76543210 0x5555666677778888
@@ -920,7 +922,7 @@ Sections:
# PHENTSIZE-GNU: Dynamic section at offset 0xc0 contains 61 entries:
# PHENTSIZE-GNU-NEXT: Tag Type Name/Value
# PHENTSIZE-GNU-NEXT: warning: '[[FILE]]': string table was not found
-# PHENTSIZE-GNU-NEXT: 0x0000000000000001 (NEEDED) Shared library: [<?>]
+# PHENTSIZE-GNU-NEXT: 0x0000000000000001 (NEEDED) Shared library: <?>
# PHENTSIZE-GNU-NEXT: 0x0000000000000002 (PLTRELSZ) 16 (bytes)
# PHENTSIZE-GNU-NEXT: 0x0000000000000003 (PLTGOT) 0x1000
# PHENTSIZE-GNU-NEXT: 0x0000000000000004 (HASH) 0x1000
@@ -933,7 +935,7 @@ Sections:
# PHENTSIZE-GNU-NEXT: 0x000000000000000b (SYMENT) 2439 (bytes)
# PHENTSIZE-GNU-NEXT: 0x000000000000000c (INIT) 0x1000
# PHENTSIZE-GNU-NEXT: 0x000000000000000d (FINI) 0x1000
-# PHENTSIZE-GNU-NEXT: 0x000000000000000e (SONAME) Library soname: [<?>]
+# PHENTSIZE-GNU-NEXT: 0x000000000000000e (SONAME) Library soname: <?>
# PHENTSIZE-GNU-NEXT: 0x000000000000000f (RPATH) Library rpath: [<?>]
# PHENTSIZE-GNU-NEXT: 0x0000000000000010 (SYMBOLIC) 0x1234567890abcdef
# PHENTSIZE-GNU-NEXT: 0x0000000000000011 (REL) 0x1000
@@ -974,9 +976,9 @@ Sections:
# PHENTSIZE-GNU-NEXT: 0x000000006ffffffd (VERDEFNUM) 0
# PHENTSIZE-GNU-NEXT: 0x000000006ffffffe (VERNEED) 0x1000
# PHENTSIZE-GNU-NEXT: 0x000000006fffffff (VERNEEDNUM) 0
-# PHENTSIZE-GNU-NEXT: 0x000000007ffffffd (AUXILIARY) Auxiliary library: [<?>]
-# PHENTSIZE-GNU-NEXT: 0x000000007ffffffe (USED) Not needed object: [<?>]
-# PHENTSIZE-GNU-NEXT: 0x000000007fffffff (FILTER) Filter library: [<?>]
+# PHENTSIZE-GNU-NEXT: 0x000000007ffffffd (AUXILIARY) Auxiliary library: <?>
+# PHENTSIZE-GNU-NEXT: 0x000000007ffffffe (USED) Not needed object: <?>
+# PHENTSIZE-GNU-NEXT: 0x000000007fffffff (FILTER) Filter library: <?>
# PHENTSIZE-GNU-NEXT: 0x0000000012345678 (<unknown:>0x12345678) 0x8765432187654321
# PHENTSIZE-GNU-NEXT: 0x000000006abcdef0 (<unknown:>0x6abcdef0) 0x9988776655443322
# PHENTSIZE-GNU-NEXT: 0x0000000076543210 (<unknown:>0x76543210) 0x5555666677778888
diff --git a/llvm/test/tools/llvm-readobj/ELF/loadname.test b/llvm/test/tools/llvm-readobj/ELF/loadname.test
index 18db00845e00b..359b9ca762334 100644
--- a/llvm/test/tools/llvm-readobj/ELF/loadname.test
+++ b/llvm/test/tools/llvm-readobj/ELF/loadname.test
@@ -15,7 +15,7 @@
# GNU-NEXT: Tag Type Name/Value
# GNU-NEXT: 0x0000000000000005 (STRTAB) 0x0
# GNU-NEXT: 0x000000000000000a (STRSZ) 8 (bytes)
-# GNU-NEXT: 0x000000000000000e (SONAME) Library soname: [test.so]
+# GNU-NEXT: 0x000000000000000e (SONAME) Library soname: test.so
# GNU-NEXT: 0x0000000000000000 (NULL) 0x0
!ELF
@@ -62,4 +62,4 @@ ProgramHeaders:
# BROKEN-OFFSET: warning: '[[FILE]]': unable to parse DT_STRTAB: can't map virtual address 0xfffe to the segment with index 1: the segment ends at 0x10077, which is greater than the file size (0x228)
# BROKEN-OFFSET: warning: '[[FILE]]': string table was not found
# BROKEN-OFFSET-LLVM: LoadName: <?>
-# BROKEN-OFFSET-GNU: 0x000000000000000e (SONAME) Library soname: [<?>]
+# BROKEN-OFFSET-GNU: 0x000000000000000e (SONAME) Library soname: <?>
diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp
index 734b28db63e54..a986ba88fdcfd 100644
--- a/llvm/tools/llvm-readobj/ELFDumper.cpp
+++ b/llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -2317,6 +2317,12 @@ std::string ELFDumper<ELFT>::getDynamicEntry(uint64_t Type,
return OS.str();
};
+ 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"},
+ };
// Handle custom printing of architecture specific tags
switch (Obj.getHeader().e_machine) {
case EM_AARCH64:
@@ -2474,18 +2480,11 @@ std::string ELFDumper<ELFT>::getDynamicEntry(uint64_t Type,
case DT_AUXILIARY:
case DT_USED:
case DT_FILTER:
+ return (Twine(TagNames.at(Type)) + ": " + getDynamicString(Value)).str();
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"},
- };
-
+ case DT_RUNPATH:
return (Twine(TagNames.at(Type)) + ": [" + getDynamicString(Value) + "]")
.str();
- }
case DT_FLAGS:
return FormatFlags(Value, ArrayRef(ElfDynamicDTFlags));
case DT_FLAGS_1:
More information about the llvm-commits
mailing list