-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[lld][WebAssembly] Error on unexpected relocation types in -pie
/-shared
data sections
#162117
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
Conversation
-pie/
-s…-pie/
-shared` data sections
@llvm/pr-subscribers-lld @llvm/pr-subscribers-lld-wasm Author: Sam Clegg (sbc100) ChangesMost likely we do want to support R_WASM_FUNCTION_INDEX_I32 at some point but this relocation types (along with many others) is not currently supported by See #146923 Full diff: https://github.com/llvm/llvm-project/pull/162117.diff 2 Files Affected:
diff --git a/lld/test/wasm/bad-data-relocs.s b/lld/test/wasm/bad-data-relocs.s
new file mode 100644
index 0000000000000..4292d67eee0c8
--- /dev/null
+++ b/lld/test/wasm/bad-data-relocs.s
@@ -0,0 +1,27 @@
+## Certain relocations types are not supported by runtime relocation code
+## generated in `-shared/`-pie` binaries.
+
+# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown -o %t.o %s
+# RUN: not wasm-ld -pie --experimental-pic %t.o -o %t.wasm 2>&1 | FileCheck %s
+
+# CHECK: wasm-ld: error: invalid relocation type in data section: R_WASM_FUNCTION_INDEX_I32
+
+foo:
+ .functype foo (i32) -> ()
+ end_function
+
+.globl _start
+_start:
+ .functype _start () -> ()
+ i32.const bar@GOT
+ call foo@GOT
+ end_function
+
+# data section containing relocation type that is not valid in a data section
+.section .data,"",@
+.globl bar
+bar:
+ .int32 0
+ .size bar, 4
+
+.reloc bar, R_WASM_FUNCTION_INDEX_I32, foo
diff --git a/lld/wasm/InputChunks.cpp b/lld/wasm/InputChunks.cpp
index 181221a77b106..f5e9c4a04a48f 100644
--- a/lld/wasm/InputChunks.cpp
+++ b/lld/wasm/InputChunks.cpp
@@ -406,6 +406,16 @@ uint64_t InputChunk::getVA(uint64_t offset) const {
return (outputSeg ? outputSeg->startVA : 0) + getChunkOffset(offset);
}
+bool isValidRuntimeRelocation(WasmRelocType type) {
+ // TODO(https://github.com/llvm/llvm-project/issues/146923): Add
+ // R_WASM_FUNCTION_INDEX_I32 to this list
+ return type == R_WASM_TABLE_INDEX_I32 ||
+ type == R_WASM_TABLE_INDEX_I64 ||
+ type == R_WASM_MEMORY_ADDR_LOCREL_I32 ||
+ type == R_WASM_MEMORY_ADDR_I32 ||
+ type == R_WASM_MEMORY_ADDR_I64;
+}
+
// Generate code to apply relocations to the data section at runtime.
// This is only called when generating shared libraries (PIC) where address are
// not known at static link time.
@@ -426,6 +436,11 @@ bool InputChunk::generateRelocationCode(raw_ostream &os) const {
for (const WasmRelocation &rel : relocations) {
uint64_t offset = getVA(rel.Offset) - getInputSectionOffset();
+ if (!isValidRuntimeRelocation(rel.getType())) {
+ error("invalid relocation type in data section: " + relocTypetoString(rel.Type));
+ }
+
+
Symbol *sym = file->getSymbol(rel);
// Runtime relocations are needed when we don't know the address of
// a symbol statically.
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
978d109
to
583bada
Compare
…hared` data sections Most likely we do want to support R_WASM_FUNCTION_INDEX_I32 at some point but this relocation types (along with many others) is not currently supported by `InputChunk::generateRelocationCode`. See llvm#146923
-pie/
-shared` data sections-pie
/-shared
data sections
-pie
/-shared
data sections-pie
/-shared
data sections
Can we land this? I think it would be good first step in fixing #146923 since it turns that crash into an error. |
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/25/builds/12106 Here is the relevant piece of the build log for the reference
|
Most likely we do want to support R_WASM_FUNCTION_INDEX_I32 at some point but this relocation types (along with many others) is not currently supported by
InputChunk::generateRelocationCode
.See #146923