Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PRINTF_LONG_DOUBLE is not compatible with MAIN_MODULE #22102

Open
allsey87 opened this issue Jun 17, 2024 · 6 comments
Open

PRINTF_LONG_DOUBLE is not compatible with MAIN_MODULE #22102

allsey87 opened this issue Jun 17, 2024 · 6 comments

Comments

@allsey87
Copy link

Version of emscripten/emsdk:

root@576256f6896e:/src# emcc -v
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.61 (67fa4c16496b157a7fc3377afd69ee0445e8a6e3)
clang version 19.0.0git (https:/github.com/llvm/llvm-project 7cfffe74eeb68fbb3fb9706ac7071f8caeeb6520)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /emsdk/upstream/bin

Failing command line in full:
emcc test.c -sPRINTF_LONG_DOUBLE=1 -sMAIN_MODULE

Contents of test.c:

#include <stdio.h>

int main() {
    printf("Hello, World!");
    return 0;
}

Full link command and output with -v appended:

root@576256f6896e:/src# emcc test.c -sPRINTF_LONG_DOUBLE=1 -sMAIN_MODULE -v
 /emsdk/upstream/bin/clang -target wasm32-unknown-emscripten -fignore-exceptions -fPIC -fvisibility=default -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr --sysroot=/emsdk/upstream/emscripten/cache/sysroot -DEMSCRIPTEN -Werror=implicit-function-declaration -Xclang -iwithsysroot/include/fakesdl -Xclang -iwithsysroot/include/compat -v test.c -c -o /tmp/emscripten_temp_pbobb795/test_0.o
clang version 19.0.0git (https:/github.com/llvm/llvm-project 7cfffe74eeb68fbb3fb9706ac7071f8caeeb6520)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /emsdk/upstream/bin
 (in-process)
 "/emsdk/upstream/bin/clang-19" -cc1 -triple wasm32-unknown-emscripten -emit-obj -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name test.c -mrelocation-model pic -pic-level 2 -mframe-pointer=none -ffp-contract=on -fno-rounding-math -mconstructor-aliases -target-feature +mutable-globals -target-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/src -v -fcoverage-compilation-dir=/src -resource-dir /emsdk/upstream/lib/clang/19 -D EMSCRIPTEN -isysroot /emsdk/upstream/emscripten/cache/sysroot -internal-isystem /emsdk/upstream/lib/clang/19/include -internal-isystem /emsdk/upstream/emscripten/cache/sysroot/include/wasm32-emscripten -internal-isystem /emsdk/upstream/emscripten/cache/sysroot/include -Werror=implicit-function-declaration -ferror-limit 19 -fvisibility=default -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -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_pbobb795/test_0.o -x c test.c
clang -cc1 version 19.0.0git based upon LLVM 19.0.0git default target x86_64-unknown-linux-gnu
ignoring nonexistent directory "/emsdk/upstream/emscripten/cache/sysroot/include/wasm32-emscripten"
#include "..." search starts here:
#include <...> search starts here:
 /emsdk/upstream/emscripten/cache/sysroot/include/fakesdl
 /emsdk/upstream/emscripten/cache/sysroot/include/compat
 /emsdk/upstream/lib/clang/19/include
 /emsdk/upstream/emscripten/cache/sysroot/include
