WebAssembly / WebAssembly/wasi-sdk

`-flto` + `-fwasm-exceptions` flags together break the compiler

Open
#629 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
CMake
Stars
1.6k
Forks
237
Avg merge
18h 26m
Merged PRs (30d)
5

Description

Here's a minimal reproducer:

$ echo 'int main(){}' >test.c
$ wasi-sdk-33.0-x86_64-linux/bin/clang --target=wasm32-wasip1 --sysroot wasi-sdk-33.0-x86_64-linux/share/wasi-sysroot -fwasm-exceptions -mllvm -wasm-use-legacy-eh=false -flto -lunwind test.c
wasm-ld: error: symbol type mismatch: __cpp_exception
>>> defined as WASM_SYMBOL_TYPE_FUNCTION in .../wasi-sdk-33.0-x86_64-linux/share/wasi-sysroot/lib/wasm32-wasip1/eh/llvm-lto/22.1.0-wasi-sdk/libunwind.a(Unwind-wasm.c.o)
>>> defined as WASM_SYMBOL_TYPE_TAG in a.out.lto.o
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Here's the error I'm getting from CMake during compiler detection:

-- Check for working C compiler: /usr/bin/ccache
-- Check for working C compiler: /usr/bin/ccache - broken
CMake Error at /usr/share/cmake-3.31/Modules/CMakeTestCCompiler.cmake:67 (message):
  The C compiler

    "/usr/bin/ccache"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: '/home/whitequark/Projects/yowasp/nextpnr/prjtrellis-build/CMakeFiles/CMakeScratch/TryCompile-axg3T6'
    
    Run Build Command(s): /usr/bin/cmake -E env VERBOSE=1 /usr/bin/gmake -f Makefile cmTC_31eb1/fast
    /usr/bin/gmake  -f CMakeFiles/cmTC_31eb1.dir/build.make CMakeFiles/cmTC_31eb1.dir/build
    gmake[1]: Entering directory '/home/whitequark/Projects/yowasp/nextpnr/prjtrellis-build/CMakeFiles/CMakeScratch/TryCompile-axg3T6'
    Building C object CMakeFiles/cmTC_31eb1.dir/testCCompiler.c.obj
    /usr/bin/ccache /home/whitequark/Projects/yowasp/nextpnr/wasi-sdk-33.0-x86_64-linux/bin/clang --target=wasm32-wasip1   --sysroot /home/whitequark/Projects/yowasp/nextpnr/wasi-sdk-33.0-x86_64-linux/share/wasi-sysroot -fwasm-exceptions -mllvm -wasm-use-legacy-eh=false -flto  -MD -MT CMakeFiles/cmTC_31eb1.dir/testCCompiler.c.obj -MF CMakeFiles/cmTC_31eb1.dir/testCCompiler.c.obj.d -o CMakeFiles/cmTC_31eb1.dir/testCCompiler.c.obj -c /home/whitequark/Projects/yowasp/nextpnr/prjtrellis-build/CMakeFiles/CMakeScratch/TryCompile-axg3T6/testCCompiler.c
    Linking C executable cmTC_31eb1
    /usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_31eb1.dir/link.txt --verbose=1
    clang: warning: argument unused during compilation: '-mllvm -wasm-use-legacy-eh=false' [-Wunused-command-line-argument]
    wasm-ld: error: symbol type mismatch: __cpp_exception
    >>> defined as WASM_SYMBOL_TYPE_FUNCTION in /home/whitequark/Projects/yowasp/nextpnr/wasi-sdk-33.0-x86_64-linux/share/wasi-sysroot/lib/wasm32-wasip1/eh/llvm-lto/22.1.0-wasi-sdk/libunwind.a(Unwind-wasm.c.o)
    >>> defined as WASM_SYMBOL_TYPE_TAG in cmTC_31eb1.lto.o
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    /usr/bin/ccache /home/whitequark/Projects/yowasp/nextpnr/wasi-sdk-33.0-x86_64-linux/bin/clang --target=wasm32-wasip1 --sysroot /home/whitequark/Projects/yowasp/nextpnr/wasi-sdk-33.0-x86_64-linux/share/wasi-sysroot -fwasm-exceptions -mllvm -wasm-use-legacy-eh=false -flto  -lunwind -Wl,--strip-all  CMakeFiles/cmTC_31eb1.dir/testCCompiler.c.obj -o cmTC_31eb1
    gmake[1]: *** [CMakeFiles/cmTC_31eb1.dir/build.make:103: cmTC_31eb1] Error 1
    gmake[1]: Leaving directory '/home/whitequark/Projects/yowasp/nextpnr/prjtrellis-build/CMakeFiles/CMakeScratch/TryCompile-axg3T6'
    gmake: *** [Makefile:134: cmTC_31eb1/fast] Error 2

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the minimal test.c reproducer using wasi-sdk-33.0-x86_64-linux/bin/clang and compare builds with -fwasm-exceptions, -mllvm -wasm-use-legacy-eh=false, and -flto. Inspect the CMake compiler-detection invocation in CMakeTestCCompiler.cmake and the reported __cpp_exception mismatch between libunwind.a and the LTO object. Done means the flag combination links successfully without the wasm-ld symbol type mismatch.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, cmake, wasm
Domain
build-system, compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.