[llvm] cd31802 - [llvm-objdump][COFF] Skip empty export entries when dumping the export table
Alexandre Ganea via llvm-commits
llvm-commits at lists.llvm.org
Thu May 4 11:29:10 PDT 2023
Author: Alexandre Ganea
Date: 2023-05-04T14:28:59-04:00
New Revision: cd3180296c10b033f106b34222b3a4a2aaf75d52
URL: https://github.com/llvm/llvm-project/commit/cd3180296c10b033f106b34222b3a4a2aaf75d52
DIFF: https://github.com/llvm/llvm-project/commit/cd3180296c10b033f106b34222b3a4a2aaf75d52.diff
LOG: [llvm-objdump][COFF] Skip empty export entries when dumping the export table
Before this patch, export entries with empy RVA were displayed in the output. In some cases, when the module had exports with sparse ordinals, `llvm-objdump` used to print a lot of `0 0` lines.
We now skip over these empty entries in the output, just as `dumpbin` or binutils `objdump` does.
Differential Revision: https://reviews.llvm.org/D149610
Added:
Modified:
lld/test/COFF/export.test
lld/test/COFF/export32.test
llvm/tools/llvm-objdump/COFFDump.cpp
Removed:
################################################################################
diff --git a/lld/test/COFF/export.test b/lld/test/COFF/export.test
index e53e3dea9aa29..755a552a57ff8 100644
--- a/lld/test/COFF/export.test
+++ b/lld/test/COFF/export.test
@@ -4,8 +4,9 @@
# RUN: llvm-objdump -p %t.dll | FileCheck --check-prefix=CHECK1 %s
CHECK1: Export Table:
-CHECK1: DLL name: export.test.tmp.dll
-CHECK1: Ordinal RVA Name
+CHECK1-NEXT: DLL name: export.test.tmp.dll
+CHECK1-NEXT: Ordinal base: 1
+CHECK1-NEXT: Ordinal RVA Name
CHECK1-NEXT: 1 0x1008 exportfn1
CHECK1-NEXT: 2 0x1010 exportfn2
@@ -13,12 +14,9 @@ CHECK1-NEXT: 2 0x1010 exportfn2
# RUN: llvm-objdump -p %t.dll | FileCheck --check-prefix=CHECK2 %s
CHECK2: Export Table:
-CHECK2: DLL name: export.test.tmp.dll
-CHECK2: Ordinal RVA Name
-CHECK2-NEXT: 1 0
-CHECK2-NEXT: 2 0
-CHECK2-NEXT: 3 0
-CHECK2-NEXT: 4 0
+CHECK2-NEXT: DLL name: export.test.tmp.dll
+CHECK2-NEXT: Ordinal base: 1
+CHECK2-NEXT: Ordinal RVA Name
CHECK2-NEXT: 5 0x1008 exportfn1
CHECK2-NEXT: 6 0x1010 exportfn2
CHECK2-NEXT: 7 0x1010 exportfn3
@@ -27,12 +25,9 @@ CHECK2-NEXT: 7 0x1010 exportfn3
# RUN: llvm-objdump -p %t.dll | FileCheck --check-prefix=CHECK3 %s
CHECK3: Export Table:
-CHECK3: DLL name: export.test.tmp.dll
-CHECK3: Ordinal RVA Name
-CHECK3-NEXT: 1 0
-CHECK3-NEXT: 2 0
-CHECK3-NEXT: 3 0
-CHECK3-NEXT: 4 0
+CHECK3-NEXT: DLL name: export.test.tmp.dll
+CHECK3-NEXT: Ordinal base: 1
+CHECK3-NEXT: Ordinal RVA Name
CHECK3-NEXT: 5 0x1008
CHECK3-NEXT: 6 0x1010 exportfn2
@@ -41,8 +36,9 @@ CHECK3-NEXT: 6 0x1010 exportfn2
# RUN: llvm-nm %t.lib | FileCheck -check-prefix=CHECK4-NM %s
CHECK4: Export Table:
-CHECK4: DLL name: export.test.tmp.dll
-CHECK4: Ordinal RVA Name
+CHECK4-NEXT: DLL name: export.test.tmp.dll
+CHECK4-NEXT: Ordinal base: 1
+CHECK4-NEXT: Ordinal RVA Name
CHECK4-NEXT: 1 0x1010 exportfn3
CHECK4-NEXT: 2 0x1008 f1
CHECK4-NEXT: 3 0x1010 f2
@@ -55,9 +51,9 @@ CHECK4-NM: 00000000 T f2
# RUN: llvm-objdump -p %t.dll | FileCheck --check-prefix=CHECK5 %s
CHECK5: Export Table:
-CHECK5: DLL name: export.test.tmp.dll
-CHECK5: Ordinal RVA Name
-CHECK5-NEXT: 1 0
+CHECK5-NEXT: DLL name: export.test.tmp.dll
+CHECK5-NEXT: Ordinal base: 1
+CHECK5-NEXT: Ordinal RVA Name
CHECK5-NEXT: 2 0x1010 fn2
CHECK5-NEXT: 3 0x1008 exportfn1
CHECK5-NEXT: 4 0x1010 exportfn3
diff --git a/lld/test/COFF/export32.test b/lld/test/COFF/export32.test
index 9f3f1827a65f8..8e27b0834024a 100644
--- a/lld/test/COFF/export32.test
+++ b/lld/test/COFF/export32.test
@@ -8,8 +8,9 @@
# RUN: llvm-readobj --file-headers --sections %t.dll | FileCheck -check-prefix=HEADER-MERGE %s
# CHECK1: Export Table:
-# CHECK1: DLL name: export32.test.tmp.dll
-# CHECK1: Ordinal RVA Name
+# CHECK1-NEXT: DLL name: export32.test.tmp.dll
+# CHECK1-NEXT: Ordinal base: 1
+# CHECK1-NEXT: Ordinal RVA Name
# CHECK1-NEXT: 1 0x1008 exportfn1
# CHECK1-NEXT: 2 0x1010 exportfn2
@@ -24,12 +25,9 @@
# RUN: llvm-objdump -p %t.dll | FileCheck --check-prefix=CHECK2 %s
# CHECK2: Export Table:
-# CHECK2: DLL name: export32.test.tmp.dll
-# CHECK2: Ordinal RVA Name
-# CHECK2-NEXT: 1 0
-# CHECK2-NEXT: 2 0
-# CHECK2-NEXT: 3 0
-# CHECK2-NEXT: 4 0
+# CHECK2-NEXT: DLL name: export32.test.tmp.dll
+# CHECK2-NEXT: Ordinal base: 1
+# CHECK2-NEXT: Ordinal RVA Name
# CHECK2-NEXT: 5 0x1008 exportfn1
# CHECK2-NEXT: 6 0x1010 exportfn2
# CHECK2-NEXT: 7 0x1010 exportfn3
@@ -39,12 +37,9 @@
# RUN: llvm-objdump -p %t.dll | FileCheck --check-prefix=CHECK3 %s
# CHECK3: Export Table:
-# CHECK3: DLL name: export32.test.tmp.dll
-# CHECK3: Ordinal RVA Name
-# CHECK3-NEXT: 1 0
-# CHECK3-NEXT: 2 0
-# CHECK3-NEXT: 3 0
-# CHECK3-NEXT: 4 0
+# CHECK3-NEXT: DLL name: export32.test.tmp.dll
+# CHECK3-NEXT: Ordinal base: 1
+# CHECK3-NEXT: Ordinal RVA Name
# CHECK3-NEXT: 5 0x1008
# CHECK3-NEXT: 6 0x1010 exportfn2
@@ -52,8 +47,9 @@
# RUN: llvm-objdump -p %t.dll | FileCheck --check-prefix=CHECK4 %s
# CHECK4: Export Table:
-# CHECK4: DLL name: export32.test.tmp.dll
-# CHECK4: Ordinal RVA Name
+# CHECK4-NEXT: DLL name: export32.test.tmp.dll
+# CHECK4-NEXT: Ordinal base: 1
+# CHECK4-NEXT: Ordinal RVA Name
# CHECK4-NEXT: 1 0x1010 exportfn3
# CHECK4-NEXT: 2 0x1008 f1
# CHECK4-NEXT: 3 0x1010 f2
@@ -69,9 +65,9 @@
# RUN: llvm-objdump -p %t.dll | FileCheck --check-prefix=CHECK5 %s
# CHECK5: Export Table:
-# CHECK5: DLL name: export32.test.tmp.dll
-# CHECK5: Ordinal RVA Name
-# CHECK5-NEXT: 1 0
+# CHECK5-NEXT: DLL name: export32.test.tmp.dll
+# CHECK5-NEXT: Ordinal base: 1
+# CHECK5-NEXT: Ordinal RVA Name
# CHECK5-NEXT: 2 0x1010 fn2
# CHECK5-NEXT: 3 0x1008 exportfn1
# CHECK5-NEXT: 4 0x1010 exportfn3
@@ -87,8 +83,9 @@
# RUN: llvm-objdump -p %t.dll | FileCheck --check-prefix=CHECK7 %s
# CHECK7: Export Table:
-# CHECK7: DLL name: export32.test.tmp.dll
-# CHECK7: Ordinal RVA Name
+# CHECK7-NEXT: DLL name: export32.test.tmp.dll
+# CHECK7-NEXT: Ordinal base: 1
+# CHECK7-NEXT: Ordinal RVA Name
# CHECK7-NEXT: 1 0x1010 exportfn3
# CHECK7-NEXT: 2 0x1010 foo
diff --git a/llvm/tools/llvm-objdump/COFFDump.cpp b/llvm/tools/llvm-objdump/COFFDump.cpp
index 56daee554eaaf..a7052cb3fb3cd 100644
--- a/llvm/tools/llvm-objdump/COFFDump.cpp
+++ b/llvm/tools/llvm-objdump/COFFDump.cpp
@@ -545,12 +545,18 @@ static void printExportTable(const COFFObjectFile *Obj) {
outs() << " Ordinal base: " << OrdinalBase << "\n";
outs() << " Ordinal RVA Name\n";
for (; I != E; I = ++I) {
- uint32_t Ordinal;
- if (I->getOrdinal(Ordinal))
- return;
uint32_t RVA;
if (I->getExportRVA(RVA))
return;
+ StringRef Name;
+ if (I->getSymbolName(Name))
+ continue;
+ if (!RVA && Name.empty())
+ continue;
+
+ uint32_t Ordinal;
+ if (I->getOrdinal(Ordinal))
+ return;
bool IsForwarder;
if (I->isForwarder(IsForwarder))
return;
@@ -564,9 +570,6 @@ static void printExportTable(const COFFObjectFile *Obj) {
outs() << format(" %5d %# 8x", Ordinal, RVA);
}
- StringRef Name;
- if (I->getSymbolName(Name))
- continue;
if (!Name.empty())
outs() << " " << Name;
if (IsForwarder) {
More information about the llvm-commits
mailing list