me

/

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

Retain native GCC build objects between package retries

diviocity committed 5 days ago · e9d38658eac1f6ccabeafd3cc560020b098402c7 View patch
Unverified signature 6 files changed +252 -0
BOOTSTRAP.md +4 -0

@@ -13,6 +13,10 @@ Build the ports outside the source checkout. Keep a separate SDK and package dat

1313

1414The 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.

1515

16+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`.

17+

18+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`.

19+

1620For 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.

1721

1822```sh

gcc/PKGBUILD.vile new file +156 -0

@@ -0,0 +1,156 @@

1+; The build machine needs a working musl C++17 compiler. CXXFLAGS and LDFLAGS

2+; may point at that compiler's C++ headers and runtime for this first stage.

3+; A native bootstrap builds the target runtime with the new compiler. A

4+; cross bootstrap needs an existing build-machine compiler for the target.

5+host-arch := if memq(string->symbol("aarch64"), features()) { "aarch64" } else { "x86_64" }

6+selected := get-environment-variable("VPAC_TARGET_ARCH")

7+arch := if string?(selected) { selected } else { host-arch }

8+triplet := string-append(arch, "-linux-musl")

9+cross := not(string=?(arch, host-arch))

10+libc := if string=?(arch, "aarch64") { "musl>=1.2.6-4" } else { "musl" }

11+

12+; Makefiles keep absolute paths. A worker retry can keep the prepared source

13+; and objects in the same dedicated directory.

14+checkpoint := get-environment-variable("VINIX_GCC_BUILD_DIR")

15+persistent := if string?(checkpoint) { not(string=?("", checkpoint)) } else { #f }

16+checkpoint-recipe := if persistent { string-append(checkpoint, "/recipe.vile") } else { "" }

17+cached := if persistent { file-exists?(checkpoint-recipe) } else { #f }

18+build-dir := fn() { if persistent { checkpoint } else { srcdir() } }

19+local-archive := get-environment-variable("VINIX_GCC_LOCAL_SOURCE")

20+source-archive := if equal?("1", local-archive) {

21+ "gcc-14.2.0.tar.xz"

22+} else {

23+ "https://distfiles.alpinelinux.org/distfiles/v3.21/gcc-14.2.0.tar.xz"

24+}

25+

26+itm-compiler := fn() {

27+ if cross { "CXX_FOR_TARGET=vinix-c++" }

28+ else {

29+ build := build-dir()

30+ cxx := string-append(build, "/", triplet, "/libstdc++-v3")

31+ string-append("CXX_FOR_TARGET=", build, "/gcc/xg++ -B", build, "/gcc/ -nostdinc++",

32+ " -isystem ", cxx, "/include/", triplet, " -isystem ", cxx, "/include",

33+ " -isystem ", build, "/gcc-14.2.0/libstdc++-v3/libsupc++",

34+ " -L", cxx, "/src/.libs -L", cxx, "/libsupc++/.libs")

35+ }

36+}

37+

38+defpkgbuild(gcc,

39+ #:pkgname, "gcc",

40+ #:pkgver, "14.2.0",

41+ #:pkgrel, 1,

42+ #:pkgdesc, "GNU C and C++ compilers, headers and development libraries for Vinix",

43+ #:arch, [#:x86-64, #:aarch64],

44+ #:url, "https://gcc.gnu.org/",

45+ #:license, ["GPL-3.0-or-later", "GPL-3.0-or-later WITH GCC-exception-3.1"],

46+ #:depends, list(libc, if string=?(arch, "aarch64") { "gcc-libs=14.2.0-2" } else { "gcc-libs=14.2.0-1" },

47+ "gmp", "mpfr", "mpc", "isl25", "zlib", "binutils"),

48+ #:provides, ["g++=14.2.0", "libstdc++-dev=14.2.0"],

49+ #:makedepends, ["make", "linux-headers"],

50+ #:source, if cached { list() } else { list(source-archive) },

51+ #:sha256sums, if cached { list() } else { ["a7b39bc69cbf9e25826c5a60ab26477001f7c08d85cec04bc0e29cabed6f3cc9"] },

52+ #:prepare, fn() {

53+ if cached {

54+ run("cmp", string-append(startdir(), "/PKGBUILD.vile"), checkpoint-recipe)

55+ run("test", "-x", string-append(build-dir(), "/gcc-14.2.0/configure"))

56+ } else {

57+ ; Serialize the two memory-intensive instruction-table generators.

58+ run("sed", "-i", "$a s-automata: s-attrtab", "gcc-14.2.0/gcc/Makefile.in")

59+ ; Match the library directory used by Vinix's musl loader.

60+ if string=?(arch, "x86_64") {

61+ run("sed", "-i", "s|m64=../lib64|m64=../lib|", "gcc-14.2.0/gcc/config/i386/t-linux64")

62+ } else {

63+ run("sed", "-i", "s|mabi.lp64=../lib64|mabi.lp64=../lib|", "gcc-14.2.0/gcc/config/aarch64/t-aarch64-linux")

64+ ; This default also applies when GCC drives an alternate GNU linker.

65+ 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|",

66+ "gcc-14.2.0/gcc/config/aarch64/aarch64-linux.h")

67+ }

68+ if persistent {

69+ run("mkdir", checkpoint)

70+ run("mv", "gcc-14.2.0", checkpoint)

71+ run("cp", string-append(startdir(), "/PKGBUILD.vile"), checkpoint-recipe)

72+ }

73+ }

74+ },

75+ #:build, fn() {

76+ root := get-environment-variable("VPAC_MAKEPKG_ROOT")

77+ binutils := if cross { get-environment-variable("VINIX_GCC_BUILD_TOOLS") } else { string-append(root, "/usr/bin") }

78+ run("test", "-x", string-append(binutils, "/as"))

79+ run("test", "-x", string-append(binutils, "/ld"))

80+ target-tools := if cross {

81+ list("CC_FOR_BUILD=gcc", "CXX_FOR_BUILD=g++", "CFLAGS_FOR_BUILD=-O2 -g0", "CXXFLAGS_FOR_BUILD=-O2 -g0", "LDFLAGS_FOR_BUILD=",

82+ "AR_FOR_BUILD=ar", "RANLIB_FOR_BUILD=ranlib",

83+ string-append("AR=", binutils, "/ar"), string-append("AS=", binutils, "/as"),

84+ string-append("LD=", binutils, "/ld"), string-append("NM=", binutils, "/nm"),

85+ string-append("RANLIB=", binutils, "/ranlib"), string-append("STRIP=", binutils, "/strip"),

86+ "CC_FOR_TARGET=vinix-cc", "GCC_FOR_TARGET=vinix-cc", "CXX_FOR_TARGET=vinix-c++", "RAW_CXX_FOR_TARGET=vinix-c++",

87+ string-append("AR_FOR_TARGET=", binutils, "/ar"),

88+ string-append("AS_FOR_TARGET=", binutils, "/as"), string-append("LD_FOR_TARGET=", binutils, "/ld"),

89+ string-append("NM_FOR_TARGET=", binutils, "/nm"), string-append("RANLIB_FOR_TARGET=", binutils, "/ranlib"))

90+ } else { list() }

91+ build-option := if cross { list() } else { list(string-append("--build=", triplet)) }

92+ configured := string-append(build-dir(), "/.vinix-configured")

93+ if not(file-exists?(configured)) {

94+ apply(run, append(list("sh", "-ec", "cd \"$1\"; shift; exec \"$@\"", "gcc-configure", build-dir(),

95+ "env", "CC=vinix-cc", "CXX=vinix-c++", "CC_FOR_BUILD=gcc", "CXX_FOR_BUILD=g++",

96+ "CFLAGS=-O1 -g0", "CFLAGS_FOR_TARGET=-O2 -g0", "CXXFLAGS_FOR_TARGET=-O2 -g0"), target-tools,

97+ list("gcc-14.2.0/configure", "--prefix=/usr", "--libdir=/usr/lib"), build-option,

98+ list(string-append("--host=", triplet), string-append("--target=", triplet), "--enable-languages=c,c++", "--disable-bootstrap",

99+ "--with-sysroot=/", string-append("--with-build-sysroot=", root), "--with-native-system-header-dir=/usr/include",

100+ string-append("--with-build-time-tools=", binutils),

101+ string-append("--with-gmp=", root, "/usr"), string-append("--with-mpfr=", root, "/usr"), string-append("--with-mpc=", root, "/usr"),

102+ string-append("--with-isl=", root, "/usr"), "--with-system-zlib", "--without-zstd", "--disable-multilib", "--disable-nls",

103+ "--disable-libsanitizer", "--disable-libvtv", "--disable-libquadmath", "--enable-libgomp", "--enable-libatomic", "--enable-libitm",

104+ "--disable-libstdcxx-pch", "--enable-libcc1", "--enable-lto", "--enable-plugin", "--enable-threads=posix",

105+ "--enable-shared", "--enable-default-pie", "--enable-default-ssp", "--enable-initfini-array")))

106+ run("touch", configured)

107+ }

108+ apply(run, append(list("make", "-C", build-dir(), "GENERATOR_CFLAGS=-O2 -g0"), target-tools,

109+ list("all-gcc", "all-libcc1", "all-lto-plugin", "all-target-libgcc", "all-target-libstdc++-v3",

110+ "all-target-libatomic", "all-target-libgomp")))

111+ ; Pass a concrete command to libitm's recursive make. The standard

112+ ; CXX_FOR_TARGET recipe expands a shell command to find the C++ headers.

113+ apply(run, append(list("make", "-C", build-dir(), itm-compiler()), target-tools, list("all-target-libitm")))

114+ },

115+ #:check, fn() {

116+ driver := string-append(build-dir(), "/gcc/xgcc")

117+ binaries := string-append("-B", build-dir(), "/gcc/")

118+ if cross {

119+ runtime := string-append(build-dir(), "/", triplet)

120+ libraries := string-append(runtime, "/libstdc++-v3/src/.libs:", runtime, "/libgcc")

121+ run("vinix-run", "--library-path", libraries, driver, binaries, "-dumpmachine")

122+ } else {

123+ run(driver, binaries, "-dumpmachine")

124+ }

125+ },

126+ #:package, fn() {

127+ run("make", "-C", build-dir(), string-append("DESTDIR=", pkgdir()), "install-gcc", "install-libcc1", "install-lto-plugin", "install-target-libgcc",

128+ "install-target-libstdc++-v3", "install-target-libatomic", "install-target-libgomp")

129+ run("make", "-C", build-dir(), string-append("DESTDIR=", pkgdir()), itm-compiler(), "install-target-libitm")

130+ ; The versioned shared objects are owned by gcc-libs. Keep the unversioned

131+ ; linker entries, static archives and headers here.

132+ for-each(fn(lib) {

133+ files := glob(string-append(pkgdir(), "/usr/lib/", lib, ".so.[0-9]*"))

134+ run("test", "-f", car(files))

135+ for-each(fn(file) { run("rm", file) }, files)

136+ }, list("libgcc_s", "libstdc++", "libatomic", "libgomp"))

137+ for-each(fn(la) { run("rm", la) }, glob(string-append(pkgdir(), "/usr/lib/*.la")))

138+ run("ln", "-s", "gcc", string-append(pkgdir(), "/usr/bin/cc"))

139+ for-each(fn(standard) {

140+ path := string-append(pkgdir(), "/usr/bin/", standard)

141+ compatible := if string=?(standard, "c89") { "-ansi|-std=iso9899:1990" } else { "-std=iso9899:1999" }

142+ call-with-output-file(path, fn(port) {

143+ display(string-append("#!/bin/sh\nfor arg do\n case \"$arg\" in\n -std=", standard, "|", compatible,

144+ ") ;;\n -std=*) echo \"", standard, ": incompatible C standard: $arg\" >&2; exit 1 ;;\n esac\ndone\nexec /usr/bin/gcc -std=",

145+ standard, " \"$@\"\n"), port)

146+ })

147+ run("chmod", "755", path)

148+ }, list("c89", "c99"))

149+ plugin := string-append("libexec/gcc/", triplet, "/14.2.0/liblto_plugin.so")

150+ run("test", "-f", string-append(pkgdir(), "/usr/", plugin))

151+ run("mkdir", "-p", string-append(pkgdir(), "/usr/lib/bfd-plugins"))

152+ run("ln", "-s", string-append("../../", plugin), string-append(pkgdir(), "/usr/lib/bfd-plugins/liblto_plugin.so"))

153+ run("rm", "-f", string-append(pkgdir(), "/usr/share/info/dir"))

154+ run("install", "-Dm644", string-append(build-dir(), "/gcc-14.2.0/COPYING3"), string-append(pkgdir(), "/usr/share/licenses/gcc/COPYING3"))

155+ run("install", "-Dm644", string-append(build-dir(), "/gcc-14.2.0/COPYING.RUNTIME"), string-append(pkgdir(), "/usr/share/licenses/gcc/COPYING.RUNTIME"))

156+ })

tests/toolchain/Makefile new file +39 -0

@@ -0,0 +1,39 @@

1+.PHONY: check

2+check: arithmetic exceptions parallel graphite optimizers transaction

3+ printf '\n' | c99 -dM -E - | grep -Fx '#define __STDC_VERSION__ 199901L'

4+ printf '\n' | c89 -dM -E - >c89-macros

5+ if grep -q __STDC_VERSION__ c89-macros; then exit 1; fi

6+ if c89 -std=c99 -v >/dev/null 2>&1; then exit 1; fi

7+ ./arithmetic

8+ ./exceptions

9+ ./parallel

10+ ./graphite

11+ ./optimizers

12+ ./transaction

13+ readelf -d transaction | grep -F '[libitm.so.1]'

14+ grep -Eq 'number of SCoPs: [1-9]|SCoP statistics' graphite.dump

15+

16+arithmetic: arithmetic.c

17+ $(CC) -std=c17 -Wall -Wextra -o $@ $< -lmpc -lmpfr -lgmp

18+

19+exceptions: exceptions.cc

20+ $(CXX) -std=c++17 -Wall -Wextra -o $@ $<

21+

22+parallel: parallel.c

23+ $(CC) -std=gnu17 -Wall -Wextra -fopenmp -o $@ $< -latomic

24+

25+transaction: transaction.c

26+ $(CC) -std=gnu17 -Wall -Wextra -fgnu-tm -pthread -o $@ $<

27+

28+graphite.o: graphite.c

29+ $(CC) -O2 -fgraphite-identity -fdump-tree-graphite-details=graphite.dump -c -o $@ $<

30+

31+graphite: optimizers.c graphite.o

32+ $(CC) -O2 -o $@ $^

33+

34+libgraphite.a: graphite.c

35+ $(CC) -O2 -flto -fno-fat-lto-objects -c -o graphite-lto.o $<

36+ $(AR) rcs $@ graphite-lto.o

37+

38+optimizers: optimizers.c libgraphite.a

39+ $(CC) -O2 -flto -o $@ $^

tests/toolchain/graphite.c new file +6 -0

@@ -0,0 +1,6 @@

1+void fill_rows(int grid[32][32], int step)

2+{

3+ for (int row = 0; row < 32; ++row)

4+ for (int col = 1; col < 32; ++col)

5+ grid[row][col] = grid[row][col - 1] + step;

6+}

tests/toolchain/optimizers.c new file +19 -0

@@ -0,0 +1,19 @@

1+#include <stdio.h>

2+

3+void fill_rows(int grid[32][32], int step);

4+

5+int main(int argc, char **argv)

6+{

7+ int grid[32][32];

8+ int step = argc + 2;

9+ (void)argv;

10+ for (int row = 0; row < 32; ++row)

11+ grid[row][0] = row;

12+ fill_rows(grid, step);

13+ for (int row = 0; row < 32; ++row)

14+ for (int col = 0; col < 32; ++col)

15+ if (grid[row][col] != row + col * step)

16+ return 1;

17+ puts("Vinix optimized loop passed");

18+ return 0;

19+}

tests/toolchain/transaction.c new file +28 -0

@@ -0,0 +1,28 @@

1+#include <pthread.h>

2+#include <stdio.h>

3+

4+enum { iterations = 64 };

5+static int total;

6+

7+static void *increment(void *unused)

8+{

9+ (void)unused;

10+ for (int i = 0; i < iterations; ++i) {

11+ __transaction_atomic {

12+ ++total;

13+ }

14+ }

15+ return NULL;

16+}

17+

18+int main(void)

19+{

20+ pthread_t thread;

21+ if (pthread_create(&thread, NULL, increment, NULL) != 0)

22+ return 1;

23+ increment(NULL);

24+ if (pthread_join(thread, NULL) != 0)

25+ return 1;

26+ printf("transaction total %d\n", total);

27+ return total != 2 * iterations;

28+}