llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.32k stars 12.12k forks source link

wasm assembler does not support v128 global definition #61773

Open TerrorJack opened 1 year ago

TerrorJack commented 1 year ago

Consider this minimum repro:

    .hidden __R1
    .globl __R1
    .section .data.__R1,"",@
    .globaltype __R1, v128
__R1:

When attempting to compile it with clang --target=wasm32 -c test.s, it'll panic with the following error:

unexpected type
UNREACHABLE executed at /workspace/wasi-sdk/src/llvm-project/llvm/lib/MC/WasmObjectWriter.cpp:1676!
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.      Program arguments: /workspace/wasi-sdk/build/install/opt/wasi-sdk/bin/clang -c test.s
 #0 0x000055bc2f4459fd llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /workspace/wasi-sdk/src/llvm-project/llvm/lib/Support/Unix/Signals.inc:567:11
 #1 0x000055bc2f445e8b PrintStackTraceSignalHandler(void*) /workspace/wasi-sdk/src/llvm-project/llvm/lib/Support/Unix/Signals.inc:641:1
 #2 0x000055bc2f444236 llvm::sys::RunSignalHandlers() /workspace/wasi-sdk/src/llvm-project/llvm/lib/Support/Signals.cpp:104:5
 #3 0x000055bc2f4452ee llvm::sys::CleanupOnSignal(unsigned long) /workspace/wasi-sdk/src/llvm-project/llvm/lib/Support/Unix/Signals.inc:367:1
 #4 0x000055bc2f37f845 (anonymous namespace)::CrashRecoveryContextImpl::HandleCrash(int, unsigned long) /workspace/wasi-sdk/src/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:0:7
 #5 0x000055bc2f37fbe2 CrashRecoverySignalHandler(int) /workspace/wasi-sdk/src/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:391:1
 #6 0x00007f265c851cf0 (/lib/x86_64-linux-gnu/libc.so.6+0x3bcf0)
 #7 0x00007f265c8a826b __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #8 0x00007f265c8a826b __pthread_kill_internal ./nptl/pthread_kill.c:78:10
 #9 0x00007f265c8a826b pthread_kill ./nptl/pthread_kill.c:89:10
