[PATCH] D68017: [LLD] [COFF] Always demangle the __imp_ prefix to __declspec(dllimport)
Martin Storsjö via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 4 01:25:28 PDT 2019
mstorsjo updated this revision to Diff 223166.
mstorsjo edited the summary of this revision.
mstorsjo added a comment.
Updated to never remove the extra leading underscore on i386 (except when demangling itanium C++ symbols).
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D68017/new/
https://reviews.llvm.org/D68017
Files:
lld/COFF/Symbols.cpp
lld/test/COFF/delayimports-error.test
lld/test/COFF/duplicate.test
lld/test/COFF/undefined-symbol-itanium-i386.s
lld/test/COFF/undefined-symbol.s
Index: lld/test/COFF/undefined-symbol.s
===================================================================
--- lld/test/COFF/undefined-symbol.s
+++ lld/test/COFF/undefined-symbol.s
@@ -20,7 +20,7 @@
# CHECK-NEXT: error: undefined symbol: __declspec(dllimport) int __cdecl baz(void)
# CHECK-NEXT: >>> referenced by {{.*}}.obj:(f2)
# CHECK-EMPTY:
-# CHECK-NEXT: error: undefined symbol: __imp_undecorated
+# CHECK-NEXT: error: undefined symbol: __declspec(dllimport) undecorated
# CHECK-NEXT: >>> referenced by {{.*}}.obj:(f2)
.section .text,"xr",one_only,main
Index: lld/test/COFF/undefined-symbol-itanium-i386.s
===================================================================
--- lld/test/COFF/undefined-symbol-itanium-i386.s
+++ lld/test/COFF/undefined-symbol-itanium-i386.s
@@ -8,6 +8,7 @@
# NODEMANGLE: error: undefined symbol: __Z3barPKc
# NODEMANGLE: error: undefined symbol: __imp___Z3bazv
# NODEMANGLE: error: undefined symbol: _Z3fooi
+# NODEMANGLE: error: undefined symbol: __imp__cfunc
# CHECK: error: undefined symbol: foo(int)
# CHECK-NEXT: >>> referenced by {{.*}}.o:(_main)
@@ -21,6 +22,9 @@
# CHECK-NEXT: >>> referenced by {{.*}}.o:(_f2)
# CHECK-EMPTY:
# CHECK-NEXT: error: undefined symbol: _Z3fooi
+# CHECK-NEXT: >>> referenced by {{.*}}.o:(_f2)
+# CHECK-EMPTY:
+# CHECK-NEXT: error: undefined symbol: __declspec(dllimport) _cfunc
# CHECK-NEXT: >>> referenced by {{.*}}.o:(_f2)
.section .text,"xr",one_only,_main
@@ -39,3 +43,4 @@
_f2:
call *__imp___Z3bazv
call _Z3fooi
+ call *__imp__cfunc
Index: lld/test/COFF/duplicate.test
===================================================================
--- lld/test/COFF/duplicate.test
+++ lld/test/COFF/duplicate.test
@@ -9,5 +9,5 @@
RUN: llc -mtriple x86_64-windows-msvc -filetype obj -o gamma.obj %S/Inputs/gamma.ll
RUN: not lld-link /out:gamma.exe /subsystem:console /entry:mainCRTStartup gamma.obj alpha.lib 2>&1 | FileCheck %s -check-prefix CHECK-GAMMA
-CHECK-GAMMA: error: duplicate symbol: __imp_f in {{.*}}gamma.obj and in alpha.dll
+CHECK-GAMMA: error: duplicate symbol: __declspec(dllimport) f in {{.*}}gamma.obj and in alpha.dll
Index: lld/test/COFF/delayimports-error.test
===================================================================
--- lld/test/COFF/delayimports-error.test
+++ lld/test/COFF/delayimports-error.test
@@ -7,7 +7,7 @@
# RUN: /alternatename:__delayLoadHelper2=main /opt:noref >& %t.log
# RUN: FileCheck %s < %t.log
-# CHECK: cannot delay-load foo.dll due to import of data: __imp_datasym
+# CHECK: cannot delay-load foo.dll due to import of data: __declspec(dllimport) datasym
--- !COFF
header:
Index: lld/COFF/Symbols.cpp
===================================================================
--- lld/COFF/Symbols.cpp
+++ lld/COFF/Symbols.cpp
@@ -30,14 +30,16 @@
static std::string maybeDemangleSymbol(StringRef symName) {
if (config->demangle) {
std::string prefix;
- StringRef demangleInput = symName;
- if (demangleInput.consume_front("__imp_"))
+ StringRef prefixless = symName;
+ if (prefixless.consume_front("__imp_"))
prefix = "__declspec(dllimport) ";
+ StringRef demangleInput = prefixless;
if (config->machine == I386)
demangleInput.consume_front("_");
std::string demangled = demangle(demangleInput);
if (demangled != demangleInput)
- return prefix + demangled;
+ return prefix + demangle(demangleInput);
+ return (prefix + prefixless).str();
}
return symName;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68017.223166.patch
Type: text/x-patch
Size: 3516 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191004/728cb22d/attachment.bin>
More information about the llvm-commits
mailing list