Skip to content

Commit 738f717

Browse files
committed
[lld][WebAssembly] Fix regression in function signature checking
Followup to #78658, which caused a regression in emscripten. When a lazy symbol is added, which resolved and existing undefined symbol, we don't need/want to replace the undefined symbol with the lazy one. Instead we called extract, which replaces the undefined symbol with the defined one. The fact that we were first replacing the undefined symbol with a lazy one before extracting the archive member doesn't normally matter but, in the case of the function symbol, replacing the undefined symbol with a lazy symbol means that `addDefinedFunction` sees the existing symbol as lazy and simply replaces it. Note that this is consistent with both the ELF code in `Symbol::resolve(const LazySymbol &other)` and the wasm code prior to #78658, neither of which replace the existing symbol with the lazy one in this case.
1 parent bcc9b9d commit 738f717

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

lld/test/wasm/signature-mismatch.s

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
# RUN: wasm-ld -r -o %t.reloc.o %t.main.o %t.ret32.o %t.call.o 2>&1 | FileCheck %s -check-prefix=WARN
99
# RUN: obj2yaml %t.reloc.o | FileCheck %s -check-prefix=RELOC
1010

11+
# RUN: rm -f %t.a
12+
# RUN: ar crS %t.a %t.ret32.o %t.call.o
13+
# RUN: wasm-ld --export=call_ret32 --export=ret32 -o %t2.wasm %t.main.o %t.a 2>&1 | FileCheck %s -check-prefix=ARCHIVE
14+
# RUN: obj2yaml %t2.wasm | FileCheck %s -check-prefix=YAML
15+
1116
# RUN: not wasm-ld --fatal-warnings -o %t.wasm %t.main.o %t.ret32.o %t.call.o 2>&1 | FileCheck %s -check-prefix=ERROR
1217

1318
.functype ret32 (i32, i64, i32) -> (i32)
@@ -42,6 +47,10 @@ ret32_address_main:
4247
# WARN-NEXT: >>> defined as (i32, i64, i32) -> i32 in {{.*}}.main.o
4348
# WARN-NEXT: >>> defined as (f32) -> i32 in {{.*}}.ret32.o
4449

50+
# ARCHIVE: warning: function signature mismatch: ret32
51+
# ARCHIVE-NEXT: >>> defined as (i32, i64, i32) -> i32 in {{.*}}.main.o
52+
# ARCHIVE-NEXT: >>> defined as (f32) -> i32 in {{.*}}.ret32.o
53+
4554
# ERROR: error: function signature mismatch: ret32
4655
# ERROR-NEXT: >>> defined as (i32, i64, i32) -> i32 in {{.*}}.main.o
4756
# ERROR-NEXT: >>> defined as (f32) -> i32 in {{.*}}.ret32.o
@@ -56,7 +65,7 @@ ret32_address_main:
5665

5766
# YAML: - Type: CUSTOM
5867
# YAML-NEXT: Name: name
59-
# YAML-NEXT: FunctionNames:
68+
# YAML-NEXT: FunctionNames:
6069
# YAML-NEXT: - Index: 0
6170
# YAML-NEXT: Name: 'signature_mismatch:ret32'
6271
# YAML-NEXT: - Index: 1

lld/wasm/SymbolTable.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@ void SymbolTable::addLazy(StringRef name, InputFile *file) {
774774

775775
LLVM_DEBUG(dbgs() << "replacing existing undefined\n");
776776
const InputFile *oldFile = s->getFile();
777-
replaceSymbol<LazySymbol>(s, name, 0, file)->extract();
777+
LazySymbol(name, 0, file).extract();
778778
if (!config->whyExtract.empty())
779779
ctx.whyExtractRecords.emplace_back(toString(oldFile), s->getFile(), *s);
780780
}

0 commit comments

Comments
 (0)