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; } 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/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/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/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