[lld] Fix SEGFAULT in wasm-ld when importing wrapped symbol (PR #169656)
Lukas Döllerer via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 27 01:16:32 PST 2025
================
@@ -0,0 +1,36 @@
+# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown %s -o %t.o
+# RUN: wasm-ld -emit-relocs -wrap nosuchsym -wrap foo -allow-undefined -o %t.wasm %t.o
+# RUN: obj2yaml %t.wasm | FileCheck %s
+
+.globl foo
+.globl _start
+
+foo:
+ .functype foo () -> (i32)
+ i32.const 1
+ end_function
+
+_start:
+ .functype _start () -> ()
+ call foo
+ drop
+ end_function
+
+# CHECK: - Type: IMPORT
+# CHECK-NEXT: Imports:
+# CHECK-NEXT: - Module: env
+# CHECK-NEXT: Field: __wrap_foo
+# CHECK-NEXT: Kind: FUNCTION
+# CHECK-NEXT SigIndex: 0
+
+# CHECK: - Type: CODE
+# CHECK-NEXT: Relocations:
+# CHECK-NEXT: - Type: R_WASM_FUNCTION_INDEX_LEB
+# CHECK-NEXT: Index: 1
----------------
Lukasdoe wrote:
I just stepped through the code a bit and I think this is intended behavior.
```
- Type: CODE
Relocations:
- Type: R_WASM_FUNCTION_INDEX_LEB
Index: 1
Offset: 0x4
Functions:
- Index: 1
Locals: []
Body: 1080808080000B
- Type: CUSTOM
Name: linking
Version: 2
SymbolTable:
- Index: 0
Kind: FUNCTION
Name: _start
Flags: [ ]
Function: 1
- Index: 1
Kind: FUNCTION
Name: __wrap_foo
Flags: [ UNDEFINED ]
Function: 0
- Type: CUSTOM
Name: name
FunctionNames:
- Index: 0
Name: __wrap_foo
- Index: 1
Name: _start
```
The symbol index is a different one than the function index. `__wrap_foo` has symbol index 1, which is why the relocation is emitted for index 1, while `_start` has function index 1, explaining why this function is shown.
https://github.com/llvm/llvm-project/pull/169656
More information about the llvm-commits
mailing list