tccelf: Fix static linking with musl
Some checks failed
build and test / test-x86_64-linux (push) Has been cancelled
build and test / test-x86_64-osx (push) Has been cancelled
build and test / test-aarch64-osx (push) Has been cancelled
build and test / test-x86_64-win32 (push) Has been cancelled
build and test / test-i386-win32 (push) Has been cancelled
build and test / test-arm64-win32 (push) Has been cancelled
build and test / test-armv7-linux (push) Has been cancelled
build and test / test-aarch64-linux (push) Has been cancelled
build and test / test-riscv64-linux (push) Has been cancelled
build and test / test-i386-linux (push) Has been cancelled

tccelf.c:
- tcc_add_runtime()
    Add a second tcc_add_library(s1, "c"). The libtcc1.a references at
    least abort() from the C library. After libtcc1.a the libc.a needs
    to be linked again to resolve abort(). For similar reasons gcc
    passes --start-group -lgcc -lc --end-group to the linker.

    This solves:

    ./configure '--sysincludepaths=<musl>/include:{B}/include' \
                '--libpaths={B}:<musl>/lib' \
                '--crtprefix=<musl>/lib' \
                '--tcc-switches=-static'
    make -j
    make test
    …
    ------------ hello-exe ------------
    tcc: error: unresolved reference to 'abort'
This commit is contained in:
Stefan 2026-10-03 18:05:49 +02:00
parent 9db1105c32
commit 43c7708b85

View File

@ -1873,8 +1873,10 @@ ST_FUNC void tcc_add_runtime(TCCState *s1)
#if defined TCC_TARGET_ARM && TARGETOS_FreeBSD
tcc_add_library(s1, "gcc_s"); // unwind code
#endif
if (TCC_LIBTCC1[0])
if (TCC_LIBTCC1[0]) {
tcc_add_support(s1, TCC_LIBTCC1);
tcc_add_library(s1, "c");
}
#ifndef TCC_TARGET_MACHO
if (s1->output_type != TCC_OUTPUT_MEMORY)
tccelf_add_crtend(s1);