End of search list.
 /emsdk/upstream/bin/clang --version
 /emsdk/upstream/bin/wasm-ld -o a.out.wasm /tmp/emscripten_temp_pbobb795/test_0.o -L/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/pic -lGL-getprocaddr -lal -lhtml5 -lprintf_long_double-debug -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 --export-if-defined=setThrew --export-if-defined=_emscripten_stack_restore --export-if-defined=emscripten_stack_get_current --export-if-defined=_emscripten_tempret_set --export-if-defined=malloc --export-if-defined=_emscripten_stack_alloc --export-if-defined=_emscripten_tempret_get --export-if-defined=htons --export-if-defined=ntohs --export-if-defined=htonl --export-if-defined=_emscripten_timeout --export-if-defined=__cxa_is_pointer_type --export-if-defined=emscripten_stack_get_base --export-if-defined=emscripten_stack_get_end --export-if-defined=free --export-if-defined=__cxa_can_catch --export-if-defined=__cxa_increment_exception_refcount --export-if-defined=__cxa_decrement_exception_refcount --export-if-defined=fileno --export-if-defined=emscripten_builtin_memalign --export-if-defined=__dl_seterr --export-if-defined=memcmp --export-if-defined=memcpy --export-if-defined=__errno_location --export-if-defined=__cxa_demangle /tmp/tmpn5vhuwbslibemscripten_js_symbols.so --import-memory --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_set_limits --export=_emscripten_stack_alloc --export=__get_temp_ret --export=__set_temp_ret --export=__wasm_call_ctors --export=setThrew --export=_emscripten_stack_restore --export=_emscripten_tempret_set --export=malloc --export=_emscripten_tempret_get --export=htons --export=ntohs --export=htonl --export=_emscripten_timeout --export=__cxa_is_pointer_type --export=free --export=__cxa_can_catch --export=__cxa_increment_exception_refcount --export=__cxa_decrement_exception_refcount --export=fileno --export=emscripten_builtin_memalign --export=__dl_seterr --export=memcmp --export=memcpy --export=__errno_location --export=__cxa_demangle --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=__wasm_apply_data_relocs --export-if-defined=fflush --experimental-pic --unresolved-symbols=import-dynamic -pie --no-export-dynamic -z stack-size=65536 --no-growable-memory --initial-memory=16777216 --no-entry --stack-first
 /emsdk/upstream/bin/wasm-ld -o a.out.wasm --whole-archive /tmp/emscripten_temp_pbobb795/test_0.o -L/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/pic -lGL-getprocaddr -lal -lhtml5 -lprintf_long_double-debug -lstubs-debug -lnoexit -lc-debug -ldlmalloc -lcompiler_rt -lc++-noexcept -lc++abi-debug-noexcept -lsockets --no-whole-archive -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr --export-if-defined=setThrew --export-if-defined=_emscripten_stack_restore --export-if-defined=emscripten_stack_get_current --export-if-defined=_emscripten_tempret_set --export-if-defined=malloc --export-if-defined=_emscripten_stack_alloc --export-if-defined=_emscripten_tempret_get --export-if-defined=htons --export-if-defined=ntohs --export-if-defined=htonl --export-if-defined=_emscripten_timeout --export-if-defined=__cxa_is_pointer_type --export-if-defined=emscripten_stack_get_base --export-if-defined=emscripten_stack_get_end --export-if-defined=free --export-if-defined=__cxa_can_catch --export-if-defined=__cxa_increment_exception_refcount --export-if-defined=__cxa_decrement_exception_refcount --export-if-defined=fileno --export-if-defined=emscripten_builtin_memalign --export-if-defined=__dl_seterr --export-if-defined=memcmp --export-if-defined=memcpy --export-if-defined=__errno_location --export-if-defined=__cxa_demangle /tmp/tmpmzhuwxfwlibemscripten_js_symbols.so --import-memory --strip-debug --export-dynamic --export=emscripten_stack_get_end --export=emscripten_stack_get_free --export=emscripten_stack_get_base --export=emscripten_stack_get_current --export=emscripten_stack_set_limits --export=_emscripten_stack_alloc --export=__get_temp_ret --export=__set_temp_ret --export=__wasm_call_ctors --export=setThrew --export=_emscripten_stack_restore --export=_emscripten_tempret_set --export=malloc --export=_emscripten_tempret_get --export=htons --export=ntohs --export=htonl --export=_emscripten_timeout --export=__cxa_is_pointer_type --export=free --export=__cxa_can_catch --export=__cxa_increment_exception_refcount --export=__cxa_decrement_exception_refcount --export=fileno --export=emscripten_builtin_memalign --export=__dl_seterr --export=memcmp --export=memcpy --export=__errno_location --export=__cxa_demangle --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=__wasm_apply_data_relocs --export-if-defined=fflush --experimental-pic --unresolved-symbols=import-dynamic -pie -z stack-size=65536 --no-growable-memory --initial-memory=16777216 --no-entry --stack-first
wasm-ld: error: duplicate symbol: __vfprintf_internal
>>> defined in /emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/pic/libprintf_long_double-debug.a(vfprintf.o)
>>> defined in /emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/pic/libc-debug.a(vfprintf.o)

wasm-ld: error: duplicate symbol: vfprintf
>>> defined in /emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/pic/libprintf_long_double-debug.a(vfprintf.o)
>>> defined in /emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/pic/libc-debug.a(vfprintf.o)

wasm-ld: error: duplicate symbol: vfiprintf
>>> defined in /emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/pic/libprintf_long_double-debug.a(vfprintf.o)
>>> defined in /emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/pic/libc-debug.a(vfprintf.o)

