Skip to content

Duplicate symbol error emitted,when I use libiconv with -sMAIN_MODULE=1 (version:2.0.0) #11985

Open

Description

@ucanudo

the error list:

wasm-ld: error: duplicate symbol: __ctype_get_mb_cur_max
>>> defined in ../../lib/bitcode/libiconv.so
>>> defined in /opt/emsdk/upstream/emscripten/cache/wasm-pic/libc.a(__ctype_get_mb_cur_max.o)

wasm-ld: error: duplicate symbol: __errno_location
>>> defined in ../../lib/bitcode/libiconv.so
>>> defined in /opt/emsdk/upstream/emscripten/cache/wasm-pic/libc.a(__errno_location.o)

wasm-ld: error: duplicate symbol: __progname
>>> defined in ../../lib/bitcode/libiconv.so
>>> defined in /opt/emsdk/upstream/emscripten/cache/wasm-pic/libc.a(libc.o)

wasm-ld: error: duplicate symbol: __progname_full
>>> defined in ../../lib/bitcode/libiconv.so
>>> defined in /opt/emsdk/upstream/emscripten/cache/wasm-pic/libc.a(libc.o)

wasm-ld: error: duplicate symbol: __libc
>>> defined in ../../lib/bitcode/libiconv.so
>>> defined in /opt/emsdk/upstream/emscripten/cache/wasm-pic/libc.a(libc.o)

wasm-ld: error: duplicate symbol: __hwcap
>>> defined in ../../lib/bitcode/libiconv.so
>>> defined in /opt/emsdk/upstream/emscripten/cache/wasm-pic/libc.a(libc.o)

wasm-ld: error: duplicate symbol: __sysinfo
>>> defined in ../../lib/bitcode/libiconv.so
>>> defined in /opt/emsdk/upstream/emscripten/cache/wasm-pic/libc.a(libc.o)

wasm-ld: error: duplicate symbol: __lctrans
>>> defined in ../../lib/bitcode/libiconv.so
>>> defined in /opt/emsdk/upstream/emscripten/cache/wasm-pic/libc.a(__lctrans.o)

wasm-ld: error: duplicate symbol: __lctrans_cur
>>> defined in ../../lib/bitcode/libiconv.so
>>> defined in /opt/emsdk/upstream/emscripten/cache/wasm-pic/libc.a(__lctrans.o)

wasm-ld: error: duplicate symbol: __nl_langinfo_l
>>> defined in ../../lib/bitcode/libiconv.so
>>> defined in /opt/emsdk/upstream/emscripten/cache/wasm-pic/libc.a(langinfo.o)

