[llvm] be55829 - [llvm-readobj][COFF] Print forwarder export symbols correctly
Martin Storsjö via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 26 01:07:01 PDT 2022
Author: Alvin Wong
Date: 2022-09-26T11:05:41+03:00
New Revision: be5582981a748b9a48db71911dad9136d19c7997
URL: https://github.com/llvm/llvm-project/commit/be5582981a748b9a48db71911dad9136d19c7997
DIFF: https://github.com/llvm/llvm-project/commit/be5582981a748b9a48db71911dad9136d19c7997.diff
LOG: [llvm-readobj][COFF] Print forwarder export symbols correctly
Reviewed By: mstorsjo
Differential Revision: https://reviews.llvm.org/D134528
Added:
llvm/test/tools/llvm-readobj/COFF/exports-forwarder.yaml
Modified:
llvm/tools/llvm-readobj/COFFDumper.cpp
Removed:
################################################################################
diff --git a/llvm/test/tools/llvm-readobj/COFF/exports-forwarder.yaml b/llvm/test/tools/llvm-readobj/COFF/exports-forwarder.yaml
new file mode 100644
index 0000000000000..61f8ab1e595d4
--- /dev/null
+++ b/llvm/test/tools/llvm-readobj/COFF/exports-forwarder.yaml
@@ -0,0 +1,52 @@
+# RUN: yaml2obj %s -o %t
+# RUN: llvm-readobj --coff-exports %t | FileCheck %s
+
+# CHECK: Export {
+# CHECK-NEXT: Ordinal: 1
+# CHECK-NEXT: Name: LoadLibrary
+# CHECK-NEXT: ForwardedTo: kernel32.LoadLibrary
+# CHECK-NEXT: }
+
+# Test file generated with:
+# clang -O2 --target=x86_64-windows-msvc test.c -nostdlib -c -o test.obj
+# lld-link -dll -out:test.dll -entry:entry -export:LoadLibrary=kernel32.LoadLibrary test.obj
+# test.c:
+# void entry(void) {}
+
+--- !COFF
+OptionalHeader:
+ AddressOfEntryPoint: 4096
+ ImageBase: 6442450944
+ SectionAlignment: 4096
+ FileAlignment: 512
+ MajorOperatingSystemVersion: 6
+ MinorOperatingSystemVersion: 0
+ MajorImageVersion: 0
+ MinorImageVersion: 0
+ MajorSubsystemVersion: 6
+ MinorSubsystemVersion: 0
+ Subsystem: IMAGE_SUBSYSTEM_WINDOWS_GUI
+ DLLCharacteristics: [ IMAGE_DLL_CHARACTERISTICS_HIGH_ENTROPY_VA, IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE, IMAGE_DLL_CHARACTERISTICS_NX_COMPAT ]
+ SizeOfStackReserve: 1048576
+ SizeOfStackCommit: 4096
+ SizeOfHeapReserve: 1048576
+ SizeOfHeapCommit: 4096
+ ExportTable:
+ RelativeVirtualAddress: 8192
+ Size: 110
+header:
+ Machine: IMAGE_FILE_MACHINE_AMD64
+ Characteristics: [ IMAGE_FILE_EXECUTABLE_IMAGE, IMAGE_FILE_LARGE_ADDRESS_AWARE, IMAGE_FILE_DLL ]
+sections:
+ - Name: .text
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ VirtualAddress: 4096
+ VirtualSize: 1
+ SectionData: C3
+ - Name: .rdata
+ Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ ]
+ VirtualAddress: 8192
+ VirtualSize: 110
+ SectionData: 0000000000000000000000002820000001000000010000000100000043200000472000004B2000006578706F72742D666F727761726465722E632E746D702E646C6C00592000004D20000000004C6F61644C696272617279006B65726E656C33322E4C6F61644C69627261727900
+symbols: []
+...
diff --git a/llvm/tools/llvm-readobj/COFFDumper.cpp b/llvm/tools/llvm-readobj/COFFDumper.cpp
index 56c5d9c0ae538..4ae9d13153569 100644
--- a/llvm/tools/llvm-readobj/COFFDumper.cpp
+++ b/llvm/tools/llvm-readobj/COFFDumper.cpp
@@ -1789,18 +1789,29 @@ void COFFDumper::printCOFFExports() {
DictScope Export(W, "Export");
StringRef Name;
- uint32_t Ordinal, RVA;
+ uint32_t Ordinal;
+ bool IsForwarder;
if (Error E = Exp.getSymbolName(Name))
reportError(std::move(E), Obj->getFileName());
if (Error E = Exp.getOrdinal(Ordinal))
reportError(std::move(E), Obj->getFileName());
- if (Error E = Exp.getExportRVA(RVA))
+ if (Error E = Exp.isForwarder(IsForwarder))
reportError(std::move(E), Obj->getFileName());
W.printNumber("Ordinal", Ordinal);
W.printString("Name", Name);
- W.printHex("RVA", RVA);
+ StringRef ForwardTo;
+ if (IsForwarder) {
+ if (Error E = Exp.getForwardTo(ForwardTo))
+ reportError(std::move(E), Obj->getFileName());
+ W.printString("ForwardedTo", ForwardTo);
+ } else {
+ uint32_t RVA;
+ if (Error E = Exp.getExportRVA(RVA))
+ reportError(std::move(E), Obj->getFileName());
+ W.printHex("RVA", RVA);
+ }
}
}
More information about the llvm-commits
mailing list