Index: COFF/SymbolTable.cpp =================================================================== --- COFF/SymbolTable.cpp +++ COFF/SymbolTable.cpp @@ -301,7 +301,8 @@ std::tie(S, WasInserted) = insert(N); if (!isa(F)) S->IsUsedInRegularObj = true; - if (WasInserted || !isa(S)) + if (WasInserted || (!isa(S) && !isa(S) && + !isa(S))) replaceSymbol(S, F, N, /*IsCOMDAT*/ false, /*IsExternal*/ true, Sym, C); else @@ -317,7 +318,8 @@ std::tie(S, WasInserted) = insert(N); if (!isa(F)) S->IsUsedInRegularObj = true; - if (WasInserted || !isa(S)) { + if (WasInserted || (!isa(S) && !isa(S) && + !isa(S))) { replaceSymbol(S, F, N, /*IsCOMDAT*/ true, /*IsExternal*/ true, Sym, nullptr); return {S, true}; @@ -334,7 +336,9 @@ std::tie(S, WasInserted) = insert(N); if (!isa(F)) S->IsUsedInRegularObj = true; - if (WasInserted || !isa(S)) + if (!WasInserted && (isa(S) || isa(S))) + reportDuplicate(S, F); + else if (WasInserted || !isa(S)) replaceSymbol(S, F, N, Size, Sym, C); else if (auto *DC = dyn_cast(S)) if (Size > DC->getSize()) Index: test/COFF/Inputs/otherFunc.s =================================================================== --- /dev/null +++ test/COFF/Inputs/otherFunc.s @@ -0,0 +1,7 @@ +.global otherFunc +.global MessageBoxA +.text +otherFunc: + ret +MessageBoxA: + ret Index: test/COFF/thunk-replace.s =================================================================== --- /dev/null +++ test/COFF/thunk-replace.s @@ -0,0 +1,15 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -triple=x86_64-win32 %s -filetype=obj -o %t.main.obj +# RUN: llvm-mc -triple=x86_64-win32 %p/Inputs/otherFunc.s -filetype=obj -o %t.other.obj +# RUN: llvm-ar rcs %t.other.lib %t.other.obj +# RUN: not lld-link -out:%t.exe -entry:main %t.main.obj %p/Inputs/std64.lib %t.other.lib -opt:noref 2>&1 | FileCheck %s +# CHECK: duplicate symbol: MessageBoxA + +.global main +.text +main: + callq MessageBoxA + callq ExitProcess + callq otherFunc + ret