me

/

vinix-ports Public
382 commits 0 issues 0 pull requests 1 contributor Discussions Projects Snippets LOC history Platform CI

Build toolchain smoke tests inside Vinix guests

diviocity committed 5 days ago · 9ffa3525405544a1f712b1911224c0f74bea5198 View patch
Unverified signature 2 files changed +81 -0
gcc/BOOTSTRAP.md new file +58 -0

@@ -0,0 +1,58 @@

1+# Building the first native GCC

2+

3+The x86-64 native bootstrap uses a build machine that can run musl executables. The first build uses Alpine 3.21's GCC and G++ 14.2 as build tools. Install `build-base`, `bash`, `bison`, `flex`, `m4`, `perl`, `texinfo`, `curl`, `libarchive-tools` and `zstd` in the build environment. Make vpac's native builder available to the unprivileged build user.

4+

5+Mount a signed Vinix SDK at `/sdk` and its vpac database at `/sdkdb`. The initial SDK needs `musl`, `linux-headers`, `zlib`, `make`, `gmp`, `mpfr` and `mpc`. Put the repository's `vinix-cc` wrapper and its `vinix-c++` symlink on the build environment's `PATH`. The bootstrap toolchain supplies its own target assembler and linker during the runtime build. The full Binutils package links to this runtime for `dwp` and the gold linker. Commit `06d5cb5` provides the earlier C-only binutils 2.43.1-2 recipe for bringing up a new build machine.

6+

7+The first G++ needs its own C++ headers and support libraries to compile GCC. Exposing only those four library names preserves the SDK's startup files, C library and other link dependencies. The isolated builder used these paths.

8+

9+```sh

10+mkdir -p /opt/cxx-link

11+ln -s /usr/lib/libstdc++.so.6 /opt/cxx-link/libstdc++.so

12+ln -s /usr/lib/libgcc_s.so.1 /opt/cxx-link/libgcc_s.so

13+ln -s /usr/lib/libgcc_s.so.1 /opt/cxx-link/libgcc_s.so.1

14+ln -s /usr/lib/libssp_nonshared.a /opt/cxx-link/libssp_nonshared.a

15+export VPAC_MAKEPKG_ROOT=/sdk VPAC_MAKEPKG_DB=/sdkdb

16+export LD_LIBRARY_PATH=/sdk/usr/lib:/usr/lib

17+export CXXFLAGS='-O0 -g0 -isystem /usr/include/c++/14.2.0 -isystem /usr/include/c++/14.2.0/x86_64-alpine-linux-musl'

18+export LDFLAGS='-L/opt/cxx-link -Wl,-rpath-link,/opt/cxx-link'

19+export MAKEFLAGS=-j2

20+vpac --native-build /work/gcc-libs/PKGBUILD.vile /work/runtime-archive

21+```

22+

23+Publish `gcc-libs` from the runtime manifest and install it in the SDK. It supplies the versioned `libgcc_s`, `libstdc++`, `libatomic` and `libgomp` libraries. Applications that use those libraries can install this package with musl alone. The `gcc` package adds the compiler executables, C++ headers, static archives and unversioned development links.

24+

25+Verify the runtime from a second signed root containing just `musl` and `gcc-libs`. Point `runtime` at its root directory and `ports` at the ports checkout. The bootstrap compiler supplies the C++ and OpenMP headers. The linker maps record which shared objects provided the four libraries, and the installed loader runs both programs.

26+

27+```sh

28+links=$(mktemp -d)

29+for soname in libgcc_s.so.1 libstdc++.so.6 libatomic.so.1 libgomp.so.1; do

30+ ln -s "$runtime/usr/lib/$soname" "$links/${soname%.*}"

31+done

32+export VPAC_MAKEPKG_ROOT=$runtime

33+vinix-c++ $CXXFLAGS -std=c++17 -L"$links" -L/opt/cxx-link \

34+ -Wl,-rpath-link,"$runtime/usr/lib" -Wl,-Map,exceptions.map \

35+ "$ports/tests/toolchain/exceptions.cc" -lgcc_s -o exceptions

36+vinix-cc -std=gnu17 -fopenmp -L"$links" -L/opt/cxx-link \

37+ -Wl,-rpath-link,"$runtime/usr/lib" -Wl,-Map,parallel.map \

38+ "$ports/tests/toolchain/parallel.c" -latomic -o parallel

39+for lib in libstdc++.so libgcc_s.so; do grep -F "LOAD $links/$lib" exceptions.map; done

40+for lib in libgomp.so libatomic.so; do grep -F "LOAD $links/$lib" parallel.map; done

41+readelf -d "$runtime/usr/lib/libstdc++.so.6" | grep NEEDED | grep -F '[libgcc_s.so.1]'

42+vinix-run ./exceptions

43+vinix-run ./parallel

44+```

