[PATCH] D52145: lld-link: Also demangle undefined dllimported symbols.

Nico Weber via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Sep 15 17:40:45 PDT 2018


thakis updated this revision to Diff 165672.
thakis added a comment.

fix  case on variable


https://reviews.llvm.org/D52145

Files:
  Common/Strings.cpp
  test/COFF/undefined-symbol.s


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)
Index: Common/Strings.cpp
===================================================================
--- Common/Strings.cpp
+++ Common/Strings.cpp
@@ -38,14 +38,22 @@
 }
 
 Optional<std::string> 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<StringRef> Pat) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52145.165672.patch
Type: text/x-patch
Size: 1526 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180916/b19f0536/attachment.bin>


More information about the llvm-commits mailing list