Skip to content

[lld][WebAssembly] Don't report relocation error when linking with -r/--relocatable #109822

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lld/test/wasm/unsupported-pic-relocations.s
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
# RUN: not wasm-ld --experimental-pic -shared %t.o -o /dev/null --unresolved-symbols=import-dynamic 2>&1 | \
# RUN: FileCheck %s

## These errors should not be reported under -r/--relocation (i.e. when
## generating an object file)
# RUN: wasm-ld --experimental-pic -r %t.o -o /dev/null

.functype external_func () -> ()

use_undefined_function:
Expand All @@ -23,7 +27,7 @@ use_undefined_function:
# CHECK: error: {{.*}}.o: relocation R_WASM_TABLE_INDEX_REL_SLEB is not supported against an undefined symbol `external_func`
drop
end_function

use_undefined_data:
.functype use_undefined_data () -> ()
i32.const external_data@MBREL
Expand Down
6 changes: 5 additions & 1 deletion lld/test/wasm/unsupported-pic-relocations64.s
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
# RUN: not wasm-ld -mwasm64 --experimental-pic -shared %t.o -o /dev/null --unresolved-symbols=import-dynamic 2>&1 | \
# RUN: FileCheck %s

## These errors should not be reported under -r/--relocation (i.e. when
## generating an object file)
# RUN: wasm-ld -mwasm64 --experimental-pic -r %t.o -o /dev/null

.functype external_func () -> ()

use_undefined_function:
Expand All @@ -23,7 +27,7 @@ use_undefined_function:
# CHECK: error: {{.*}}.o: relocation R_WASM_TABLE_INDEX_REL_SLEB64 is not supported against an undefined symbol `external_func`
drop
end_function

use_undefined_data:
.functype use_undefined_data () -> ()
i64.const external_data@MBREL
Expand Down
10 changes: 5 additions & 5 deletions lld/wasm/Relocations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ void scanRelocations(InputChunk *chunk) {
}
}

if (sym->isUndefined()) {
if (!config->relocatable && sym->isUndefined()) {
switch (reloc.Type) {
case R_WASM_TABLE_INDEX_REL_SLEB:
case R_WASM_TABLE_INDEX_REL_SLEB64:
Expand All @@ -187,11 +187,11 @@ void scanRelocations(InputChunk *chunk) {
toString(*sym) + "`");
break;
}
}

if (sym->isUndefined() && !config->relocatable && !sym->isWeak()) {
// Report undefined symbols
reportUndefined(file, sym);
if (!sym->isWeak()) {
// Report undefined symbols
reportUndefined(file, sym);
}
}
}
}
Expand Down
Loading