minimal-bootstrap.musl: Support x86_64-linux

We now build tinycc-musl through an intermediate stage.
BEFORE:
tinycc-mes (links to mes-libc) -> musl -> tinycc-musl (links to musl)
NOW:
tinycc-mes (links to mes-libc) -> musl-intermediate
  -> tinycc-musl-intermediate -> musl -> tinycc-musl

This fixes some issues with handling floating-point numbers:
certain float routines are not implemented are not implemented in mes-libc,
which would cause a miscompiled musl in the old approach.

Certain unnecessary musl patches are dropped. It is especially important to
remove the weak symbol patch, which in fact breaks the build.

tinycc-musl is upgraded to the latest "mob" version, with a couple bugfixes.
This commit is contained in:
Aleksi Hannula
2025-12-09 15:46:30 +02:00
parent 42d26b0984
commit 60cbef83e0
4 changed files with 64 additions and 27 deletions
@@ -75,7 +75,7 @@ lib.makeScope
gawk-mes = callPackage ./gawk/mes.nix {
bash = bash_2_05;
tinycc = tinycc-bootstrappable;
tinycc = tinycc-mes;
gnused = gnused-mes;
};
@@ -183,11 +183,16 @@ lib.makeScope
mes = callPackage ./mes { };
mes-libc = callPackage ./mes/libc.nix { };
musl11 = callPackage ./musl/1.1.nix {
musl11-intermediate = callPackage ./musl/1.1.nix {
bash = bash_2_05;
tinycc = tinycc-mes;
gnused = gnused-mes;
};
musl11 = callPackage ./musl/1.1.nix {
bash = bash_2_05;
tinycc = tinycc-musl-intermediate;
gnused = gnused-mes;
};
musl = callPackage ./musl {
gcc = gcc46;
@@ -205,10 +210,18 @@ lib.makeScope
tinycc-bootstrappable = lib.recurseIntoAttrs (callPackage ./tinycc/bootstrappable.nix { });
tinycc-mes = lib.recurseIntoAttrs (callPackage ./tinycc/mes.nix { });
tinycc-musl-intermediate = lib.recurseIntoAttrs (
callPackage ./tinycc/musl.nix {
bash = bash_2_05;
musl = musl11-intermediate;
tinycc = tinycc-mes;
}
);
tinycc-musl = lib.recurseIntoAttrs (
callPackage ./tinycc/musl.nix {
bash = bash_2_05;
musl = musl11;
tinycc = tinycc-musl-intermediate;
}
);
@@ -34,18 +34,6 @@ let
url = "${liveBootstrap}/patches/avoid_sys_clone.patch";
hash = "sha256-/ZmH64J57MmbxdfQ4RNjamAiBdkImMTlHsHdgV4gMj4=";
})
(fetchurl {
url = "${liveBootstrap}/patches/fenv.patch";
hash = "sha256-vMVGjoN4deAJW5gsSqA207SJqAbvhrnOsGK49DdEiTI=";
})
(fetchurl {
url = "${liveBootstrap}/patches/makefile.patch";
hash = "sha256-03iYBAUnsrEdLIIhhhq5mM6BGnPn2EfUmIHu51opxbw=";
})
(fetchurl {
url = "${liveBootstrap}/patches/musl_weak_symbols.patch";
hash = "sha256-/d9a2eUkpe9uyi1ye6T4CiYc9MR3FZ9na0Gb90+g4v0=";
})
(fetchurl {
url = "${liveBootstrap}/patches/set_thread_area.patch";
hash = "sha256-RIZYqbbRSx4X/0iFUhriwwBRmoXVR295GNBUjf2UrM0=";
@@ -58,6 +46,7 @@ let
# to avoid `error: implicit declaration of function '__stdio_exit'`
# Required to fix buffered stdout being truncated on exit
./stdio_flush_on_exit.patch
./avoid_pthread_x86_64.patch
(fetchurl {
url = "${liveBootstrap}/patches/va_list.patch";
hash = "sha256-UmcMIl+YCi3wIeVvjbsCyqFlkyYsM4ECNwTfXP+s7vg=";
@@ -99,6 +88,11 @@ bash.runCommand "${pname}-${version}"
sed -i 's|execl("/bin/sh", "sh", "-c",|execlp("sh", "-c",|'\
src/misc/wordexp.c
# @PLT specifier is not supported by tinycc.
# Calls do go through PLT regardless.
sed -i 's|@PLT||' src/math/x86_64/expl.s
sed -i 's|@PLT||' src/signal/x86_64/sigsetjmp.s
# Configure
bash ./configure \
--prefix=$out \
@@ -0,0 +1,16 @@
diff --git arch/x86_64/pthread_arch.h arch/x86_64/pthread_arch.h
index 65e880c..91b4a63 100644
--- arch/x86_64/pthread_arch.h
+++ arch/x86_64/pthread_arch.h
@@ -1,8 +1,8 @@
+extern pthread_t g_pthread;
+
static inline struct pthread *__pthread_self()
{
- struct pthread *self;
- __asm__ ("mov %%fs:0,%0" : "=r" (self) );
- return self;
+ return g_pthread;
}
#define TP_ADJ(p) (p)
@@ -2,26 +2,31 @@
lib,
fetchurl,
bash,
tinycc-bootstrappable,
tinycc,
musl,
gnupatch,
gnutar,
gzip,
buildPlatform,
}:
let
pname = "tinycc-musl";
# next commit introduces use of realpath (unsupported in mes-libc)
version = "unstable-2023-07-31";
rev = "fd6d2180c5c801bb0b4c5dde27d61503059fc97d";
version = "unstable-2025-12-03";
rev = "cb41cbfe717e4c00d7bb70035cda5ee5f0ff9341";
src = fetchurl {
url = "https://repo.or.cz/tinycc.git/snapshot/${rev}.tar.gz";
hash = "sha256-R81SNbEmh4s9FNQxCWZwUiMCYRkkwOHAdRf0aMnnRiA=";
hash = "sha256-MRuqq3TKcfIahtUWdhAcYhqDiGPkAjS8UTMsDE+/jGU=";
};
tccTarget =
{
i686-linux = "I386";
x86_64-linux = "X86_64";
}
.${buildPlatform.system};
patches = [
./ignore-duplicate-symbols.patch
./ignore-static-inside-array.patch
./static-link.patch
];
@@ -30,7 +35,10 @@ let
homepage = "https://repo.or.cz/w/tinycc.git";
license = lib.licenses.lgpl21Only;
teams = [ lib.teams.minimal-bootstrap ];
platforms = [ "i686-linux" ];
platforms = [
"i686-linux"
"x86_64-linux"
];
};
tinycc-musl =
@@ -39,7 +47,7 @@ let
inherit pname version meta;
nativeBuildInputs = [
tinycc-bootstrappable.compiler
tinycc.compiler
gnupatch
gnutar
gzip
@@ -52,6 +60,10 @@ let
# Patch
${lib.concatMapStringsSep "\n" (f: "patch -Np0 -i ${f}") patches}
replace --file i386-asm.c --output i386-asm.c --match-on "switch(size)" --replace-with "if (reg >= 8) { cstr_printf(add_str, \"%%r%d%c\", reg, (size == 1) ? 'b' : ((size == 2) ? 'w' : ((size == 4) ? 'd' : ' '))); return; } switch(size)"
# If performing ptr + (-1) for example, the offset should be ptrdiff_t and not size_t
replace --file tccgen.c --output tccgen.c --match-on "vpush_type_size(pointed_type(&vtop[-1].type), &align);" --replace-with "vpush_type_size(pointed_type(&vtop[-1].type), &align); if (!(vtop[-1].type.t & VT_UNSIGNED)) gen_cast_s(VT_PTRDIFF_T);"
# Configure
touch config.h
@@ -62,7 +74,7 @@ let
ln -s ${musl}/lib/libtcc1.a ./libtcc1.a
tcc \
-B ${tinycc-bootstrappable.libs}/lib \
-B ${tinycc.libs}/lib \
-DC2STR \
-o c2str \
conftest.c
@@ -71,7 +83,7 @@ let
tcc -v \
-static \
-o tcc-musl \
-D TCC_TARGET_I386=1 \
-D TCC_TARGET_${tccTarget}=1 \
-D CONFIG_TCCDIR=\"\" \
-D CONFIG_TCC_CRTPREFIX=\"{B}\" \
-D CONFIG_TCC_ELFINTERP=\"/musl/loader\" \
@@ -86,8 +98,9 @@ let
-D TCC_MUSL=1 \
-D CONFIG_TCC_PREDEFS=1 \
-D CONFIG_TCC_SEMLOCK=0 \
-D CONFIG_TCC_BACKTRACE=0 \
-B . \
-B ${tinycc-bootstrappable.libs}/lib \
-B ${tinycc.libs}/lib \
tcc.c
# libtcc1.a
rm -f libtcc1.a
@@ -99,7 +112,7 @@ let
-v \
-static \
-o tcc-musl \
-D TCC_TARGET_I386=1 \
-D TCC_TARGET_${tccTarget}=1 \
-D CONFIG_TCCDIR=\"\" \
-D CONFIG_TCC_CRTPREFIX=\"{B}\" \
-D CONFIG_TCC_ELFINTERP=\"/musl/loader\" \
@@ -114,6 +127,7 @@ let
-D TCC_MUSL=1 \
-D CONFIG_TCC_PREDEFS=1 \
-D CONFIG_TCC_SEMLOCK=0 \
-D CONFIG_TCC_BACKTRACE=0 \
-B . \
-B ${musl}/lib \
tcc.c