mold: mold fails to build with musl libc with undefined references to getcontext, swapcontext and makecontext
hey, I tried to compile mold source code on a linux that uses musl as the libc. Its a very lean and fast alternative to the bloaty and unhealthy glibc. Here is the error, during linking:
g++-10.3.0 -DMOLD_VERSION=\"1.0.1\" -DLIBDIR="\"/usr/lib\"" -O2 -pipe -pthread -fPIE -fno-unwind-tables -fno-asynchronous-unwind-tables -std=c++20 -fno-exceptions -Wl,-O1 -Wl,--as-needed out/compress.o out/demangle.o out/filepath.o out/hyperloglog.o out/main.o out/perf.o out/tar.o out/elf/arch-arm64.o out/elf/arch-i386.o out/elf/arch-x86-64.o out/elf/cmdline.o out/elf/gc-sections.o out/elf/icf.o out/elf/input-sections.o out/elf/linker-script.o out/elf/main.o out/elf/mapfile.o out/elf/object-file.o out/elf/output-chunks.o out/elf/output-file.o out/elf/passes.o out/elf/relocatable.o out/elf/subprocess.o out/macho/arch-arm64.o out/macho/arch-x86-64.o out/macho/cmdline.o out/macho/dead-strip.o out/macho/dumper.o out/macho/input-sections.o out/macho/main.o out/macho/mapfile.o out/macho/object-file.o out/macho/output-chunks.o out/macho/output-file.o out/macho/tapi.o out/macho/yaml.o -o mold -pthread -lz -ldl -lm -lmimalloc -ltbb -lxxhash -lrt -lcrypto
/usr/lib/gcc/aarch64-gentoo-linux-musl/10.3.0/../../../../aarch64-gentoo-linux-musl/bin/ld: /usr/lib/gcc/aarch64-gentoo-linux-musl/10.3.0/../../../../lib/libtbb.so: undefined reference to `getcontext'
/usr/lib/gcc/aarch64-gentoo-linux-musl/10.3.0/../../../../aarch64-gentoo-linux-musl/bin/ld: /usr/lib/gcc/aarch64-gentoo-linux-musl/10.3.0/../../../../lib/libtbb.so: undefined reference to `swapcontext'
/usr/lib/gcc/aarch64-gentoo-linux-musl/10.3.0/../../../../aarch64-gentoo-linux-musl/bin/ld: /usr/lib/gcc/aarch64-gentoo-linux-musl/10.3.0/../../../../lib/libtbb.so: undefined reference to `makecontext'
collect2: error: ld returned 1 exit status
make: *** [Makefile:118: mold] Error 1
mold was build using these commands:
make -j1 SYSTEM_TBB=1 SYSTEM_MIMALLOC=1 SYSTEM_XXHASH=1 STRIP=true LIBDIR=/usr/lib
do you have an idea where this is coming from? is it a bug in libtbb.so?
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 50 (21 by maintainers)
Commits related to this issue
- Revert "Fix a build issue on Gentoo with musl libc" This reverts commit 2cc85cc21dbb4ee014631327e10f5ef21bad7c62 because it didn't fix the Gentoo's issue. https://github.com/rui314/mold/issues/281 — committed to rui314/mold by rui314 2 years ago
- sys-libs/libucontext: respect CFLAGS without overriding upstream define Fixes musl runtime as the right symbols get defined now (unprefixed). Bug: https://github.com/rui314/mold/issues/281 Bug: http... — committed to gentoo/gentoo by thesamesam 2 years ago
- dev-cpp/tbb: fix underlinking on musl Avoid *context APIs. In theory, may not be needed (shouldn't be) given we've fixed our packaging of libucontext, but let's do this anyway as the fix is upstream... — committed to gentoo/gentoo by thesamesam 2 years ago
- Build arm64-musl image Bug: https://github.com/rui314/mold/issues/281 Signed-off-by: Sam James <sam@gentoo.org> Signed-off-by: Alexys Jacob <ultrabug@gentoo.org> — committed to gentoo/gentoo-docker-images by thesamesam 2 years ago
- sys-devel/mold: remove use of mimalloc for musl mold is expected to be working on amd64 and arm64, and while its working out of the box for musl-amd64 it does flake on arm64: /usr/bin/mo... — committed to stefson/musl by stefson 2 years ago
Sure, let me do that before v1.1.1.
Sounds like someone forgot the -Wl,–no-undefined on TBB. I can think of a few usecases for allowing dangling links (Python modules that want to be usable in both python3.9 and python3.10, for example), but why is no-undefined not the default?
Searching for getcontext reveals the single file https://github.com/rui314/mold/blob/main/third-party/tbb/src/tbb/co_context.h. Searching for its used symbols reveals the single file https://github.com/rui314/mold/blob/main/third-party/tbb/src/tbb/task.cpp. Since it compiles correctly with static TBB, the relevant object file is clearly unused.
Proposed solution: Poke https://github.com/rui314/mold/blob/fea59750ed50a2233f13eadfdcc27880da4a6c93/third-party/tbb/include/oneapi/tbb/detail/_config.h#L271 a little. Either disable it under musl, or just hardcode it to false.