wasm-ld: error: duplicate symbol: __small_vfprintf
>>> defined in /emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/pic/libprintf_long_double-debug.a(vfprintf.o)
>>> defined in /emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/pic/libc-debug.a(vfprintf.o)
emcc: error: '/emsdk/upstream/bin/wasm-ld -o a.out.wasm --whole-archive /tmp/emscripten_temp_pbobb795/test_0.o -L/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/pic -lGL-getprocaddr -lal -lhtml5 -lprintf_long_double-debug -lstubs-debug -lnoexit -lc-debug -ldlmalloc -lcompiler_rt -lc++-noexcept -lc++abi-debug-noexcept -lsockets --no-whole-archive -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr --export-if-defined=setThrew --export-if-defined=_emscripten_stack_restore --export-if-defined=emscripten_stack_get_current --export-if-defined=_emscripten_tempret_set --export-if-defined=malloc --export-if-defined=_emscripten_stack_alloc --export-if-defined=_emscripten_tempret_get --export-if-defined=htons --export-if-defined=ntohs --export-if-defined=htonl --export-if-defined=_emscripten_timeout --export-if-defined=__cxa_is_pointer_type --export-if-defined=emscripten_stack_get_base --export-if-defined=emscripten_stack_get_end --export-if-defined=free --export-if-defined=__cxa_can_catch --export-if-defined=__cxa_increment_exception_refcount --export-if-defined=__cxa_decrement_exception_refcount --export-if-defined=fileno --export-if-defined=emscripten_builtin_memalign --export-if-defined=__dl_seterr --export-if-defined=memcmp --export-if-defined=memcpy --export-if-defined=__errno_location --export-if-defined=__cxa_demangle /tmp/tmpmzhuwxfwlibemscripten_js_symbols.so --import-memory --strip-debug --export-dynamic --export=emscripten_stack_get_end --export=emscripten_stack_get_free --export=emscripten_stack_get_base --export=emscripten_stack_get_current --export=emscripten_stack_set_limits --export=_emscripten_stack_alloc --export=__get_temp_ret --export=__set_temp_ret --export=__wasm_call_ctors --export=setThrew --export=_emscripten_stack_restore --export=_emscripten_tempret_set --export=malloc --export=_emscripten_tempret_get --export=htons --export=ntohs --export=htonl --export=_emscripten_timeout --export=__cxa_is_pointer_type --export=free --export=__cxa_can_catch --export=__cxa_increment_exception_refcount --export=__cxa_decrement_exception_refcount --export=fileno --export=emscripten_builtin_memalign --export=__dl_seterr --export=memcmp --export=memcpy --export=__errno_location --export=__cxa_demangle --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=__wasm_apply_data_relocs --export-if-defined=fflush --experimental-pic --unresolved-symbols=import-dynamic -pie -z stack-size=65536 --no-growable-memory --initial-memory=16777216 --no-entry --stack-first' failed (returned 1)
@sbc100
Copy link
Collaborator

sbc100 commented Jun 22, 2024

Yes, this is an issue with -sMAIN_MODULE=1.

While we should fix this issue, I would also strongly recommend against using -sMAIN_MODULE=1 since it includes all symbols from all libraries and doesn't do any dead code elimination. If you can switch to -sMAIN_MODULE=2 that would solve this issue, and give you much smaller payloads.

@allsey87
Copy link
Author

Indeed, however in this case I am compiling CPython and I think it is hard (impossible?) to know what functions will be needed by the imported modules.

@sbc100
Copy link
Collaborator

sbc100 commented Jun 23, 2024

Are you working on pyodide? Or is this a separate CPython effort?

@allsey87
Copy link
Author

A separate project that integrates CPython into a larger system

@sbc100
Copy link
Collaborator

sbc100 commented Jun 23, 2024

If possible I would strongly advise against using -sMAIN_MODULE=2 and instead trying to come up with some sore of reasonable subset of symbols that your side modules have access to. I assume that dynamically loading side modules is hard requirement for you?

Fixing this particular issue is kind of pain due to the way that -sMAIN_MODULE wraps everything in -Wl,--whole-archive. I'll see if we can some up with reasonable fix though.

@allsey87
Copy link
Author

So I don't need this issue fixed for my project, I am reporting it more because perhaps someone else can save themselves 5-10 minutes by just googling "emscripten __vfprintf_internal duplicate symbol" or something like that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants