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

Most upvoted comments

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.