Index: Common/Strings.cpp =================================================================== --- Common/Strings.cpp +++ Common/Strings.cpp @@ -38,14 +38,22 @@ } Optional lld::demangleMSVC(StringRef Name) { + // Note: This only works while the check for ? below is present, else a + // regular C function that happens to be called __imp__f would be considered + // an import stub. + std::string prefix; + if (Name.consume_front("__imp_")) + prefix = "__declspec(dllimport) "; + if (!Name.startswith("?")) return None; + char *Buf = microsoftDemangle(Name.str().c_str(), nullptr, nullptr, nullptr); if (!Buf) return None; std::string S(Buf); free(Buf); - return S; + return prefix + S; } StringMatcher::StringMatcher(ArrayRef Pat) { Index: test/COFF/undefined-symbol.s =================================================================== --- test/COFF/undefined-symbol.s +++ test/COFF/undefined-symbol.s @@ -10,7 +10,7 @@ # CHECK-NEXT: >>> referenced by {{.*}}.obj:(main) # CHECK-NEXT: >>> referenced by {{.*}}.obj:(f1) # CHECK-EMPTY: -# CHECK-NEXT: error: undefined symbol: "int __cdecl baz(void)" (?baz@@YAHXZ) +# CHECK-NEXT: error: undefined symbol: "__declspec(dllimport) int __cdecl baz(void)" (__imp_?baz@@YAHXZ) # CHECK-NEXT: >>> referenced by {{.*}}.obj:(f2) .section .text,"xr",one_only,main @@ -27,4 +27,4 @@ .section .text,"xr",one_only,f2 .globl f2 f2: - call "?baz@@YAHXZ" + callq *"__imp_?baz@@YAHXZ"(%rip)