Skip to content

Commit 5ffd8ce

Browse files
committedSep 17, 2018
lld-link: Also demangle undefined dllimported symbols.
dllimported symbols go through an import stub that's called __imp_ followed by the name the stub points to. Make that work. Differential Revision: https://reviews.llvm.org/D52145 llvm-svn: 342401
1 parent 06d3b41 commit 5ffd8ce

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed
 

‎lld/Common/Strings.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,20 @@ Optional<std::string> lld::demangleItanium(StringRef Name) {
3838
}
3939

4040
Optional<std::string> lld::demangleMSVC(StringRef Name) {
41+
std::string Prefix;
42+
if (Name.consume_front("__imp_"))
43+
Prefix = "__declspec(dllimport) ";
44+
45+
// Demangle only C++ names.
4146
if (!Name.startswith("?"))
4247
return None;
48+
4349
char *Buf = microsoftDemangle(Name.str().c_str(), nullptr, nullptr, nullptr);
4450
if (!Buf)
4551
return None;
4652
std::string S(Buf);
4753
free(Buf);
48-
return S;
54+
return Prefix + S;
4955
}
5056

5157
StringMatcher::StringMatcher(ArrayRef<StringRef> Pat) {

‎lld/test/COFF/undefined-symbol.s

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# CHECK-NEXT: >>> referenced by {{.*}}.obj:(main)
1111
# CHECK-NEXT: >>> referenced by {{.*}}.obj:(f1)
1212
# CHECK-EMPTY:
13-
# CHECK-NEXT: error: undefined symbol: "int __cdecl baz(void)" (?baz@@YAHXZ)
13+
# CHECK-NEXT: error: undefined symbol: "__declspec(dllimport) int __cdecl baz(void)" (__imp_?baz@@YAHXZ)
1414
# CHECK-NEXT: >>> referenced by {{.*}}.obj:(f2)
1515

1616
.section .text,"xr",one_only,main
@@ -27,4 +27,4 @@ f1:
2727
.section .text,"xr",one_only,f2
2828
.globl f2
2929
f2:
30-
call "?baz@@YAHXZ"
30+
callq *"__imp_?baz@@YAHXZ"(%rip)

0 commit comments

Comments
 (0)
Please sign in to comment.