From 43c7708b85681a2fd4451c8a541af4494a8919b2 Mon Sep 17 00:00:00 2001 From: Stefan Date: Sat, 3 Oct 2026 18:05:49 +0200 Subject: [PATCH] tccelf: Fix static linking with musl MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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=/include:{B}/include' \ '--libpaths={B}:/lib' \ '--crtprefix=/lib' \ '--tcc-switches=-static' make -j make test … ------------ hello-exe ------------ tcc: error: unresolved reference to 'abort' --- tccelf.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tccelf.c b/tccelf.c index def5aebc..9e2d1364 100644 --- a/tccelf.c +++ b/tccelf.c @@ -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);