wasm-ld: error: duplicate symbol: __nl_langinfo
>>> defined in ../../lib/bitcode/libiconv.so
>>> defined in /opt/emsdk/u  (You can run make with `VEBOpstream/emscripten/cache/wasm-pic/libc.a(langinfo.o)

wasm-ld: error: duplicate symbol: pthread_self
>>> defined in ../../lib/bitcode/libiconv.so
>>> defined in /opt/emsdk/upstream/emscripten/cache/wasm-pic/libc.a(emscripten_pthread.o)

wasm-ld: error: duplicate symbol: __emscripten_pthread_data_constructor
>>> defined in ../../lib/bitcode/libiconv.so
>>> defined in /opt/emsdk/upstream/emscripten/cache/wasm-pic/libc.a(emscripten_pthread.o)

wasm-ld: error: duplicate symbol: __fsmu8
>>> defined in ../../lib/bitcode/libiconv.so
>>> defined in /opt/emsdk/upstream/emscripten/cache/wasm-pic/libc.a(internal.o)

wasm-ld: error: duplicate symbol: mbrtowc
>>> defined in ../../lib/bitcode/libiconv.so
>>> defined in /opt/emsdk/upstream/emscripten/cache/wasm-pic/libc.a(mbrtowc.o)

libiconv.so:
is compiled used emconfigure ./configure, version is 1.16.0

However, when set -sMAIN_MODULE=0 ,everything is ok!

Can you help me to solve this ploblem? I want to use dynamic link in my main program. but i do not know how to solve the porblem.

Activity

  1. sbc100 commented on Aug 21, 2020

    @sbc100
    Collaborator

    It looks like your "shared library" contains the contents of libc.a.. normally this doesn't matter since the linker will ignore the second copy of libc.a.

    However, one of the side effects of -s MAIN_MODULE=1 is that the whole link command get wrapped in --whole-archive which force libc.a to be included a second time.

    Your best bet is to configure and build without shared libraries and use static libraries instead. i.e. you should be linking against libiconv.a. I believe the --disable-shared argument to configure will do this.

  2. sbc100 commented on Aug 21, 2020

    @sbc100
    Collaborator

    Basically it seems the MAIN_MODULE is not compaitble with out pseudo .so files.

  3. RReverser commented on Jun 7, 2021

    @RReverser
    Collaborator

    I think I'm running into the same issue with gphoto2.

    wasm-ld: error: duplicate symbol: strcmp
    >>> defined in ../libgphoto2_port/.libs/libgphoto2_port.so
    >>> defined in /usr/local/google/home/rreverser/libtool-2.4.6/installed/lib/libltdl.so
    
    wasm-ld: error: duplicate symbol: strrchr
    >>> defined in ../libgphoto2_port/.libs/libgphoto2_port.so
    >>> defined in /usr/local/google/home/rreverser/libtool-2.4.6/installed/lib/libltdl.so
    
    wasm-ld: error: duplicate symbol: strncmp
    >>> defined in ../libgphoto2_port/.libs/libgphoto2_port.so
    >>> defined in /usr/local/google/home/rreverser/libtool-2.4.6/installed/lib/libltdl.so
    
    wasm-ld: error: duplicate symbol: getenv
    >>> defined in ../libgphoto2_port/.libs/libgphoto2_port.so
    >>> defined in /usr/local/google/home/rreverser/libtool-2.4.6/installed/lib/libltdl.so
    
    wasm-ld: error: duplicate symbol: opendir
    >>> defined in ../libgphoto2_port/.libs/libgphoto2_port.so
    >>> defined in /usr/local/google/home/rreverser/libtool-2.4.6/installed/lib/libltdl.so
    
    wasm-ld: error: duplicate symbol: readdir
    >>> defined in ../libgphoto2_port/.libs/libgphoto2_port.so
    >>> defined in /usr/local/google/home/rreverser/libtool-2.4.6/installed/lib/libltdl.so
    
    wasm-ld: error: duplicate symbol: closedir
    >>> defined in ../libgphoto2_port/.libs/libgphoto2_port.so
    >>> defined in /usr/local/google/home/rreverser/libtool-2.4.6/installed/lib/libltdl.so
    
    wasm-ld: error: duplicate symbol: open
    >>> defined in ../libgphoto2_port/.libs/libgphoto2_port.so
    >>> defined in /usr/local/google/home/rreverser/libtool-2.4.6/installed/lib/libltdl.so
    
    wasm-ld: error: duplicate symbol: memchr
    >>> defined in ../libgphoto2_port/.libs/libgphoto2_port.so
    >>> defined in /usr/local/google/home/rreverser/libtool-2.4.6/installed/lib/libltdl.so
    
    wasm-ld: error: duplicate symbol: strchr
    >>> defined in ../libgphoto2_port/.libs/libgphoto2_port.so
    >>> defined in /usr/local/google/home/rreverser/libtool-2.4.6/installed/lib/libltdl.so
    
    wasm-ld: error: duplicate symbol: __errno_location
    >>> defined in ../libgphoto2_port/.libs/libgphoto2_port.so
    >>> defined in /usr/local/google/home/rreverser/libtool-2.4.6/installed/lib/libltdl.so
    
    wasm-ld: error: duplicate symbol: __syscall_ret
    >>> defined in ../libgphoto2_port/.libs/libgphoto2_port.so
    >>> defined in /usr/local/google/home/rreverser/libtool-2.4.6/installed/lib/libltdl.so
    
    wasm-ld: error: duplicate symbol: __lock
    >>> defined in ../libgphoto2_port/.libs/libgphoto2_port.so
    >>> defined in /usr/local/google/home/rreverser/libtool-2.4.6/installed/lib/libltdl.so
    
    wasm-ld: error: duplicate symbol: __unlock
    >>> defined in ../libgphoto2_port/.libs/libgphoto2_port.so
    >>> defined in /usr/local/google/home/rreverser/libtool-2.4.6/installed/lib/libltdl.so
    
    wasm-ld: error: duplicate symbol: vsnprintf
    >>> defined in ../libgphoto2_port/.libs/libgphoto2_port.so
    >>> defined in /usr/local/google/home/rreverser/libtool-2.4.6/installed/lib/libltdl.so
    
    wasm-ld: error: duplicate symbol: vsniprintf
    >>> defined in ../libgphoto2_port/.libs/libgphoto2_port.so
    >>> defined in /usr/local/google/home/rreverser/libtool-2.4.6/installed/lib/libltdl.so
    
    wasm-ld: error: duplicate symbol: __small_vsnprintf
    >>> defined in ../libgphoto2_port/.libs/libgphoto2_port.so
    >>> defined in /usr/local/google/home/rreverser/libtool-2.4.6/installed/lib/libltdl.so
    
    wasm-ld: error: duplicate symbol: vfprintf
    >>> defined in ../libgphoto2_port/.libs/libgphoto2_port.so
    >>> defined in /usr/local/google/home/rreverser/libtool-2.4.6/installed/lib/libltdl.so
    
    wasm-ld: error: duplicate symbol: vfiprintf
    >>> defined in ../libgphoto2_port/.libs/libgphoto2_port.so
    >>> defined in /usr/local/google/home/rreverser/libtool-2.4.6/installed/lib/libltdl.so
    
    wasm-ld: error: duplicate symbol: __small_vfprintf
    >>> defined in ../libgphoto2_port/.libs/libgphoto2_port.so
    >>> defined in /usr/local/google/home/rreverser/libtool-2.4.6/installed/lib/libltdl.so
    
    wasm-ld: error: too many errors emitted, stopping now (use -error-limit=0 to see all errors)
    

    In this case using static libraries is not an option, because it heavily depends on libltdl to load modules dynamically.

    Strangely, -sMAIN_MODULE=0 tip from the issue description did let it compile but I'm yet to check what this means for runtime (I suppose it wouldn't be able to load side modules?).

  4. sbc100 commented on Jun 7, 2021

    @sbc100
    Collaborator

    I'm curious to see the full link commands used for libgphoto2_port.so and libltdl.so in the failing case. Can you include those if are able to reproduce again?

    From the error message it looks like libgphoto2_port.so and libltdl.so are both actually single object files (not actually side modules). Its is important to distinguish bettween actual shared libraries (side modules) and the intermediate static objects that emscripten produces when you build with -shared. In neither case should we be including libc.a (strcmp etc) so there is clearly a bug here.

  5. RReverser commented on Jun 7, 2021

    @RReverser
    Collaborator

    From the error message it looks like libgphoto2_port.so and libltdl.so are both actually single object files (not actually side modules).

    Perhaps I need to clean & recompile them with explicit LDFLAGS='-s SIDE_MODULE=1'? I thought building shared .so would do that automatically, but I don't know much about autoconf / emmake / make integration.

    Let me try again and I'll share the commands.

  6. RReverser commented on Jun 7, 2021

    @RReverser
    Collaborator

    Yeah -s SIDE_MODULE=1 doesn't seem to help. This is what I used:

    $ emmake make install LDFLAGS='-s SIDE_MODULE=1'

    For gphoto I used (last iteration):

    emconfigure ./configure LIBLTDL='-lltdl' LTDLINCL='-I(...libtool "install" dir...)/include/ -L(...libtool "install" dir...)/lib/' --host=wasm32
    emmake make CPPFLAGS='-I(...libtool "install" dir...)/include/' LDFLAGS='-L(...libtool "install" dir...)/lib/ -s MAIN_MODULE=1' CFLAGS='-s MAIN_MODULE=1'
  7. RReverser commented on Jun 7, 2021

    @RReverser
    Collaborator

    Ah, sorry, forgot to add. The actual link command that fails looks like this:

    /usr/local/google/home/rreverser/emsdk/upstream/emscripten/emcc -s MAIN_MODULE=1 -s MAIN_MODULE=1 -o test-gp-port test_gp_port-test-gp-port.o  ../libgphoto2_port/.libs/libgphoto2_port.a -L/usr/local/google/home/rreverser/libtool-2.4.6/installed/lib /usr/local/google/home/rreverser/libtool-2.4.6/installed/lib/libltdl.so -lpthread -Wl,-rpath -Wl,/usr/local/google/home/rreverser/libtool-2.4.6/installed/lib -Wl,-rpath -Wl,/usr/local/google/home/rreverser/libtool-2.4.6/installed/lib
    
  8. sbc100 commented on Jun 7, 2021

    @sbc100
    Collaborator

    The link command that produced /usr/local/google/home/rreverser/libtool-2.4.6/installed/lib/libltdl.so would be really useful too.

  9. RReverser commented on Jun 7, 2021

    @RReverser
    Collaborator

    Hm, looks like it's generated by make -> libtool -> .so, and I'm not sure yet how to get it to show the final command...

  10. sbc100 commented on Jun 7, 2021

    @sbc100
    Collaborator

    If you remove the file (perhaps remove libltdl.*) and then run make again it should print the full command by default. If not, the libtool command is fine too.

  11. RReverser commented on Jun 8, 2021

    @RReverser
    Collaborator

    It still didn't print the full command, but in the end I found that I can get libltdl to emit a static library, and use it in gphoto. It's the libs that gphoto uses with libltdl that have to be dynamic and... I'm running into the same issues with those. Except this time I can't just change them to be static libraries.

    Luckily, this Makefile prints full commands:

    libtool: link: /usr/local/google/home/rreverser/emsdk/upstream/emscripten/emcc -g -O2 -Wall -Wextra -Wno-unused-parameter -Wno-format-overflow -Wno-format-truncation -Wno-stringop-truncation -Wall -Wmissing-declarations -Wmissing-prototypes -o .libs/print-libgphoto2-version print-libgphoto2-version.o  ../libgphoto2/.libs/libgphoto2.so ../libgphoto2_port/libgphoto2_port/.libs/libgphoto2_port.so /usr/local/google/home/rreverser/libtool-2.4.6/installed/lib/libltdl.a -lm
    wasm-ld: error: duplicate symbol: bind_textdomain_codeset
    >>> defined in ../libgphoto2/.libs/libgphoto2.so
    >>> defined in ../libgphoto2_port/libgphoto2_port/.libs/libgphoto2_port.so
    
    wasm-ld: error: duplicate symbol: bindtextdomain
    >>> defined in ../libgphoto2/.libs/libgphoto2.so
    >>> defined in ../libgphoto2_port/libgphoto2_port/.libs/libgphoto2_port.so
    
    wasm-ld: error: duplicate symbol: getenv
    >>> defined in ../libgphoto2/.libs/libgphoto2.so
    >>> defined in ../libgphoto2_port/libgphoto2_port/.libs/libgphoto2_port.so
    
    wasm-ld: error: duplicate symbol: strcmp
    >>> defined in ../libgphoto2/.libs/libgphoto2.so
    >>> defined in ../libgphoto2_port/libgphoto2_port/.libs/libgphoto2_port.so
    
    wasm-ld: error: duplicate symbol: dgettext
    >>> defined in ../libgphoto2/.libs/libgphoto2.so
    >>> defined in ../libgphoto2_port/libgphoto2_port/.libs/libgphoto2_port.so
    
    wasm-ld: error: duplicate symbol: strrchr
    >>> defined in ../libgphoto2/.libs/libgphoto2.so
    >>> defined in ../libgphoto2_port/libgphoto2_port/.libs/libgphoto2_port.so
    
    wasm-ld: error: duplicate symbol: snprintf
    >>> defined in ../libgphoto2/.libs/libgphoto2.so
    >>> defined in ../libgphoto2_port/libgphoto2_port/.libs/libgphoto2_port.so
    
    wasm-ld: error: duplicate symbol: vsnprintf
    >>> defined in ../libgphoto2/.libs/libgphoto2.so
    >>> defined in ../libgphoto2_port/libgphoto2_port/.libs/libgphoto2_port.so
    
    wasm-ld: error: duplicate symbol: strchr
    >>> defined in ../libgphoto2/.libs/libgphoto2.so
    >>> defined in ../libgphoto2_port/libgphoto2_port/.libs/libgphoto2_port.so
    
    wasm-ld: error: duplicate symbol: strncpy
    >>> defined in ../libgphoto2/.libs/libgphoto2.so
    >>> defined in ../libgphoto2_port/libgphoto2_port/.libs/libgphoto2_port.so
    
    wasm-ld: error: duplicate symbol: opendir
    >>> defined in ../libgphoto2/.libs/libgphoto2.so
    >>> defined in ../libgphoto2_port/libgphoto2_port/.libs/libgphoto2_port.so
    
    wasm-ld: error: duplicate symbol: readdir
    >>> defined in ../libgphoto2/.libs/libgphoto2.so
    >>> defined in ../libgphoto2_port/libgphoto2_port/.libs/libgphoto2_port.so
    
    wasm-ld: error: duplicate symbol: closedir
    >>> defined in ../libgphoto2/.libs/libgphoto2.so
    >>> defined in ../libgphoto2_port/libgphoto2_port/.libs/libgphoto2_port.so
    
    wasm-ld: error: duplicate symbol: stat
    >>> defined in ../libgphoto2/.libs/libgphoto2.so
    >>> defined in ../libgphoto2_port/libgphoto2_port/.libs/libgphoto2_port.so
    
    wasm-ld: error: duplicate symbol: __syscall_ret
    >>> defined in ../libgphoto2/.libs/libgphoto2.so
    >>> defined in ../libgphoto2_port/libgphoto2_port/.libs/libgphoto2_port.so
    
    wasm-ld: error: duplicate symbol: open
    >>> defined in ../libgphoto2/.libs/libgphoto2.so
    >>> defined in ../libgphoto2_port/libgphoto2_port/.libs/libgphoto2_port.so
    
    wasm-ld: error: duplicate symbol: __lctrans_cur
    >>> defined in ../libgphoto2/.libs/libgphoto2.so
    >>> defined in ../libgphoto2_port/libgphoto2_port/.libs/libgphoto2_port.so
    
    wasm-ld: error: duplicate symbol: qsort
    >>> defined in ../libgphoto2/.libs/libgphoto2.so
    >>> defined in ../libgphoto2_port/libgphoto2_port/.libs/libgphoto2_port.so
    
    wasm-ld: error: duplicate symbol: isdigit
    >>> defined in ../libgphoto2/.libs/libgphoto2.so
    >>> defined in ../libgphoto2_port/libgphoto2_port/.libs/libgphoto2_port.so
    
    wasm-ld: error: duplicate symbol: strncmp
    >>> defined in ../libgphoto2/.libs/libgphoto2.so
    >>> defined in ../libgphoto2_port/libgphoto2_port/.libs/libgphoto2_port.so
    
    wasm-ld: error: too many errors emitted, stopping now (use -error-limit=0 to see all errors)
    emcc: error: '/usr/local/google/home/rreverser/emsdk/upstream/bin/wasm-ld -o .libs/print-libgphoto2-version.wasm print-libgphoto2-version.o ../libgphoto2/.libs/libgphoto2.so ../libgphoto2_port/libgphoto2_port/.libs/libgphoto2_port.so /usr/local/google/home/rreverser/libtool-2.4.6/installed/lib/libltdl.a -L/usr/local/google/home/rreverser/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten /usr/local/google/home/rreverser/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/libgl.a /usr/local/google/home/rreverser/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/libal.a /usr/local/google/home/rreverser/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/libhtml5.a /usr/local/google/home/rreverser/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/libc.a /usr/local/google/home/rreverser/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/libcompiler_rt.a /usr/local/google/home/rreverser/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/libc++-noexcept.a /usr/local/google/home/rreverser/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/libc++abi-noexcept.a /usr/local/google/home/rreverser/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/libdlmalloc.a /usr/local/google/home/rreverser/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/libc_rt_wasm.a /usr/local/google/home/rreverser/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/libsockets.a -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr --allow-undefined --export main --export stackSave --export stackRestore --export stackAlloc --export __wasm_call_ctors --export __errno_location --export malloc --export free --export-if-defined=__start_em_asm --export-if-defined=__stop_em_asm --export-table -z stack-size=5242880 --initial-memory=16777216 --no-entry --max-memory=16777216 --global-base=1024' failed (returned 1)
    

    In this build I haven't added SIDE_MODULE / MAIN_MODULE yet as it would require very careful review of the build system to add them in the right places... I wonder if one of those approaches could work:

    1. Assume SIDE_MODULE when something is built with -shared on the Emscripten side. Is there any reason it doesn't? In theory, that would be closest to proper shared libs.
    2. Could we tell wasm-ld to just ignore duplicate symbols somehow, so that linking would behave sort of like it does for .a archives - that is, only one symbol wins when two .sos happened to link in the same library?
  12. RReverser commented on Jun 8, 2021

    @RReverser
    Collaborator

    If I add SIDE_MODULE, then I still get conflict like above but between different libs (libgphoto2_port.so and libltdl.a instead of libgphoto2_port.so and libgphoto2.so):

    /bin/sh ../libtool  --tag=CC   --mode=link /usr/local/google/home/rreverser/emsdk/upstream/emscripten/emcc  -s SIDE_MODULE=1 ../libgphoto2_port/libgphoto2_port.la /usr/local/google/home/rreverser/libtool-2.4.6/installed/lib/libltdl.a  -s SIDE_MODULE=1 -o test-gp-port test_gp_port-test-gp-port.o  -lpthread 
    libtool: link: /usr/local/google/home/rreverser/emsdk/upstream/emscripten/emcc -s SIDE_MODULE=1 -s SIDE_MODULE=1 -o .libs/test-gp-port test_gp_port-test-gp-port.o  ../libgphoto2_port/.libs/libgphoto2_port.so /usr/local/google/home/rreverser/libtool-2.4.6/installed/lib/libltdl.a -lpthread
    wasm-ld: error: duplicate symbol: preopen_LTX_get_vtable
    >>> defined in ../libgphoto2_port/.libs/libgphoto2_port.so
    >>> defined in /usr/local/google/home/rreverser/libtool-2.4.6/installed/lib/libltdl.a(libltdl_libltdl_la-preopen.o)
    
    wasm-ld: error: duplicate symbol: lt_dlpreload_default
    >>> defined in ../libgphoto2_port/.libs/libgphoto2_port.so
    >>> defined in /usr/local/google/home/rreverser/libtool-2.4.6/installed/lib/libltdl.a(libltdl_libltdl_la-preopen.o)
    
    wasm-ld: error: duplicate symbol: lt_dlpreload
    >>> defined in ../libgphoto2_port/.libs/libgphoto2_port.so
    >>> defined in /usr/local/google/home/rreverser/libtool-2.4.6/installed/lib/libltdl.a(libltdl_libltdl_la-preopen.o)
    
    wasm-ld: error: duplicate symbol: lt_dlpreload_open
    >>> defined in ../libgphoto2_port/.libs/libgphoto2_port.so
    >>> defined in /usr/local/google/home/rreverser/libtool-2.4.6/installed/lib/libltdl.a(libltdl_libltdl_la-preopen.o)
    
    wasm-ld: error: duplicate symbol: lt__malloc
    >>> defined in ../libgphoto2_port/.libs/libgphoto2_port.so
    >>> defined in /usr/local/google/home/rreverser/libtool-2.4.6/installed/lib/libltdl.a(libltdl_libltdl_la-lt__alloc.o)
    
    wasm-ld: error: duplicate symbol: lt__alloc_die
    >>> defined in ../libgphoto2_port/.libs/libgphoto2_port.so
    >>> defined in /usr/local/google/home/rreverser/libtool-2.4.6/installed/lib/libltdl.a(libltdl_libltdl_la-lt__alloc.o)
    
    wasm-ld: error: duplicate symbol: lt__zalloc
    >>> defined in ../libgphoto2_port/.libs/libgphoto2_port.so
    >>> defined in /usr/local/google/home/rreverser/libtool-2.4.6/installed/lib/libltdl.a(libltdl_libltdl_la-lt__alloc.o)
    
    wasm-ld: error: duplicate symbol: lt__realloc
    >>> defined in ../libgphoto2_port/.libs/libgphoto2_port.so
    >>> defined in /usr/local/google/home/rreverser/libtool-2.4.6/installed/lib/libltdl.a(libltdl_libltdl_la-lt__alloc.o)
    
    wasm-ld: error: duplicate symbol: lt__memdup
    >>> defined in ../libgphoto2_port/.libs/libgphoto2_port.so
    >>> defined in /usr/local/google/home/rreverser/libtool-2.4.6/installed/lib/libltdl.a(libltdl_libltdl_la-lt__alloc.o)
    
    wasm-ld: error: duplicate symbol: lt__strdup
    >>> defined in ../libgphoto2_port/.libs/libgphoto2_port.so
    >>> defined in /usr/local/google/home/rreverser/libtool-2.4.6/installed/lib/libltdl.a(libltdl_libltdl_la-lt__alloc.o)
    
    wasm-ld: error: duplicate symbol: lt_dlloader_add
    >>> defined in ../libgphoto2_port/.libs/libgphoto2_port.so
    >>> defined in /usr/local/google/home/rreverser/libtool-2.4.6/installed/lib/libltdl.a(libltdl_libltdl_la-lt_dlloader.o)
    
    wasm-ld: error: duplicate symbol: lt_dlloader_next
    >>> defined in ../libgphoto2_port/.libs/libgphoto2_port.so
    >>> defined in /usr/local/google/home/rreverser/libtool-2.4.6/installed/lib/libltdl.a(libltdl_libltdl_la-lt_dlloader.o)
    
    wasm-ld: error: duplicate symbol: lt_dlloader_get
    >>> defined in ../libgphoto2_port/.libs/libgphoto2_port.so
    >>> defined in /usr/local/google/home/rreverser/libtool-2.4.6/installed/lib/libltdl.a(libltdl_libltdl_la-lt_dlloader.o)
    
    wasm-ld: error: duplicate symbol: lt_dlloader_remove
    >>> defined in ../libgphoto2_port/.libs/libgphoto2_port.so
    >>> defined in /usr/local/google/home/rreverser/libtool-2.4.6/installed/lib/libltdl.a(libltdl_libltdl_la-lt_dlloader.o)
    
    wasm-ld: error: duplicate symbol: lt_dlloader_find
    >>> defined in ../libgphoto2_port/.libs/libgphoto2_port.so
    >>> defined in /usr/local/google/home/rreverser/libtool-2.4.6/installed/lib/libltdl.a(libltdl_libltdl_la-lt_dlloader.o)
    
    wasm-ld: error: duplicate symbol: lt_dladderror
    >>> defined in ../libgphoto2_port/.libs/libgphoto2_port.so
    >>> defined in /usr/local/google/home/rreverser/libtool-2.4.6/installed/lib/libltdl.a(libltdl_libltdl_la-lt_error.o)
    
    wasm-ld: error: duplicate symbol: lt_dlseterror
    >>> defined in ../libgphoto2_port/.libs/libgphoto2_port.so
    >>> defined in /usr/local/google/home/rreverser/libtool-2.4.6/installed/lib/libltdl.a(libltdl_libltdl_la-lt_error.o)
    
    wasm-ld: error: duplicate symbol: lt__set_last_error
    >>> defined in ../libgphoto2_port/.libs/libgphoto2_port.so
    >>> defined in /usr/local/google/home/rreverser/libtool-2.4.6/installed/lib/libltdl.a(libltdl_libltdl_la-lt_error.o)
    
    wasm-ld: error: duplicate symbol: lt__error_string
    >>> defined in ../libgphoto2_port/.libs/libgphoto2_port.so
    >>> defined in /usr/local/google/home/rreverser/libtool-2.4.6/installed/lib/libltdl.a(libltdl_libltdl_la-lt_error.o)
    
    wasm-ld: error: duplicate symbol: lt__get_last_error
    >>> defined in ../libgphoto2_port/.libs/libgphoto2_port.so
    >>> defined in /usr/local/google/home/rreverser/libtool-2.4.6/installed/lib/libltdl.a(libltdl_libltdl_la-lt_error.o)
    
    wasm-ld: error: too many errors emitted, stopping now (use -error-limit=0 to see all errors)
    
  13. hedwiggggg commented on Sep 5, 2021

    @hedwiggggg

    Sorry, this is a little bit offtopic, but I wanted to ask, if someone of you managed to port libgphoto2 to webassembly? I would love to be able to use libgphoto2 as wasm in nodejs without writing a node native addon. It seems to be possible at least (https://github.com/odejesush/webusb-wasm-libgphoto2) but unfortunately there are no instructions and i am a bloody beginner in the C world. Maybe one of you can help me, that would be great.

    @sbc100 @RReverser @ucanudo

  14. RReverser commented on Sep 5, 2021

    @RReverser
    Collaborator

    Sorry, this is a little bit offtopic, but I wanted to ask, if someone of you managed to port libgphoto2 to webassembly?

    Stay tuned, I'm going to write something up soon-ish :)

    UPD: For other looking for this - it's up now. https://web.dev/porting-libusb-to-webusb/

  15. pepijndevos commented on Jan 21, 2022

    @pepijndevos

    I'm running into what seems to be the same bug in capnproto:

    emconfigure ./configure
    emmake make
    

    omitting most of the build, it ends like so

    libtool: compile:  /usr/lib/emscripten/em++ -DHAVE_CONFIG_H -I. -I./src -I./src -DKJ_HEADER_WARNINGS -DCAPNP_HEADER_WARNINGS -DCAPNP_INCLUDE_DIR=\"/usr/local/include\" -O2 -DNDEBUG -MT src/capnp/compat/json.capnp.lo -MD -MP -MF src/capnp/compat/.deps/json.capnp.Tpo -c src/capnp/compat/json.capnp.c++  -fPIC -DPIC -o src/capnp/compat/.libs/json.capnp.o
    libtool: compile:  /usr/lib/emscripten/em++ -DHAVE_CONFIG_H -I. -I./src -I./src -DKJ_HEADER_WARNINGS -DCAPNP_HEADER_WARNINGS -DCAPNP_INCLUDE_DIR=\"/usr/local/include\" -O2 -DNDEBUG -MT src/capnp/compat/json.capnp.lo -MD -MP -MF src/capnp/compat/.deps/json.capnp.Tpo -c src/capnp/compat/json.capnp.c++ -o src/capnp/compat/json.capnp.o >/dev/null 2>&1
    /bin/sh ./libtool  --tag=CXX   --mode=link /usr/lib/emscripten/em++ -I./src -I./src -DKJ_HEADER_WARNINGS -DCAPNP_HEADER_WARNINGS -DCAPNP_INCLUDE_DIR='"/usr/local/include"'  -O2 -DNDEBUG  -release 0.9.1 -no-undefined  -o libcapnp-json.la -rpath /usr/local/lib src/capnp/compat/json.lo src/capnp/compat/json.capnp.lo libcapnp.la libkj.la  
    libtool: link: /usr/lib/emscripten/em++  -fPIC -DPIC -shared -nostdlib   src/capnp/compat/.libs/json.o src/capnp/compat/.libs/json.capnp.o   -Wl,-rpath -Wl,/home/pepijn/code/asic/wasmsimserver/capnproto-c++-0.9.1/.libs -Wl,-rpath -Wl,/usr/local/lib ./.libs/libcapnp.so ./.libs/libkj.so -L/home/pepijn/.emscripten_cache/sysroot/lib/wasm32-emscripten -lGL -lal -lhtml5 -lstubs -lc -lcompiler_rt -lc++-noexcept -lc++abi-noexcept -ldlmalloc -lc_rt -lsockets   -O2   -Wl,-soname -Wl,libcapnp-json-0.9.1.so -o .libs/libcapnp-json-0.9.1.so
    em++: warning: linking a library with `-shared` will emit a static object file.  This is a form of emulation to support existing build systems.  If you want to build a runtime shared library use the SIDE_MODULE setting. [-Wemcc]
    em++: warning: ignoring unsupported linker flag: `-rpath` [-Wlinkflags]
    em++: warning: ignoring unsupported linker flag: `-rpath` [-Wlinkflags]
    em++: warning: ignoring unsupported linker flag: `-soname` [-Wlinkflags]
    em++: warning: ignoring dynamic library libcapnp.so because not compiling to JS or HTML, remember to link it when compiling to JS or HTML at the end [-Wemcc]
    em++: warning: ignoring dynamic library libkj.so because not compiling to JS or HTML, remember to link it when compiling to JS or HTML at the end [-Wemcc]
    libtool: link: (cd ".libs" && rm -f "libcapnp-json.so" && ln -s "libcapnp-json-0.9.1.so" "libcapnp-json.so")
    libtool: link: /usr/lib/emscripten/emar cr .libs/libcapnp-json.a  src/capnp/compat/json.o src/capnp/compat/json.capnp.o
    libtool: link: /usr/lib/emscripten/emranlib .libs/libcapnp-json.a
    libtool: link: ( cd ".libs" && rm -f "libcapnp-json.la" && ln -s "../libcapnp-json.la" "libcapnp-json.la" )
    /bin/sh ./libtool  --tag=CXX   --mode=link /usr/lib/emscripten/em++ -I./src -I./src -DKJ_HEADER_WARNINGS -DCAPNP_HEADER_WARNINGS -DCAPNP_INCLUDE_DIR='"/usr/local/include"'  -O2 -DNDEBUG    -o capnp src/capnp/compiler/module-loader.o src/capnp/compiler/capnp.o libcapnpc.la libcapnp-json.la libcapnp.la libkj.la  
    libtool: link: /usr/lib/emscripten/em++ -I./src -I./src -DKJ_HEADER_WARNINGS -DCAPNP_HEADER_WARNINGS -DCAPNP_INCLUDE_DIR=\"/usr/local/include\" -O2 -DNDEBUG -o .libs/capnp src/capnp/compiler/module-loader.o src/capnp/compiler/capnp.o  ./.libs/libcapnpc.so ./.libs/libcapnp-json.so ./.libs/libcapnp.so ./.libs/libkj.so -Wl,-rpath -Wl,/usr/local/lib
    em++: warning: ignoring unsupported linker flag: `-rpath` [-Wlinkflags]
    wasm-ld: error: duplicate symbol: memset
    >>> defined in ./.libs/libcapnpc.so
    >>> defined in ./.libs/libcapnp-json.so
    
    wasm-ld: error: duplicate symbol: strlen
    >>> defined in ./.libs/libcapnpc.so
    >>> defined in ./.libs/libcapnp-json.so
    
    wasm-ld: error: duplicate symbol: memcmp
    >>> defined in ./.libs/libcapnpc.so
    >>> defined in ./.libs/libcapnp-json.so
    
    wasm-ld: error: duplicate symbol: __cxa_pure_virtual
    >>> defined in ./.libs/libcapnpc.so
    >>> defined in ./.libs/libcapnp-json.so
    
    wasm-ld: error: duplicate symbol: vtable for __cxxabiv1::__class_type_info
    >>> defined in ./.libs/libcapnpc.so
    >>> defined in ./.libs/libcapnp-json.so
    
    wasm-ld: error: duplicate symbol: vtable for __cxxabiv1::__vmi_class_type_info
    >>> defined in ./.libs/libcapnpc.so
    >>> defined in ./.libs/libcapnp-json.so
    
    wasm-ld: error: duplicate symbol: vtable for __cxxabiv1::__si_class_type_info
    >>> defined in ./.libs/libcapnpc.so
    >>> defined in ./.libs/libcapnp-json.so
    
    wasm-ld: error: duplicate symbol: __errno_location
    >>> defined in ./.libs/libcapnpc.so
    >>> defined in ./.libs/libcapnp-json.so
    
    wasm-ld: error: duplicate symbol: emscripten_get_heap_size
    >>> defined in ./.libs/libcapnpc.so
    >>> defined in ./.libs/libcapnp-json.so
    
    wasm-ld: error: duplicate symbol: strcmp
    >>> defined in ./.libs/libcapnpc.so
    >>> defined in ./.libs/libcapnp-json.so
    
    wasm-ld: error: duplicate symbol: std::__throw_bad_alloc()
    >>> defined in ./.libs/libcapnpc.so
    >>> defined in ./.libs/libcapnp-json.so
    
    wasm-ld: error: duplicate symbol: std::get_new_handler()
    >>> defined in ./.libs/libcapnpc.so
    >>> defined in ./.libs/libcapnp-json.so
    
    wasm-ld: error: duplicate symbol: std::nothrow
    >>> defined in ./.libs/libcapnpc.so
    >>> defined in ./.libs/libcapnp-json.so
    
    wasm-ld: error: duplicate symbol: abort_message
    >>> defined in ./.libs/libcapnpc.so
    >>> defined in ./.libs/libcapnp-json.so
    
    wasm-ld: error: duplicate symbol: std::set_unexpected(void (*)())
    >>> defined in ./.libs/libcapnpc.so
    >>> defined in ./.libs/libcapnp-json.so
    
    wasm-ld: error: duplicate symbol: __cxa_unexpected_handler
    >>> defined in ./.libs/libcapnpc.so
    >>> defined in ./.libs/libcapnp-json.so
    
    wasm-ld: error: duplicate symbol: std::set_terminate(void (*)())
    >>> defined in ./.libs/libcapnpc.so
    >>> defined in ./.libs/libcapnp-json.so
    
    wasm-ld: error: duplicate symbol: __cxa_terminate_handler
    >>> defined in ./.libs/libcapnpc.so
    >>> defined in ./.libs/libcapnp-json.so
    
    wasm-ld: error: duplicate symbol: std::get_unexpected()
    >>> defined in ./.libs/libcapnpc.so
    >>> defined in ./.libs/libcapnp-json.so
    
    wasm-ld: error: duplicate symbol: std::__unexpected(void (*)())
    >>> defined in ./.libs/libcapnpc.so
    >>> defined in ./.libs/libcapnp-json.so
    
    wasm-ld: error: too many errors emitted, stopping now (use -error-limit=0 to see all errors)
    em++: error: '/opt/emscripten-llvm/bin/wasm-ld -o .libs/capnp.wasm src/capnp/compiler/module-loader.o src/capnp/compiler/capnp.o ./.libs/libcapnpc.so ./.libs/libcapnp-json.so ./.libs/libcapnp.so ./.libs/libkj.so -L/home/pepijn/.emscripten_cache/sysroot/lib/wasm32-emscripten -lGL -lal -lhtml5 -lstubs -lnoexit -lc -lcompiler_rt -lc++-noexcept -lc++abi-noexcept -ldlmalloc -lc_rt -lsockets -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr --import-undefined --strip-debug --export-if-defined=main --export-if-defined=__start_em_asm --export-if-defined=__stop_em_asm --export=stackSave --export=stackRestore --export=stackAlloc --export=__wasm_call_ctors --export=__errno_location --export=malloc --export-table -z stack-size=5242880 --initial-memory=16777216 --no-entry --max-memory=16777216 --global-base=1024' failed (returned 1)
    make: *** [Makefile:1924: capnp] Error 1
    emmake: error: 'make' failed (returned 2)
    
    
  16. sbc100 commented on Jan 21, 2022

    @sbc100
    Collaborator

    The problem is that these shared libraries are actually just object files : https://emscripten.org/docs/compiling/Building-Projects.html#faux-dynamic-linking

    If you like libc and libc++ into those object you will get duplicate symbols. Do you know how this arguments ended up the link line: -lstubs -lc -lcompiler_rt -lc++-noexcept -lc++abi-noexcept -ldlmalloc -lc_rt -lsockets for your shared objects? If you can remove those I think it could solve you issue.

    Better still, can you disable dynamic libraries completely and just use static libraries? Passing --disable-shared to configure might be enough to do this.

  17. pepijndevos commented on Jan 22, 2022

    @pepijndevos

    So is it working as intended, or is it indeed a bug for libc symbols to get into the build?

    --disable-shared actually seemed to help. Now I'm getting missing symbol errors instead.
    All of them originate in libkj's exception stuff. I tried building with -fno-rtti -fno-exceptions but no change.

    wasm-ld: error: /home/pepijn/code/asic/wasmsimserver/capnproto-c++-0.9.1/.libs/libkj.a(exception.o): undefined symbol: sigaltstack
    wasm-ld: error: /home/pepijn/code/asic/wasmsimserver/capnproto-c++-0.9.1/.libs/libkj.a(exception.o): undefined symbol: __cxa_get_globals
    wasm-ld: error: /home/pepijn/code/asic/wasmsimserver/capnproto-c++-0.9.1/.libs/libkj.a(exception.o): undefined symbol: __cxa_get_globals
    wasm-ld: error: /home/pepijn/code/asic/wasmsimserver/capnproto-c++-0.9.1/.libs/libkj.a(exception.o): undefined symbol: __cxa_get_globals
    wasm-ld: error: /home/pepijn/code/asic/wasmsimserver/capnproto-c++-0.9.1/.libs/libkj.a(filesystem-disk-unix.o): undefined symbol: fallocate
    
  18. sbc100 commented on Jan 22, 2022

    @sbc100
    Collaborator

    Its an artifact/side-effect/bug due to the way we do fake dyanmic libraries. Normally its not an issue because libc won't be included .. but your build seems to be explicitly asking for libc to be included by adding -lc on the command line (note that most programs should never need to add -lc explicitly.. unless they are doing something like -nostdlib). We could ignore the request to explicitly include libc and other system libraries when building fake shared libraries... but honestly --disable-shared is the far better solution in this case.

  19. sbc100 commented on Jan 22, 2022

    @sbc100
    Collaborator

    Regarding the missing symbols:

    • sigaltstack: Emscripten doesn't have any support for this today. We could possible add some kind of dummy/stub implementation but it would be better if you could avoid depending on it. Does capnproto have some kind of way to avoid this? HAVE_SIGNALSTACK?
    • fallocate: It looks like we currently only support posix_fallocate although it looks like we could easily add support for fallocate by just adding this file to our libc build (its currently excluded): https://github.com/emscripten-core/emscripten/blob/main/system/lib/libc/musl/src/linux/fallocate.c
    • __cxa_get_globals: I'm not sure about this one .. I would need to take a look at exception.o and see why it might be referencing that symbol. I've not previously seen that symbol being referenced out side of libc++abi itself.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions