emscripten-core / emscripten-core/emscripten

Emscripten fail to compile if the LLVM bitcode has unused global array of `ptr blockaddress(@XX, %ZZ)`

Open
#20,911 7 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

**Version of emscripten/emsdk:**
The result of `emcc -v` is as follows.
```
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.33 (c1927f22708aa9a26a5956bab61de083e8d3e463)
clang version 17.0.0 (https://github.com/llvm/llvm-project 671eeece457f6a5da7489f7b48f7afae55327b8b)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /home/masashi/emsdk/upstream/bin
```
**Failing command line in full:**
Failing command is as follows.
```
emcc -v -o test.wasm test.ll
```
The error output is as follows.
```
"/home/masashi/emsdk/upstream/bin/clang" --version
"/home/masashi/emsdk/upstream/bin/clang++" -target wasm32-unknown-emscripten -fignore-exceptions -fvisibility=default -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr -DEMSCRIPTEN --sysroot=/home/masashi/emsdk/upstream/emscripten/cache/sysroot -Xclang -iwithsysroot/include/fakesdl -Xclang -iwithsysroot/include/compat -v test.ll -c -o /tmp/emscripten_temp_o3bzg3_e/test_0.o
clang version 17.0.0 (https://github.com/llvm/llvm-project 671eeece457f6a5da7489f7b48f7afae55327b8b)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /home/masashi/emsdk/upstream/bin
(in-process)
"/home/masashi/emsdk/upstream/bin/clang-17" -cc1 -triple wasm32-unknown-emscripten -emit-obj -mrelax-all -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name test.ll -mrelocation-model static -mframe-pointer=none -ffp-contract=on -fno-rounding-math -mconstructor-aliases -target-cpu generic -mllvm -treat-scalable-fixed-error-as-warning -debugger-tuning=gdb -v -fcoverage-compilation-dir=/home/masashi/workspace/compiler/elfconv/build -resource-dir /home/masashi/emsdk/upstream/lib/clang/17 -fdebug-compilation-dir=/home/masashi/workspace/compiler/elfconv/build -ferror-limit 19 -fvisibility=default -fgnuc-version=4.2.1 -fignore-exceptions -fcolor-diagnostics -iwithsysroot/include/fakesdl -iwithsysroot/include/compat -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr -o /tmp/emscripten_temp_o3bzg3_e/test_0.o -x ir test.ll
clang -cc1 version 17.0.0 based upon LLVM 17.0.0git default target aarch64-unknown-linux-gnu
fatal error: error in backend: relocations for function or section offsets are only supported in metadata sections
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: /home/masashi/emsdk/upstream/bin/clang++ -target wasm32-unknown-emscripten -fignore-exceptions -fvisibility=default -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr -DEMSCRIPTEN --sysroot=/home/masashi/emsdk/upstream/emscripten/cache/sysroot -Xclang -iwithsysroot/include/fakesdl -Xclang -iwithsysroot/include/compat -v test.ll -c -o /tmp/emscripten_temp_o3bzg3_e/test_0.o
1. Code generation
#0 0x000000000274ad34 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/masashi/emsdk/upstream/bin/clang+++0x274ad34)
#1 0x0000000002748b4c llvm::sys::RunSignalHandlers() (/home/masashi/emsdk/upstream/bin/clang+++0x2748b4c)
#2 0x000000000274a04c llvm::sys::CleanupOnSignal(unsigned long) (/home/masashi/emsdk/upstream/bin/clang+++0x274a04c)
#3 0x00000000026c8cf0 (anonymous namespace)::CrashRecoveryContextImpl::HandleCrash(int, unsigned long) (.llvm.12806342961915451124) CrashRecoveryContext.cpp:0:0
#4 0x00000000026c8ca8 (anonymous namespace)::CrashRecoveryContextImpl::HandleCrash(int, unsigned long) (.llvm.12806342961915451124) CrashRecoveryContext.cpp:0:0
#5 0x000000000274486c llvm::sys::Process::ExitNoCleanup(int) (/home/masashi/emsdk/upstream/bin/clang+++0x274486c)
#6 0x00000000017379a8 std::pair>>, bool> llvm::StringMap>, llvm::MallocAllocator>::try_emplace<>(llvm::StringRef) cc1_main.cpp:0:0
#7 0x00000000026cceec llvm::report_fatal_error(llvm::Twine const&, bool) (/home/masashi/emsdk/upstream/bin/clang+++0x26cceec)
#8 0x00000000026ccdd8 llvm::report_fatal_error(llvm::Twine const&, bool) (/home/masashi/emsdk/upstream/bin/clang+++0x26ccdd8)
#9 0x0000000002492a64 (anonymous namespace)::WasmObjectWriter::recordRelocation(llvm::MCAssembler&, llvm::MCAsmLayout const&, llvm::MCFragment const*, llvm::MCFixup const&, llvm::MCValue, unsigned long&) WasmObjectWriter.cpp:0:0
#10 0x000000000243313c llvm::MCAssembler::layout(llvm::MCAsmLayout&) (/home/masashi/emsdk/upstream/bin/clang+++0x243313c)
#11 0x0000000002467038 llvm::MCObjectStreamer::finishImpl() (/home/masashi/emsdk/upstream/bin/clang+++0x2467038)
#12 0x00000000034fbc08 llvm::AsmPrinter::doFinalization(llvm::Module&) (/home/masashi/emsdk/upstream/bin/clang+++0x34fbc08)
#13 0x00000000022182cc llvm::FPPassManager::doFinalization(llvm::Module&) (/home/masashi/emsdk/upstream/bin/clang+++0x22182cc)
#14 0x0000000002212784 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/home/masashi/emsdk/upstream/bin/clang+++0x2212784)
#15 0x0000000002f130b0 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr, std::unique_ptr>) (/home/masashi/emsdk/upstream/bin/clang+++0x2f130b0)
#16 0x000000000333e588 clang::CodeGenAction::ExecuteAction() (/home/masashi/emsdk/upstream/bin/clang+++0x333e588)
#17 0x00000000032776e8 clang::FrontendAction::Execute() (/home/masashi/emsdk/upstream/bin/clang+++0x32776e8)
#18 0x00000000031ec610 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/home/masashi/emsdk/upstream/bin/clang+++0x31ec610)
#19 0x0000000003339c00 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/home/masashi/emsdk/upstream/bin/clang+++0x3339c00)
#20 0x00000000017372f8 cc1_main(llvm::ArrayRef, char const*, void*) (/home/masashi/emsdk/upstream/bin/clang+++0x17372f8)
#21 0x0000000001734d48 ExecuteCC1Tool(llvm::SmallVectorImpl&, llvm::ToolContext const&) driver.cpp:0:0
#22 0x00000000030adfc8 void llvm::function_ref::callback_fn>, std::__cxx11::basic_string, std::allocator>*, bool*) const::$_1>(long) Job.cpp:0:0
#23 0x00000000026c8c80 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref) (/home/masashi/emsdk/upstream/bin/clang+++0x26c8c80)
#24 0x00000000030ad8d0 clang::driver::CC1Command::Execute(llvm::ArrayRef>, std::__cxx11::basic_string, std::allocator>*, bool*) const (/home/masashi/emsdk/upstream/bin/clang+++0x30ad8d0)
#25 0x0000000003077dac clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/home/masashi/emsdk/upstream/bin/clang+++0x3077dac)
#26 0x0000000003077f8c clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl>&, bool) const (/home/masashi/emsdk/upstream/bin/clang+++0x3077f8c)
#27 0x0000000003091b4c clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl>&) (/home/masashi/emsdk/upstream/bin/clang+++0x3091b4c)
#28 0x0000000001733b7c clang_main(int, char**, llvm::ToolContext const&) (/home/masashi/emsdk/upstream/bin/clang+++0x1733b7c)
#29 0x00000000017410dc main (/home/masashi/emsdk/upstream/bin/clang+++0x17410dc)
#30 0x0000ffffbe4473fc (/lib/aarch64-linux-gnu/libc.so.6+0x273fc)
#31 0x0000ffffbe4474cc __libc_start_main (/lib/aarch64-linux-gnu/libc.so.6+0x274cc)
#32 0x000000000173042c _start (/home/masashi/emsdk/upstream/bin/clang+++0x173042c)
clang++: error: clang frontend command failed with exit code 70 (use -v to see invocation)
clang version 17.0.0 (https://github.com/llvm/llvm-project 671eeece457f6a5da7489f7b48f7afae55327b8b)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /home/masashi/emsdk/upstream/bin
clang++: note: diagnostic msg: Error generating preprocessed source(s) - no preprocessable inputs.
emcc: error: '/home/masashi/emsdk/upstream/bin/clang++ -target wasm32-unknown-emscripten -fignore-exceptions -fvisibility=default -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr -DEMSCRIPTEN --sysroot=/home/masashi/emsdk/upstream/emscripten/cache/sysroot -Xclang -iwithsysroot/include/fakesdl -Xclang -iwithsysroot/include/compat -v test.ll -c -o /tmp/emscripten_temp_o3bzg3_e/test_0.o' failed (returned 1)
```
**Description of the error**
I tried to compile the `test.ll` to WebAssembly binary by the command `emcc -o test.wasm test.ll`. The whole code of `test.ll` is shown below.
```llvm
; ModuleID = 'computed_goto.c'
source_filename = "computed_goto.c"
target datalayout = "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-f128:64-n32:64-S128-ni:1:10:20"
target triple = "wasm32-unknown-emscripten"

@main.addrs = internal global [1 x ptr] [ptr blockaddress(@main, %L1)], align 16
@.arr1 = internal global [5 x i64] [i64 4195120, i64 4195124, i64 4195128, i64 4195132, i64 -1]
@.str = private unnamed_addr constant [14 x i8] c"Hello, World!\00", align 1

@__main_void = hidden alias i32 (), ptr @main

; Function Attrs: noinline nounwind optnone
define i32 @main() #0 {
br label %L1

L1:
call i32 (ptr, ...) @printf(ptr noundef @.str)
ret i32 0
}

declare i32 @printf(ptr noundef, ...) #1

attributes #0 = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="generic" "target-features"="+mutable-globals,+sign-ext" }
attributes #1 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="generic" "target-features"="+mutable-globals,+sign-ext" }

!llvm.module.flags = !{!0}
!llvm.ident = !{!1}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{!"clang version 17.0.0 (https://github.com/llvm/llvm-project 671eeece457f6a5da7489f7b48f7afae55327b8b)"}
```
However, a fatal error occurred because `test.ll` has unused global array (`@main.addrs`) using emscripten, but clang (version: 16.0.6) can compile it.
Is this the correct behavior? Thanks.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.