From e9d38658eac1f6ccabeafd3cc560020b098402c7 Mon Sep 17 00:00:00 2001 From: diviocity Date: Mon, 30 Nov 2026 14:52:41 +0100 Subject: [PATCH] Retain native GCC build objects between package retries --- BOOTSTRAP.md | 4 + gcc/PKGBUILD.vile | 156 ++++++++++++++++++++++++++++++++++ tests/toolchain/Makefile | 39 +++++++++ tests/toolchain/graphite.c | 6 ++ tests/toolchain/optimizers.c | 19 +++++ tests/toolchain/transaction.c | 28 ++++++ 6 files changed, 252 insertions(+) create mode 100644 gcc/PKGBUILD.vile create mode 100644 tests/toolchain/Makefile create mode 100644 tests/toolchain/graphite.c create mode 100644 tests/toolchain/optimizers.c create mode 100644 tests/toolchain/transaction.c diff --git a/BOOTSTRAP.md b/BOOTSTRAP.md index 4afa5e9..00b4ea0 100644 --- a/BOOTSTRAP.md +++ b/BOOTSTRAP.md @@ -13,6 +13,10 @@ Build the ports outside the source checkout. Keep a separate SDK and package dat The order above describes dependencies. The signed feed receipt, clean-install log, file-ownership check and guest transcript record how far a particular build got. Keep these records beside the package archives, outside Git. +The GCC worker keeps its prepared sources and objects at a fixed absolute path with `VINIX_GCC_BUILD_DIR`. Reuse that path with the same recipe, SDK and build tools under the compile lock. With `VINIX_GCC_LOCAL_SOURCE=1`, the recipe verifies the pinned checksum of `gcc-14.2.0.tar.xz` beside `PKGBUILD.vile`. The preparation fixture reopened the same tree from a new vpac work directory, verified the original files and rejected changed recipe bytes. See `gnu/gcc-checkpoints/recipe-retry-01`, receipt SHA-256 `d266107ef72538e53f35c06f96d97f445e35b70ae8f8b1886db2611867cff01d`. + +The x86_64 `libitm` preflight built the static archive and the musl shared library with SONAME `libitm.so.1` against the signed GCC SDK. An independent recursive make test verified that the explicit `CXX_FOR_TARGET` argument reached the child make. These checks precede the complete compiler package and its native guest test. See `gnu/libitm-preflight-01` and `gnu/libitm-recursive-make-01`, receipt SHA-256 `adbd88a897d4c1528fbcabd72b5508d99aaf6fe93cd6e26e6095d0b85d2381ce` and `c58525cb90de735cc0aedc6fc6de8fa3d679dcec3bc1b7b75a955bf3ddb8e25f`. + For the exact order within a source-built feed, run the following on the worker. The checker verifies each archive against the receipt from `feed publish`, reads its `.PKGINFO`, and resolves runtime, build and check dependencies including versioned providers. Its inputs are the feed and the indicated target architecture. The worker supplies `bsdtar`, ALPM's `vercmp` and Python 3.11 or later. ```sh diff --git a/gcc/PKGBUILD.vile b/gcc/PKGBUILD.vile new file mode 100644 index 0000000..faa6ddf --- /dev/null +++ b/gcc/PKGBUILD.vile @@ -0,0 +1,156 @@ +; The build machine needs a working musl C++17 compiler. CXXFLAGS and LDFLAGS +; may point at that compiler's C++ headers and runtime for this first stage. +; A native bootstrap builds the target runtime with the new compiler. A +; cross bootstrap needs an existing build-machine compiler for the target. +host-arch := if memq(string->symbol("aarch64"), features()) { "aarch64" } else { "x86_64" } +selected := get-environment-variable("VPAC_TARGET_ARCH") +arch := if string?(selected) { selected } else { host-arch } +triplet := string-append(arch, "-linux-musl") +cross := not(string=?(arch, host-arch)) +libc := if string=?(arch, "aarch64") { "musl>=1.2.6-4" } else { "musl" } + +; Makefiles keep absolute paths. A worker retry can keep the prepared source +; and objects in the same dedicated directory. +checkpoint := get-environment-variable("VINIX_GCC_BUILD_DIR") +persistent := if string?(checkpoint) { not(string=?("", checkpoint)) } else { #f } +checkpoint-recipe := if persistent { string-append(checkpoint, "/recipe.vile") } else { "" } +cached := if persistent { file-exists?(checkpoint-recipe) } else { #f } +build-dir := fn() { if persistent { checkpoint } else { srcdir() } } +local-archive := get-environment-variable("VINIX_GCC_LOCAL_SOURCE") +source-archive := if equal?("1", local-archive) { + "gcc-14.2.0.tar.xz" +} else { + "https://distfiles.alpinelinux.org/distfiles/v3.21/gcc-14.2.0.tar.xz" +} + +itm-compiler := fn() { + if cross { "CXX_FOR_TARGET=vinix-c++" } + else { + build := build-dir() + cxx := string-append(build, "/", triplet, "/libstdc++-v3") + string-append("CXX_FOR_TARGET=", build, "/gcc/xg++ -B", build, "/gcc/ -nostdinc++", + " -isystem ", cxx, "/include/", triplet, " -isystem ", cxx, "/include", + " -isystem ", build, "/gcc-14.2.0/libstdc++-v3/libsupc++", + " -L", cxx, "/src/.libs -L", cxx, "/libsupc++/.libs") + } +} + +defpkgbuild(gcc, + #:pkgname, "gcc", + #:pkgver, "14.2.0", + #:pkgrel, 1, + #:pkgdesc, "GNU C and C++ compilers, headers and development libraries for Vinix", + #:arch, [#:x86-64, #:aarch64], + #:url, "https://gcc.gnu.org/", + #:license, ["GPL-3.0-or-later", "GPL-3.0-or-later WITH GCC-exception-3.1"], + #:depends, list(libc, if string=?(arch, "aarch64") { "gcc-libs=14.2.0-2" } else { "gcc-libs=14.2.0-1" }, + "gmp", "mpfr", "mpc", "isl25", "zlib", "binutils"), + #:provides, ["g++=14.2.0", "libstdc++-dev=14.2.0"], + #:makedepends, ["make", "linux-headers"], + #:source, if cached { list() } else { list(source-archive) }, + #:sha256sums, if cached { list() } else { ["a7b39bc69cbf9e25826c5a60ab26477001f7c08d85cec04bc0e29cabed6f3cc9"] }, + #:prepare, fn() { + if cached { + run("cmp", string-append(startdir(), "/PKGBUILD.vile"), checkpoint-recipe) + run("test", "-x", string-append(build-dir(), "/gcc-14.2.0/configure")) + } else { + ; Serialize the two memory-intensive instruction-table generators. + run("sed", "-i", "$a s-automata: s-attrtab", "gcc-14.2.0/gcc/Makefile.in") + ; Match the library directory used by Vinix's musl loader. + if string=?(arch, "x86_64") { + run("sed", "-i", "s|m64=../lib64|m64=../lib|", "gcc-14.2.0/gcc/config/i386/t-linux64") + } else { + run("sed", "-i", "s|mabi.lp64=../lib64|mabi.lp64=../lib|", "gcc-14.2.0/gcc/config/aarch64/t-aarch64-linux") + ; This default also applies when GCC drives an alternate GNU linker. + run("sed", "-i", "s|^#define LINK_SPEC LINUX_TARGET_LINK_SPEC|#define LINK_SPEC \"-z max-page-size=16384 -z common-page-size=16384 \" LINUX_TARGET_LINK_SPEC|", + "gcc-14.2.0/gcc/config/aarch64/aarch64-linux.h") + } + if persistent { + run("mkdir", checkpoint) + run("mv", "gcc-14.2.0", checkpoint) + run("cp", string-append(startdir(), "/PKGBUILD.vile"), checkpoint-recipe) + } + } + }, + #:build, fn() { + root := get-environment-variable("VPAC_MAKEPKG_ROOT") + binutils := if cross { get-environment-variable("VINIX_GCC_BUILD_TOOLS") } else { string-append(root, "/usr/bin") } + run("test", "-x", string-append(binutils, "/as")) + run("test", "-x", string-append(binutils, "/ld")) + target-tools := if cross { + list("CC_FOR_BUILD=gcc", "CXX_FOR_BUILD=g++", "CFLAGS_FOR_BUILD=-O2 -g0", "CXXFLAGS_FOR_BUILD=-O2 -g0", "LDFLAGS_FOR_BUILD=", + "AR_FOR_BUILD=ar", "RANLIB_FOR_BUILD=ranlib", + string-append("AR=", binutils, "/ar"), string-append("AS=", binutils, "/as"), + string-append("LD=", binutils, "/ld"), string-append("NM=", binutils, "/nm"), + string-append("RANLIB=", binutils, "/ranlib"), string-append("STRIP=", binutils, "/strip"), + "CC_FOR_TARGET=vinix-cc", "GCC_FOR_TARGET=vinix-cc", "CXX_FOR_TARGET=vinix-c++", "RAW_CXX_FOR_TARGET=vinix-c++", + string-append("AR_FOR_TARGET=", binutils, "/ar"), + string-append("AS_FOR_TARGET=", binutils, "/as"), string-append("LD_FOR_TARGET=", binutils, "/ld"), + string-append("NM_FOR_TARGET=", binutils, "/nm"), string-append("RANLIB_FOR_TARGET=", binutils, "/ranlib")) + } else { list() } + build-option := if cross { list() } else { list(string-append("--build=", triplet)) } + configured := string-append(build-dir(), "/.vinix-configured") + if not(file-exists?(configured)) { + apply(run, append(list("sh", "-ec", "cd \"$1\"; shift; exec \"$@\"", "gcc-configure", build-dir(), + "env", "CC=vinix-cc", "CXX=vinix-c++", "CC_FOR_BUILD=gcc", "CXX_FOR_BUILD=g++", + "CFLAGS=-O1 -g0", "CFLAGS_FOR_TARGET=-O2 -g0", "CXXFLAGS_FOR_TARGET=-O2 -g0"), target-tools, + list("gcc-14.2.0/configure", "--prefix=/usr", "--libdir=/usr/lib"), build-option, + list(string-append("--host=", triplet), string-append("--target=", triplet), "--enable-languages=c,c++", "--disable-bootstrap", + "--with-sysroot=/", string-append("--with-build-sysroot=", root), "--with-native-system-header-dir=/usr/include", + string-append("--with-build-time-tools=", binutils), + string-append("--with-gmp=", root, "/usr"), string-append("--with-mpfr=", root, "/usr"), string-append("--with-mpc=", root, "/usr"), + string-append("--with-isl=", root, "/usr"), "--with-system-zlib", "--without-zstd", "--disable-multilib", "--disable-nls", + "--disable-libsanitizer", "--disable-libvtv", "--disable-libquadmath", "--enable-libgomp", "--enable-libatomic", "--enable-libitm", + "--disable-libstdcxx-pch", "--enable-libcc1", "--enable-lto", "--enable-plugin", "--enable-threads=posix", + "--enable-shared", "--enable-default-pie", "--enable-default-ssp", "--enable-initfini-array"))) + run("touch", configured) + } + apply(run, append(list("make", "-C", build-dir(), "GENERATOR_CFLAGS=-O2 -g0"), target-tools, + list("all-gcc", "all-libcc1", "all-lto-plugin", "all-target-libgcc", "all-target-libstdc++-v3", + "all-target-libatomic", "all-target-libgomp"))) + ; Pass a concrete command to libitm's recursive make. The standard + ; CXX_FOR_TARGET recipe expands a shell command to find the C++ headers. + apply(run, append(list("make", "-C", build-dir(), itm-compiler()), target-tools, list("all-target-libitm"))) + }, + #:check, fn() { + driver := string-append(build-dir(), "/gcc/xgcc") + binaries := string-append("-B", build-dir(), "/gcc/") + if cross { + runtime := string-append(build-dir(), "/", triplet) + libraries := string-append(runtime, "/libstdc++-v3/src/.libs:", runtime, "/libgcc") + run("vinix-run", "--library-path", libraries, driver, binaries, "-dumpmachine") + } else { + run(driver, binaries, "-dumpmachine") + } + }, + #:package, fn() { + run("make", "-C", build-dir(), string-append("DESTDIR=", pkgdir()), "install-gcc", "install-libcc1", "install-lto-plugin", "install-target-libgcc", + "install-target-libstdc++-v3", "install-target-libatomic", "install-target-libgomp") + run("make", "-C", build-dir(), string-append("DESTDIR=", pkgdir()), itm-compiler(), "install-target-libitm") + ; The versioned shared objects are owned by gcc-libs. Keep the unversioned + ; linker entries, static archives and headers here. + for-each(fn(lib) { + files := glob(string-append(pkgdir(), "/usr/lib/", lib, ".so.[0-9]*")) + run("test", "-f", car(files)) + for-each(fn(file) { run("rm", file) }, files) + }, list("libgcc_s", "libstdc++", "libatomic", "libgomp")) + for-each(fn(la) { run("rm", la) }, glob(string-append(pkgdir(), "/usr/lib/*.la"))) + run("ln", "-s", "gcc", string-append(pkgdir(), "/usr/bin/cc")) + for-each(fn(standard) { + path := string-append(pkgdir(), "/usr/bin/", standard) + compatible := if string=?(standard, "c89") { "-ansi|-std=iso9899:1990" } else { "-std=iso9899:1999" } + call-with-output-file(path, fn(port) { + display(string-append("#!/bin/sh\nfor arg do\n case \"$arg\" in\n -std=", standard, "|", compatible, + ") ;;\n -std=*) echo \"", standard, ": incompatible C standard: $arg\" >&2; exit 1 ;;\n esac\ndone\nexec /usr/bin/gcc -std=", + standard, " \"$@\"\n"), port) + }) + run("chmod", "755", path) + }, list("c89", "c99")) + plugin := string-append("libexec/gcc/", triplet, "/14.2.0/liblto_plugin.so") + run("test", "-f", string-append(pkgdir(), "/usr/", plugin)) + run("mkdir", "-p", string-append(pkgdir(), "/usr/lib/bfd-plugins")) + run("ln", "-s", string-append("../../", plugin), string-append(pkgdir(), "/usr/lib/bfd-plugins/liblto_plugin.so")) + run("rm", "-f", string-append(pkgdir(), "/usr/share/info/dir")) + run("install", "-Dm644", string-append(build-dir(), "/gcc-14.2.0/COPYING3"), string-append(pkgdir(), "/usr/share/licenses/gcc/COPYING3")) + run("install", "-Dm644", string-append(build-dir(), "/gcc-14.2.0/COPYING.RUNTIME"), string-append(pkgdir(), "/usr/share/licenses/gcc/COPYING.RUNTIME")) + }) diff --git a/tests/toolchain/Makefile b/tests/toolchain/Makefile new file mode 100644 index 0000000..f542d4c --- /dev/null +++ b/tests/toolchain/Makefile @@ -0,0 +1,39 @@ +.PHONY: check +check: arithmetic exceptions parallel graphite optimizers transaction + printf '\n' | c99 -dM -E - | grep -Fx '#define __STDC_VERSION__ 199901L' + printf '\n' | c89 -dM -E - >c89-macros + if grep -q __STDC_VERSION__ c89-macros; then exit 1; fi + if c89 -std=c99 -v >/dev/null 2>&1; then exit 1; fi + ./arithmetic + ./exceptions + ./parallel + ./graphite + ./optimizers + ./transaction + readelf -d transaction | grep -F '[libitm.so.1]' + grep -Eq 'number of SCoPs: [1-9]|SCoP statistics' graphite.dump + +arithmetic: arithmetic.c + $(CC) -std=c17 -Wall -Wextra -o $@ $< -lmpc -lmpfr -lgmp + +exceptions: exceptions.cc + $(CXX) -std=c++17 -Wall -Wextra -o $@ $< + +parallel: parallel.c + $(CC) -std=gnu17 -Wall -Wextra -fopenmp -o $@ $< -latomic + +transaction: transaction.c + $(CC) -std=gnu17 -Wall -Wextra -fgnu-tm -pthread -o $@ $< + +graphite.o: graphite.c + $(CC) -O2 -fgraphite-identity -fdump-tree-graphite-details=graphite.dump -c -o $@ $< + +graphite: optimizers.c graphite.o + $(CC) -O2 -o $@ $^ + +libgraphite.a: graphite.c + $(CC) -O2 -flto -fno-fat-lto-objects -c -o graphite-lto.o $< + $(AR) rcs $@ graphite-lto.o + +optimizers: optimizers.c libgraphite.a + $(CC) -O2 -flto -o $@ $^ diff --git a/tests/toolchain/graphite.c b/tests/toolchain/graphite.c new file mode 100644 index 0000000..96ad053 --- /dev/null +++ b/tests/toolchain/graphite.c @@ -0,0 +1,6 @@ +void fill_rows(int grid[32][32], int step) +{ + for (int row = 0; row < 32; ++row) + for (int col = 1; col < 32; ++col) + grid[row][col] = grid[row][col - 1] + step; +} diff --git a/tests/toolchain/optimizers.c b/tests/toolchain/optimizers.c new file mode 100644 index 0000000..201af4d --- /dev/null +++ b/tests/toolchain/optimizers.c @@ -0,0 +1,19 @@ +#include + +void fill_rows(int grid[32][32], int step); + +int main(int argc, char **argv) +{ + int grid[32][32]; + int step = argc + 2; + (void)argv; + for (int row = 0; row < 32; ++row) + grid[row][0] = row; + fill_rows(grid, step); + for (int row = 0; row < 32; ++row) + for (int col = 0; col < 32; ++col) + if (grid[row][col] != row + col * step) + return 1; + puts("Vinix optimized loop passed"); + return 0; +} diff --git a/tests/toolchain/transaction.c b/tests/toolchain/transaction.c new file mode 100644 index 0000000..b2ff6a0 --- /dev/null +++ b/tests/toolchain/transaction.c @@ -0,0 +1,28 @@ +#include +#include + +enum { iterations = 64 }; +static int total; + +static void *increment(void *unused) +{ + (void)unused; + for (int i = 0; i < iterations; ++i) { + __transaction_atomic { + ++total; + } + } + return NULL; +} + +int main(void) +{ + pthread_t thread; + if (pthread_create(&thread, NULL, increment, NULL) != 0) + return 1; + increment(NULL); + if (pthread_join(thread, NULL) != 0) + return 1; + printf("transaction total %d\n", total); + return total != 2 * iterations; +} -- 2.56.1