[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:39:55 PDT 2018
thakis created this revision.
thakis added a reviewer: ruiu.
Herald added a subscriber: erik.pilkington.
dllimported symbols go through an import stub that's called __imp_ followed by the name the stub points to. Make that work.
Follow-up to https://reviews.llvm.org/D52104
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.165671.patch
Type: text/x-patch
Size: 1526 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180916/61b3af8a/attachment.bin>
More information about the llvm-commits
mailing list