45+

46+For the compiler build, set `VPAC_MAKEPKG_ROOT` and `VPAC_MAKEPKG_DB` to the full SDK containing `gcc-libs` and `isl25`. ISL supplies the integer set operations used by GCC's Graphite loop optimizer. Keep the private link directory ahead of `/opt/cxx-link` in `LDFLAGS` and set `-Wl,-rpath-link,$VPAC_MAKEPKG_ROOT/usr/lib`. Run `vpac --native-build /work/gcc/PKGBUILD.vile /work/compiler-archive`. On a native build GCC builds its target development files with the new compiler and the SDK binutils.

47+

48+After publishing the compiler archive, install `gcc`, `make`, `busybox` and `linux-headers` by name in a fresh signed root. Copy `tests/toolchain/` into a writable directory in that root and run `make check` there. The test compiles and executes C and C++ programs with the packaged compiler, checks the three arithmetic libraries, unwinds a C++ exception and exercises the OpenMP and atomic runtimes. It also checks that Graphite found an affine loop region and uses a normal binutils archive containing link-time-optimization objects.

49+

50+### Building native AArch64 tools on x86-64

51+

52+Use a build-machine executable musl cross toolchain, its C++ headers and support libraries, and the signed AArch64 package root. Set `VPAC_TARGET_ARCH=aarch64`, `CROSS_COMPILE=aarch64-linux-`, and `VINIX_GCC_BUILD_TOOLS` to the cross toolchain's directory containing the unprefixed `as`, `ld`, `ar`, `nm` and `ranlib`. The worker's Bootlin 15.3 toolchain has this directory at `aarch64-buildroot-linux-musl/bin` under the toolchain root. Put the toolchain's top-level `bin` on `PATH` alongside `vinix-cc`, `vinix-c++`, `vinix-run` and `qemu-aarch64`.

53+

54+Use `CXXFLAGS` to add the target C++ headers and their `aarch64-buildroot-linux-musl` subdirectory. Provide the bootstrap `libstdc++.so` and `libgcc_s.so.1` link dependencies via a private directory as above. Keep the build machine's own library path for its make, shell and build-time tools. With the target-aware vpac builder, pass `--target=aarch64` to `--native-build`. The cross compiler builds target runtimes from the pinned GCC sources using the Vinix sysroot.

55+

56+Use musl 1.2.6-4 or later in the AArch64 SDK. Its GCC specs select the 16 KiB page size required by the released Vinix kernel, including when the bootstrap compiler has a 4 KiB default. Build the host tool `tools/vinix-elf-pages.v` as `vinix-elf-pages` and place it on `PATH`. The runtime and binutils recipes use it to check the installed shared objects and small executables produced by both linkers.

57+

58+Run the compiler test on each released kernel after the signed install. Copy `Makefile`, `arithmetic.c`, `exceptions.cc`, `parallel.c`, `graphite.c`, `optimizers.c` and `transaction.c` from `tests/toolchain/` to `/usr/share/vinix-toolchain-test/` in a disposable copy of the package root. Boot with `tests/disk-root.py` and `tests/toolchain/guest.sh`. The guest checks both compiler triplets and uses the installed GNU Make, compilers, assembler and linker to build and run the fixtures. The checks cover arithmetic, C++ unwinding, OpenMP and 128-bit atomics, Graphite, LTO and concurrent transactions through `libitm.so.1`.

tests/toolchain/guest.sh new file +23 -0

@@ -0,0 +1,23 @@

1+#!/bin/sh

2+# Build and run the compiler fixtures on the released Vinix kernel.

3+set -eu

4+export PATH=/bin:/usr/bin:/sbin:/usr/sbin

5+export HOME=/tmp LC_ALL=C

6+phase=start

7+finish() {

8+ rc=$?

9+ if [ "$rc" -ne 0 ]; then printf 'VPAC TOOLCHAIN GUEST FAIL %s %s\n' "$phase" "$rc"; fi

10+ /sbin/poweroff -f

11+}

12+trap finish EXIT

13+mkdir -p /tmp

14+test "$(uname -o)" = Vinix

15+arch=$(uname -m)

16+test "$(gcc -dumpmachine)" = "$arch-linux-musl"

17+test "$(g++ -dumpmachine)" = "$arch-linux-musl"

18+mkdir /tmp/vinix-toolchain-test

19+cp /usr/share/vinix-toolchain-test/* /tmp/vinix-toolchain-test/

20+cd /tmp/vinix-toolchain-test

21+phase=compile-and-run

22+make -j1 check

23+echo 'VPAC FIXTURE GUEST PASS'