# Building the first native GCC 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. 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. 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. ```sh mkdir -p /opt/cxx-link ln -s /usr/lib/libstdc++.so.6 /opt/cxx-link/libstdc++.so ln -s /usr/lib/libgcc_s.so.1 /opt/cxx-link/libgcc_s.so ln -s /usr/lib/libgcc_s.so.1 /opt/cxx-link/libgcc_s.so.1 ln -s /usr/lib/libssp_nonshared.a /opt/cxx-link/libssp_nonshared.a export VPAC_MAKEPKG_ROOT=/sdk VPAC_MAKEPKG_DB=/sdkdb export LD_LIBRARY_PATH=/sdk/usr/lib:/usr/lib export CXXFLAGS='-O0 -g0 -isystem /usr/include/c++/14.2.0 -isystem /usr/include/c++/14.2.0/x86_64-alpine-linux-musl' export LDFLAGS='-L/opt/cxx-link -Wl,-rpath-link,/opt/cxx-link' export MAKEFLAGS=-j2 vpac --native-build /work/gcc-libs/PKGBUILD.vile /work/runtime-archive ``` 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. 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. ```sh links=$(mktemp -d) for soname in libgcc_s.so.1 libstdc++.so.6 libatomic.so.1 libgomp.so.1; do ln -s "$runtime/usr/lib/$soname" "$links/${soname%.*}" done export VPAC_MAKEPKG_ROOT=$runtime vinix-c++ $CXXFLAGS -std=c++17 -L"$links" -L/opt/cxx-link \ -Wl,-rpath-link,"$runtime/usr/lib" -Wl,-Map,exceptions.map \ "$ports/tests/toolchain/exceptions.cc" -lgcc_s -o exceptions vinix-cc -std=gnu17 -fopenmp -L"$links" -L/opt/cxx-link \ -Wl,-rpath-link,"$runtime/usr/lib" -Wl,-Map,parallel.map \ "$ports/tests/toolchain/parallel.c" -latomic -o parallel for lib in libstdc++.so libgcc_s.so; do grep -F "LOAD $links/$lib" exceptions.map; done for lib in libgomp.so libatomic.so; do grep -F "LOAD $links/$lib" parallel.map; done readelf -d "$runtime/usr/lib/libstdc++.so.6" | grep NEEDED | grep -F '[libgcc_s.so.1]' vinix-run ./exceptions vinix-run ./parallel ``` 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. 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. ### Building native AArch64 tools on x86-64 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`. 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. 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. 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`.