Repository navigation
Closed
Description
Trying to use a custom imported allocator but it's causing wasm-ld to segfault.
Been trying to repro this with upstream LLVM but so far having difficulties with clang++ ignoring --sysroot, so for now...
Using wasi-sdk-30.0-x86_64-windows and wasi-sysroot-30.0:
Save this file as "wraptest.cpp":
#include <stdlib.h>
void extern_dosomething(void *);
void *extern_malloc(size_t size);
void* __wrap_malloc(size_t size)
{
return extern_malloc(size);
}
[[clang::export_name("whatever")]]
void whatever(int a, int b)
{
void *mem = malloc(a);
extern_dosomething(mem);
}
Run:
wasm32-wasi-clang++ -O3 -Wl,--allow-undefined -Wl,--wrap=malloc --sysroot=<path to wasi-sysroot-30.0> -mexec-model=reactor -o wraptest.wasm wraptest.cpp
Crashes with segfault:
Exception Code: 0xC0000005
#0 0x00007ff69cfcee5d (C:\Users\Eric\Downloads\wasi-sdk-30.0-x86_64-windows\bin\wasm-ld.exe+0x32ee5d)
#1 0x00007ff69cfcf42b (C:\Users\Eric\Downloads\wasi-sdk-30.0-x86_64-windows\bin\wasm-ld.exe+0x32f42b)
#2 0x00007ff69cfb8bc6 (C:\Users\Eric\Downloads\wasi-sdk-30.0-x86_64-windows\bin\wasm-ld.exe+0x318bc6)
#3 0x00007ff69cfbefe3 (C:\Users\Eric\Downloads\wasi-sdk-30.0-x86_64-windows\bin\wasm-ld.exe+0x31efe3)
#4 0x00007ff69cfbfd66 (C:\Users\Eric\Downloads\wasi-sdk-30.0-x86_64-windows\bin\wasm-ld.exe+0x31fd66)
#5 0x00007ff69cfa80f2 (C:\Users\Eric\Downloads\wasi-sdk-30.0-x86_64-windows\bin\wasm-ld.exe+0x3080f2)
#6 0x00007ff69cfa7006 (C:\Users\Eric\Downloads\wasi-sdk-30.0-x86_64-windows\bin\wasm-ld.exe+0x307006)
#7 0x00007ff69cd5956a (C:\Users\Eric\Downloads\wasi-sdk-30.0-x86_64-windows\bin\wasm-ld.exe+0xb956a)
#8 0x00007ff69ccea151 (C:\Users\Eric\Downloads\wasi-sdk-30.0-x86_64-windows\bin\wasm-ld.exe+0x4a151)
#9 0x00007ff69ccea3da (C:\Users\Eric\Downloads\wasi-sdk-30.0-x86_64-windows\bin\wasm-ld.exe+0x4a3da)
#10 0x00007ff69e3537b0 (C:\Users\Eric\Downloads\wasi-sdk-30.0-x86_64-windows\bin\wasm-ld.exe+0x16b37b0)
#11 0x00007ffd6dcfe8d7 (C:\WINDOWS\System32\KERNEL32.DLL+0x2e8d7)
#12 0x00007ffd6fc4c40c (C:\WINDOWS\SYSTEM32\ntdll.dll+0x8c40c)
wasm32-wasi-clang++: error: linker command failed due to signal (use -v to see invocation)
Metadata
Metadata
Assignees
Labels
No labels
Activity
elasota commentedon Mar 2, 2026
Seems __wrap_malloc needs to be extern "C" so seems like the problem is more like it's crashing if it can't resolve it and a more minimal version is just:
sbc100 commentedon Mar 2, 2026
This looks like must be bug in wasm-ld, although I'm having trouble replicating it with emscripten.
Here we see the wasm-ld command succeed and then undefined symbol are reported later.
If you are able to build a repro case using just clang and wasm-ld (preferably built from tip-of-tree with symbol information), could you open llvm issue for this?
elasota commentedon Mar 2, 2026
Was able to get the intermediates with -v and try it with LLVM 22.1.0.
It happens with the wasm-sdk-30 wasm-ld, but doesn't happen in the LLVM 22.1.0 wasm-ld, so maybe this was fixed upstream at some point?
sbc100 commentedon Mar 2, 2026
Indeed, sounds like its already fixed upstream, so maybe its just question of waiting for the next release of wasi-sdk.
@alexcrichton is there a wasi-sdk with LLVM 22.1.0 coming soon?
alexcrichton commentedon Mar 2, 2026
We were just waiting for LLVM 22.1.0 historically, which happened last week I now realize, so time to rebase some things and get things merged.
sbc100 commentedon Mar 2, 2026
Great. Maybe we can leave this open for now and close as part of the next release.
Update to LLVM 22.1.0 (WebAssembly#585)