mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-18 19:16:43 +00:00
[LLD][COFF] Handle imported weak aliases consistently (#109105)
symTab being a DenseMap, the order in which a symbol and its corresponding import symbol are processed is not guaranteed, and when the latter comes first, it is left undefined.
This commit is contained in:
parent
403897484f
commit
5e23b66699
@ -502,6 +502,14 @@ void SymbolTable::resolveRemainingUndefines() {
|
||||
// This odd rule is for compatibility with MSVC linker.
|
||||
if (name.starts_with("__imp_")) {
|
||||
Symbol *imp = find(name.substr(strlen("__imp_")));
|
||||
if (imp) {
|
||||
// The unprefixed symbol might come later in symMap, so handle it now
|
||||
// so that the condition below can be appropriately applied.
|
||||
auto *undef = dyn_cast<Undefined>(imp);
|
||||
if (undef) {
|
||||
undef->resolveWeakAlias();
|
||||
}
|
||||
}
|
||||
if (imp && isa<Defined>(imp)) {
|
||||
auto *d = cast<Defined>(imp);
|
||||
replaceSymbol<DefinedLocalImport>(sym, ctx, name, d);
|
||||
|
20
lld/test/COFF/import_weak_alias.test
Normal file
20
lld/test/COFF/import_weak_alias.test
Normal file
@ -0,0 +1,20 @@
|
||||
# REQUIRES: x86
|
||||
|
||||
# RUN: split-file %s %t.dir
|
||||
# RUN: llvm-mc --filetype=obj -triple=x86_64-windows-msvc %t.dir/foo.s -o %t.foo.obj
|
||||
# RUN: llvm-mc --filetype=obj -triple=x86_64-windows-msvc %t.dir/qux.s -o %t.qux.obj
|
||||
# RUN: lld-link %t.qux.obj %t.foo.obj -out:%t.dll -dll
|
||||
#
|
||||
#--- foo.s
|
||||
.text
|
||||
bar:
|
||||
ret
|
||||
|
||||
.weak foo
|
||||
.set foo, bar
|
||||
#--- qux.s
|
||||
.text
|
||||
.global _DllMainCRTStartup
|
||||
_DllMainCRTStartup:
|
||||
call *__imp_foo(%rip)
|
||||
ret
|
Loading…
x
Reference in New Issue
Block a user