emscripten-core / emscripten

Emscripten: An LLVM-to-WebAssembly Compiler
Other
25.63k stars 3.28k forks source link

wasm-ld: Section too large #22411

Open goodspeed1986 opened 3 weeks ago

goodspeed1986 commented 3 weeks ago

Hello. I have compiled the iec60870 library (https://github.com/mz-automation/lib60870) using emmake. When I try to compile my application that uses this library using emcc

emcc -g -o ../../../bin/client104_emcc simple_client_1.c -I../../src/inc/api -I../../src/hal/inc -I../../src/tls ../../build/liblib60870.a  

I get a [wasm-ld error](wasm-ld: error: linked_list.o: section too large).

emcc: error: '/opt/homebrew/Cellar/emscripten/3.1.64/libexec/llvm/bin/wasm-ld -o ../../../bin/client104_emcc.wasm /tmp/emscripten_temp_r4t89bci/simple_client_1_0.o ../../build/liblib60870.a -L/opt/homebrew/Cellar/emscripten/3.1.64/libexec/cache/sysroot/lib/wasm32-emscripten -lGL-getprocaddr -lal -lhtml5 -lstubs -lnoexit -lc -ldlmalloc -lcompiler_rt -lc++-noexcept -lc++abi-noexcept -lsockets -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr /tmp/tmp8ozmoqlrlibemscripten_js_symbols.so --export=_emscripten_stack_alloc --export=__get_temp_ret --export=__set_temp_ret --export=__wasm_call_ctors --export=emscripten_stack_get_current --export=_emscripten_stack_restore --export-if-defined=__start_em_asm --export-if-defined=__stop_em_asm --export-if-defined=__start_em_lib_deps --export-if-defined=__stop_em_lib_deps --export-if-defined=__start_em_js --export-if-defined=__stop_em_js --export-if-defined=main --export-if-defined=__main_argc_argv --export-table -z stack-size=65536 --no-growable-memory --initial-heap=16777216 --no-entry --table-base=1 --global-base=1024' failed (returned 1)

Is it possible to somehow solve this problem?

emcc -v emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.64-git clang version 19.0.0git Target: wasm32-unknown-emscripten Thread model: posix InstalledDir: /opt/homebrew/Cellar/emscripten/3.1.64/libexec/llvm/bin

kripken commented 3 weeks ago

This sounds like an LLVM issue, but @sbc100 might have a quick answer.

I'd guess this might be the code or the data section that is too large. @sbc100 is there a way to tell?

If it is code or data, then @goodspeed1986 optimizations might work around the issue. Perhaps adding -Oz somewhere in the build system could help.

sbc100 commented 3 weeks ago

@goodspeed1986, is it possible for you to attach linked_list.o to this issue? Based on its name I assume it implements a linked list, which should not be large in code or data size.. so something strange may be going on.

sbc100 commented 3 weeks ago

Indeed, this error comes from a malformed input, not from a valid but large section: https://github.com/llvm/llvm-project/blob/2599d695128381e6932b43f0e95649c533308d6d/llvm/lib/Object/WasmObjectFile.cpp#L321-L323

Specifcally it looks like it only happens when the section extents beyond the end of the file. So linked_list.o seems to be malformed in some way. Could you share the full command you used to build it? And the object itself if possible.

vadimkantorov commented 2 weeks ago

@sbc100 I also wonder what are the limits for the section sizes in wasm binaries :) (for the case of embedding data blobs into the wasm binary)

goodspeed1986 commented 1 week ago

I am attaching the file linked_list.o linked_list.zip

sbc100 commented 1 week ago

The file that you attached seems to be an ELF file not a wasm file.

goodspeed1986 commented 1 week ago

Sorry. Try this. linked_list.zip

sbc100 commented 1 week ago

That linked_list.o seems perfectly fine, and wasm-ld seems to accept it just fine without error.

Can you perhaps attach the whole library that contains linked_list.o or better still the result of running emcc with -Wl,--reproduce=repro.tar?

goodspeed1986 commented 1 week ago

liblib60870.zip Can i call functions from this library directly without c application?