Index: COFF/Symbols.cpp =================================================================== --- COFF/Symbols.cpp +++ COFF/Symbols.cpp @@ -27,9 +27,20 @@ // Returns a symbol name for an error message. static std::string demangle(StringRef symName) { - if (config->demangle) + if (config->demangle) { if (Optional s = demangleMSVC(symName)) return *s; + if (config->mingw) { + StringRef demangleInput = symName; + std::string prefix; + if (demangleInput.consume_front("__imp_")) + prefix = "__declspec(dllimport) "; + if (config->machine == I386) + demangleInput.consume_front("_"); + if (Optional s = demangleItanium(demangleInput)) + return prefix + *s; + } + } return symName; } std::string toString(coff::Symbol &b) { return demangle(b.getName()); } Index: test/COFF/undefined-symbol-itanium-i386.s =================================================================== --- /dev/null +++ test/COFF/undefined-symbol-itanium-i386.s @@ -0,0 +1,36 @@ +# REQUIRES: x86 +# RUN: llvm-mc -triple=i386-windows-gnu -filetype=obj -o %t.o %s +# RUN: not lld-link /lldmingw /out:%t.exe %t.o 2>&1 | FileCheck %s +# RUN: not lld-link /lldmingw /out:%t.exe /demangle %t.o 2>&1 | FileCheck %s +# RUN: not lld-link /lldmingw /out:%t.exe /demangle:no %t.o 2>&1 | FileCheck --check-prefix=NODEMANGLE %s + +# NODEMANGLE: error: undefined symbol: __Z3fooi +# NODEMANGLE: error: undefined symbol: __Z3barPKc +# NODEMANGLE: error: undefined symbol: __imp___Z3bazv + +# CHECK: error: undefined symbol: foo(int) +# CHECK-NEXT: >>> referenced by {{.*}}.o:(_main) +# CHECK-NEXT: >>> referenced by {{.*}}.o:(_main) +# CHECK-EMPTY: +# CHECK-NEXT: error: undefined symbol: bar(char const*) +# CHECK-NEXT: >>> referenced by {{.*}}.o:(_main) +# CHECK-NEXT: >>> referenced by {{.*}}.o:(_f1) +# CHECK-EMPTY: +# CHECK-NEXT: error: undefined symbol: __declspec(dllimport) baz() +# CHECK-NEXT: >>> referenced by {{.*}}.o:(_f2) + + .section .text,"xr",one_only,_main +.globl _main +_main: + call __Z3fooi + call __Z3fooi + call __Z3barPKc + +_f1: + call __Z3barPKc +.Lfunc_end1: + + .section .text,"xr",one_only,_f2 +.globl _f2 +_f2: + call *__imp___Z3bazv Index: test/COFF/undefined-symbol-itanium.s =================================================================== --- /dev/null +++ test/COFF/undefined-symbol-itanium.s @@ -0,0 +1,36 @@ +# REQUIRES: x86 +# RUN: llvm-mc -triple=x86_64-windows-gnu -filetype=obj -o %t.o %s +# RUN: not lld-link /lldmingw /out:%t.exe %t.o 2>&1 | FileCheck %s +# RUN: not lld-link /lldmingw /out:%t.exe /demangle %t.o 2>&1 | FileCheck %s +# RUN: not lld-link /lldmingw /out:%t.exe /demangle:no %t.o 2>&1 | FileCheck --check-prefix=NODEMANGLE %s + +# NODEMANGLE: error: undefined symbol: _Z3fooi +# NODEMANGLE: error: undefined symbol: _Z3barPKc +# NODEMANGLE: error: undefined symbol: __imp__Z3bazv + +# CHECK: error: undefined symbol: foo(int) +# CHECK-NEXT: >>> referenced by {{.*}}.o:(main) +# CHECK-NEXT: >>> referenced by {{.*}}.o:(main) +# CHECK-EMPTY: +# CHECK-NEXT: error: undefined symbol: bar(char const*) +# CHECK-NEXT: >>> referenced by {{.*}}.o:(main) +# CHECK-NEXT: >>> referenced by {{.*}}.o:(f1) +# CHECK-EMPTY: +# CHECK-NEXT: error: undefined symbol: __declspec(dllimport) baz() +# CHECK-NEXT: >>> referenced by {{.*}}.o:(f2) + + .section .text,"xr",one_only,main +.globl main +main: + call _Z3fooi + call _Z3fooi + call _Z3barPKc + +f1: + call _Z3barPKc +.Lfunc_end1: + + .section .text,"xr",one_only,f2 +.globl f2 +f2: + callq *__imp__Z3bazv(%rip)