tpoechtrager / osxcross

Mac OS X cross toolchain for Linux, FreeBSD, OpenBSD and Android (Termux)
GNU General Public License v2.0
2.8k stars 318 forks source link

Can't pass -Wl,--allow-multiple-definition #397

Closed alucryd closed 9 months ago

alucryd commented 9 months ago

To anyone building rust static libs, they all come with redundant symbols which is a huge pain for the linker... With GCC, and even android's clang and lld I can pass -Wl,--allow-multiple-definition, however this flag doesn't seem to be supported by the osxcross toolchain. I also tried -Wl,-Xlink=-force:multiple but that didn't work either. Is there a way to achieve this using osxcross?

Without the flag:

duplicate symbol '___rust_foreign_exception' in:
    /home/embybuilder/Buildbot/armv8_osx/staging/lib/librav1e.a(std-2ca50e2550a11ed4.std.64f42f12-cgu.0.rcgu.o)
    /home/embybuilder/Buildbot/armv8_osx/libimagequant-armv8_osx/staging/lib/libimagequant.a(std-f6811f31090e0239.std.add96b74-cgu.0.rcgu.o)
duplicate symbol '_rust_begin_unwind' in:
    /home/embybuilder/Buildbot/armv8_osx/staging/lib/librav1e.a(std-2ca50e2550a11ed4.std.64f42f12-cgu.0.rcgu.o)
    /home/embybuilder/Buildbot/armv8_osx/libimagequant-armv8_osx/staging/lib/libimagequant.a(std-f6811f31090e0239.std.add96b74-cgu.0.rcgu.o)
duplicate symbol '___rdl_alloc_zeroed' in:
    /home/embybuilder/Buildbot/armv8_osx/staging/lib/librav1e.a(std-2ca50e2550a11ed4.std.64f42f12-cgu.0.rcgu.o)
    /home/embybuilder/Buildbot/armv8_osx/libimagequant-armv8_osx/staging/lib/libimagequant.a(std-f6811f31090e0239.std.add96b74-cgu.0.rcgu.o)
duplicate symbol '___rdl_realloc' in:
    /home/embybuilder/Buildbot/armv8_osx/staging/lib/librav1e.a(std-2ca50e2550a11ed4.std.64f42f12-cgu.0.rcgu.o)
    /home/embybuilder/Buildbot/armv8_osx/libimagequant-armv8_osx/staging/lib/libimagequant.a(std-f6811f31090e0239.std.add96b74-cgu.0.rcgu.o)
duplicate symbol '___rdl_dealloc' in:
    /home/embybuilder/Buildbot/armv8_osx/staging/lib/librav1e.a(std-2ca50e2550a11ed4.std.64f42f12-cgu.0.rcgu.o)
    /home/embybuilder/Buildbot/armv8_osx/libimagequant-armv8_osx/staging/lib/libimagequant.a(std-f6811f31090e0239.std.add96b74-cgu.0.rcgu.o)
duplicate symbol '___rdl_alloc' in:
    /home/embybuilder/Buildbot/armv8_osx/staging/lib/librav1e.a(std-2ca50e2550a11ed4.std.64f42f12-cgu.0.rcgu.o)
    /home/embybuilder/Buildbot/armv8_osx/libimagequant-armv8_osx/staging/lib/libimagequant.a(std-f6811f31090e0239.std.add96b74-cgu.0.rcgu.o)
duplicate symbol '_rust_panic' in:
    /home/embybuilder/Buildbot/armv8_osx/staging/lib/librav1e.a(std-2ca50e2550a11ed4.std.64f42f12-cgu.0.rcgu.o)
    /home/embybuilder/Buildbot/armv8_osx/libimagequant-armv8_osx/staging/lib/libimagequant.a(std-f6811f31090e0239.std.add96b74-cgu.0.rcgu.o)
duplicate symbol '___rust_drop_panic' in:
    /home/embybuilder/Buildbot/armv8_osx/staging/lib/librav1e.a(std-2ca50e2550a11ed4.std.64f42f12-cgu.0.rcgu.o)
    /home/embybuilder/Buildbot/armv8_osx/libimagequant-armv8_osx/staging/lib/libimagequant.a(std-f6811f31090e0239.std.add96b74-cgu.0.rcgu.o)
duplicate symbol '___rdl_oom' in:
    /home/embybuilder/Buildbot/armv8_osx/staging/lib/librav1e.a(alloc-ad1eeb16b5006415.alloc.c81d41f3-cgu.0.rcgu.o)
    /home/embybuilder/Buildbot/armv8_osx/libimagequant-armv8_osx/staging/lib/libimagequant.a(alloc-80ef5ce8d4cd7e19.alloc.157cdf10-cgu.0.rcgu.o)
duplicate symbol '___rg_oom' in:
    /home/embybuilder/Buildbot/armv8_osx/staging/lib/librav1e.a(std-2ca50e2550a11ed4.std.64f42f12-cgu.0.rcgu.o)
    /home/embybuilder/Buildbot/armv8_osx/libimagequant-armv8_osx/staging/lib/libimagequant.a(alloc-80ef5ce8d4cd7e19.alloc.157cdf10-cgu.0.rcgu.o)
ld: 10 duplicate symbols for architecture arm64
clang-15: error: linker command failed with exit code 1 (use -v to see invocation)

With the flag:

ld: unknown option: --allow-multiple-definition
clang-15: error: linker command failed with exit code 1 (use -v to see invocation)
tpoechtrager commented 9 months ago

There is probably no such option in ld64. https://github.com/tpoechtrager/cctools-port/blob/986-ld64-711/cctools/ld64/src/ld/Options.cpp#L3391

alucryd commented 9 months ago

Yeah. I didn't find anything in the ld64 manpages unfortunately. Wondering if I can use ld64.lld instead.

alucryd commented 9 months ago

No such option in ld64.lld either unfortunately. Will poke the llvm guys in case they have an idea.