#10 0x00007f265c851c46 raise ./signal/../sysdeps/posix/raise.c:27:6
#11 0x00007f265c8387fc abort ./stdlib/abort.c:81:7
#12 0x000055bc2f387700 llvm::install_out_of_memory_new_handler() /workspace/wasi-sdk/src/llvm-project/llvm/lib/Support/ErrorHandling.cpp:193:0
#13 0x000055bc2efae6f5 (anonymous namespace)::WasmObjectWriter::writeOneObject(llvm::MCAssembler&, llvm::MCAsmLayout const&, (anonymous namespace)::WasmObjectWriter::DwoMode) /workspace/wasi-sdk/src/llvm-project/llvm/lib/MC/WasmObjectWriter.cpp:0:13
#14 0x000055bc2efaac52 (anonymous namespace)::WasmObjectWriter::writeObject(llvm::MCAssembler&, llvm::MCAsmLayout const&) /workspace/wasi-sdk/src/llvm-project/llvm/lib/MC/WasmObjectWriter.cpp:1448:5
#15 0x000055bc2eeeffdc llvm::MCAssembler::Finish() /workspace/wasi-sdk/src/llvm-project/llvm/lib/MC/MCAssembler.cpp:941:37
#16 0x000055bc2ef5fd04 llvm::MCObjectStreamer::finishImpl() /workspace/wasi-sdk/src/llvm-project/llvm/lib/MC/MCObjectStreamer.cpp:936:1
#17 0x000055bc2ef92716 llvm::MCWasmStreamer::finishImpl() /workspace/wasi-sdk/src/llvm-project/llvm/lib/MC/MCWasmStreamer.cpp:222:1
#18 0x000055bc2ef85640 llvm::MCStreamer::finish(llvm::SMLoc) /workspace/wasi-sdk/src/llvm-project/llvm/lib/MC/MCStreamer.cpp:1014:1
#19 0x000055bc2efeba81 (anonymous namespace)::AsmParser::Run(bool, bool) /workspace/wasi-sdk/src/llvm-project/llvm/lib/MC/MCParser/AsmParser.cpp:0:9
#20 0x000055bc2d9c31b2 ExecuteAssemblerImpl((anonymous namespace)::AssemblerInvocation&, clang::DiagnosticsEngine&) /workspace/wasi-sdk/src/llvm-project/clang/tools/driver/cc1as_main.cpp:579:12
#21 0x000055bc2d9c1770 ExecuteAssembler((anonymous namespace)::AssemblerInvocation&, clang::DiagnosticsEngine&) /workspace/wasi-sdk/src/llvm-project/clang/tools/driver/cc1as_main.cpp:587:8
#22 0x000055bc2d9bfa40 cc1as_main(llvm::ArrayRef<char const*>, char const*, void*) /workspace/wasi-sdk/src/llvm-project/clang/tools/driver/cc1as_main.cpp:665:45
#23 0x000055bc2d9a25b6 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) /workspace/wasi-sdk/src/llvm-project/clang/tools/driver/driver.cpp:362:5
#24 0x000055bc306c5b85 clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::$_0::operator()() const /workspace/wasi-sdk/src/llvm-project/clang/lib/Driver/Job.cpp:428:34
#25 0x000055bc306c5b55 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::$_0>(long) /workspace/wasi-sdk/src/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:45:5
#26 0x000055bc2df450f9 llvm::function_ref<void ()>::operator()() const /workspace/wasi-sdk/src/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:68:5
#27 0x000055bc2f37f66a llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) /workspace/wasi-sdk/src/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:427:3
#28 0x000055bc306c533b clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const /workspace/wasi-sdk/src/llvm-project/clang/lib/Driver/Job.cpp:428:7
#29 0x000055bc30663f5f clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const /workspace/wasi-sdk/src/llvm-project/clang/lib/Driver/Compilation.cpp:199:15
#30 0x000055bc30664167 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const /workspace/wasi-sdk/src/llvm-project/clang/lib/Driver/Compilation.cpp:253:13
#31 0x000055bc3067dd28 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) /workspace/wasi-sdk/src/llvm-project/clang/lib/Driver/Driver.cpp:1856:7
#32 0x000055bc2d9a1f78 clang_main(int, char**) /workspace/wasi-sdk/src/llvm-project/clang/tools/driver/driver.cpp:562:9
#33 0x000055bc2d9d4e72 main /workspace/wasi-sdk/build/llvm/tools/clang/tools/driver/clang-driver.cpp:11:35
#34 0x00007f265c839510 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#35 0x00007f265c8395c9 call_init ./csu/../csu/libc-start.c:128:20
#36 0x00007f265c8395c9 __libc_start_main ./csu/../csu/libc-start.c:368:5
#37 0x000055bc2d98eca5 _start (/workspace/wasi-sdk/build/install/opt/wasi-sdk/bin/clang+0x3cbdca5)
clang-16: error: clang integrated assembler command failed with exit code 134 (use -v to see invocation)
clang version 16.0.0 (git@gitlab.haskell.org:ghc/llvm-project.git 82c72626485a390ecf787a7fb920d24d5dcadac0)
Target: wasm32-unknown-wasi
Thread model: posix
InstalledDir: /workspace/wasi-sdk/build/install/opt/wasi-sdk/bin
clang-16: note: diagnostic msg: Error generating preprocessed source(s) - no preprocessable inputs.

The error comes from https://github.com/llvm/llvm-project/blob/main/llvm/lib/MC/WasmObjectWriter.cpp#L1676, so it's clear that the WASM assembler doesn't support v128 global definition yet. v128 globals can be defined in the WASM binary format spec, so it's a bug in Clang.

llvmbot commented 1 year ago

@llvm/issue-subscribers-backend-webassembly