Skip to content

-flto + -fwasm-exceptions flags together break the compiler #629

@whitequark

Description

@whitequark

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions