emscripten icon indicating copy to clipboard operation
emscripten copied to clipboard

wasm-ld: Section too large

Open goodspeed1986 opened this issue 1 year ago • 9 comments

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

goodspeed1986 avatar Aug 20 '24 12:08 goodspeed1986

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.

kripken avatar Aug 20 '24 18:08 kripken

@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 avatar Aug 20 '24 20:08 sbc100

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.

sbc100 avatar Aug 20 '24 20:08 sbc100

@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)

vadimkantorov avatar Aug 30 '24 11:08 vadimkantorov

I am attaching the file linked_list.o linked_list.zip

goodspeed1986 avatar Sep 02 '24 08:09 goodspeed1986

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

sbc100 avatar Sep 03 '24 17:09 sbc100

Sorry. Try this. linked_list.zip

goodspeed1986 avatar Sep 04 '24 14:09 goodspeed1986

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?

sbc100 avatar Sep 05 '24 16:09 sbc100

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

goodspeed1986 avatar Sep 06 '24 13:09 goodspeed1986

That library looks pretty odd:

$ ar t lib.a 
/
//
linked_list.o
frame.o

cs101_asdu.o
cs101_bcr.o
�
cs101_master.o

cs101_queue.o
cs101_slave.o
�
cs104_frame.o
cs104_slave.o
buffer_frame.o
link_layer.o
�
cpXXtime2a.o
socket_bsd.o
thread_bsd.o
time.o
lib_memory.o

Do you know why it has those strange things it like / and //?

sbc100 avatar Jan 02 '25 23:01 sbc100

I think somehow your archive files are corrupted, or at least not created using the normal emar / llvm-ar tools.

I was able to reproduce the section too large by extracting the object files and trying to use them directly:

$ ar x lib.a lib_memory.o
$ emcc lib_memory.o 
wasm-ld: error: lib_memory.o: section too large
emcc: error: '/home/sbc/dev/wasm/emsdk/upstream/bin/wasm-ld -o a.out.wasm lib_memory.o -L/home/sbc/dev/wasm/emscripten/cache/sysroot/lib/wasm32-emscripten -lGL-getprocaddr -lal -lhtml5 -lstubs-debug -lnoexit -lc-debug -ldlmalloc -lcompiler_rt -lc++-noexcept -lc++abi-debug-noexcept -lsockets -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr /tmp/tmpocuqhxa_libemscripten_js_symbols.so --strip-debug --export=emscripten_stack_get_end --export=emscripten_stack_get_free --export=emscripten_stack_get_base --export=emscripten_stack_get_current --export=emscripten_stack_init --export=_emscripten_stack_alloc --export=__wasm_call_ctors --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-if-defined=fflush --export-table -z stack-size=65536 --no-growable-memory --initial-heap=16777216 --no-entry --stack-first --table-base=1' failed (returned 1)

Looks at lib_memory.o it looks like there is something odd about it:

$ wasm-objdump -h tmp/cs101_bcr.o 

cs101_bcr.o:	file format wasm 0x1
00017c7: error: multiple Code sections

Sections:

     Type start=0x0000000e end=0x00000027 (size=0x00000019) count: 4
   Import start=0x0000002d end=0x00000082 (size=0x00000055) count: 4
 Function start=0x00000088 end=0x00000095 (size=0x0000000d) count: 12
     Code start=0x0000009b end=0x000007ad (size=0x00000712) count: 12
   Custom start=0x000007b3 end=0x0000087a (size=0x000000c7) ".debug_abbrev"
   Custom start=0x00000880 end=0x00000bc6 (size=0x00000346) ".debug_info"
   Custom start=0x00000bcc end=0x00000c42 (size=0x00000076) ".debug_ranges"
   Custom start=0x00000c48 end=0x00000f01 (size=0x000002b9) ".debug_str"
   Custom start=0x00000f07 end=0x0000128c (size=0x00000385) ".debug_line"
   Custom start=0x00001292 end=0x0000145a (size=0x000001c8) "linking"
   Custom start=0x00001460 end=0x000014c7 (size=0x00000067) "reloc.CODE"
   Custom start=0x000014cd end=0x0000165a (size=0x0000018d) "reloc..debug_info"
   Custom start=0x00001660 end=0x000016e2 (size=0x00000082) "reloc..debug_ranges"
   Custom start=0x000016e8 end=0x00001738 (size=0x00000050) "reloc..debug_line"
   Custom start=0x0000173e end=0x00001776 (size=0x00000038) "producers"
   Custom start=0x0000177c end=0x000017c5 (size=0x00000049) "target_features"

See error: multiple Code sections.

sbc100 avatar Jan 02 '25 23:01 sbc100

$ wasm-validate  tmp/cs101_bcr.o 
00017c7: error: multiple Code sections

sbc100 avatar Jan 02 '25 23:01 sbc100