Skip to content

Commit 312f737

Browse files
authored
[lld][WebAssembly] Don't report relocation error when linking with -r/--relocatable (#109822)
Followup to #104926. We ran into issues on the emscripten waterfall where relocation against `__dso_handle` were being reported as errors even though `-r/--relocatable` was being used to generate object file output rather than executable output.
1 parent 6dfeea3 commit 312f737

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

lld/test/wasm/unsupported-pic-relocations.s

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
# RUN: not wasm-ld --experimental-pic -shared %t.o -o /dev/null --unresolved-symbols=import-dynamic 2>&1 | \
1616
# RUN: FileCheck %s
1717

18+
## These errors should not be reported under -r/--relocation (i.e. when
19+
## generating an object file)
20+
# RUN: wasm-ld --experimental-pic -r %t.o -o /dev/null
21+
1822
.functype external_func () -> ()
1923

2024
use_undefined_function:
@@ -23,7 +27,7 @@ use_undefined_function:
2327
# CHECK: error: {{.*}}.o: relocation R_WASM_TABLE_INDEX_REL_SLEB is not supported against an undefined symbol `external_func`
2428
drop
2529
end_function
26-
30+
2731
use_undefined_data:
2832
.functype use_undefined_data () -> ()
2933
i32.const external_data@MBREL

lld/test/wasm/unsupported-pic-relocations64.s

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
# RUN: not wasm-ld -mwasm64 --experimental-pic -shared %t.o -o /dev/null --unresolved-symbols=import-dynamic 2>&1 | \
1616
# RUN: FileCheck %s
1717

18+
## These errors should not be reported under -r/--relocation (i.e. when
19+
## generating an object file)
20+
# RUN: wasm-ld -mwasm64 --experimental-pic -r %t.o -o /dev/null
21+
1822
.functype external_func () -> ()
1923

2024
use_undefined_function:
@@ -23,7 +27,7 @@ use_undefined_function:
2327
# CHECK: error: {{.*}}.o: relocation R_WASM_TABLE_INDEX_REL_SLEB64 is not supported against an undefined symbol `external_func`
2428
drop
2529
end_function
26-
30+
2731
use_undefined_data:
2832
.functype use_undefined_data () -> ()
2933
i64.const external_data@MBREL

lld/wasm/Relocations.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ void scanRelocations(InputChunk *chunk) {
173173
}
174174
}
175175

176-
if (sym->isUndefined()) {
176+
if (!config->relocatable && sym->isUndefined()) {
177177
switch (reloc.Type) {
178178
case R_WASM_TABLE_INDEX_REL_SLEB:
179179
case R_WASM_TABLE_INDEX_REL_SLEB64:
@@ -187,11 +187,11 @@ void scanRelocations(InputChunk *chunk) {
187187
toString(*sym) + "`");
188188
break;
189189
}
190-
}
191190

192-
if (sym->isUndefined() && !config->relocatable && !sym->isWeak()) {
193-
// Report undefined symbols
194-
reportUndefined(file, sym);
191+
if (!sym->isWeak()) {
192+
// Report undefined symbols
193+
reportUndefined(file, sym);
194+
}
195195
}
196196
}
197197
}

0 commit comments

Comments
 (0)