简体   繁体   中英

WebAssembly wasm-ld cannot resolve __builtin_memcpy and __builtin_memset

I'm working on a C++/Wasm-Module and have a hard time with clang and wasm-ld .

the toolchain lets me use builtin functions like

  • __builtin_clz
  • __builtin_floorf

just fine. The following functions are accepted by clang, but cannot be resolved by wasm-ld.

  • __builtin_memcpy
  • __builtin_memset
wasm-ld: error: lto.tmp: undefined symbol: memcpy

below are the flags i pass to clang and wasm-ld in my makefile: weird is, that even though i explicitly call the builtin function, clang emits the clib name.

// clang.exe
CLANGFLAGS = \
    -c \
    --target=wasm32 \
    -Os \
    -flto \
    --include-directory=.

//wasm-ld.exe
LDFLAGS = \
    -O3 \
    --no-entry \
    --strip-all \
    --export-dynamic \
    --lto-O3 \
    --gc-sections
    --std=c++20

what i have tried:

  1. I thought, I could cheat and maybe use memset() and forward it to the builtin equivalent - this just ends in a stack-overflow because of an endless recursion. The method just calls itself over and over again.
extern "C" void* memset(void* pMemory, i32 value, size_t length) noexcept {
    return __builtin_memset(pMemory, value, length);
}
  1. disable link time optimization -flto. Doesn't help. Error is now reported by clang instead of wasm-ld.
  2. disabled all flags except --target=wasm32 and --no-entry. Nope...

Google didn't have a good advice 'til now. But maybe you guys do.

I Confirm the suggestion by Hasturkun :

The memory builtins get enabled by -mbulk-memory. See stackoverflow.com/a/67084011 for a more details.

clang -c --target=wasm32 -mbulk-memory

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM