; Build the target runtimes from GCC sources using the external bootstrap ; compiler. Only the versioned shared objects belong to this package. 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 } arm := string=?(arch, "aarch64") libc := if arm { "musl>=1.2.6-4" } else { "musl" } triplet := string-append(arch, "-linux-musl") libs := list("libgcc_s.so.1", "libstdc++.so.6", "libatomic.so.1", "libgomp.so.1") defpkgbuild(gcc-libs, #:pkgname, "gcc-libs", #:pkgver, "14.2.0", #:pkgrel, if arm { 2 } else { 1 }, #:pkgdesc, "GNU C and C++ shared runtime libraries for Vinix", #:arch, [#:x86-64, #:aarch64], #:url, "https://gcc.gnu.org/", #:license, ["GPL-3.0-or-later WITH GCC-exception-3.1"], #:depends, list(libc), #:provides, ["libgcc=14.2.0", "libstdc++=14.2.0", "libatomic=14.2.0", "libgomp=14.2.0"], #:makedepends, ["linux-headers", "gmp", "mpfr", "mpc", "zlib", "make"], #:source, ["https://distfiles.alpinelinux.org/distfiles/v3.21/gcc-14.2.0.tar.xz"], #:sha256sums, ["a7b39bc69cbf9e25826c5a60ab26477001f7c08d85cec04bc0e29cabed6f3cc9"], #:build, fn() { root := get-environment-variable("VPAC_MAKEPKG_ROOT") native := string=?(host-arch, arch) prefix := if native { "" } else { get-environment-variable("CROSS_COMPILE") } driver := string-append(srcdir(), "/driver-support") ; Alpine's bootstrap GCC unconditionally links -lssp_nonshared. Older ; Vinix SDKs lack the archive. Build its GCC implementation for the ; selected target without adding any external library search directory. driver-flags := if file-exists?(string-append(root, "/usr/lib/libssp_nonshared.a")) { "" } else { run("mkdir", "-p", driver) call-with-output-file(string-append(driver, "/config.h"), fn(port) { display("#define HAVE_HIDDEN_VISIBILITY 1\n", port) }) object := string-append(driver, "/ssp-local.o") run("vinix-cc", "-O2", "-fPIC", "-fno-stack-protector", string-append("-I", driver), "-c", "gcc-14.2.0/libssp/ssp-local.c", "-o", object) run(string-append(prefix, "ar"), "rcs", string-append(driver, "/libssp_nonshared.a"), object) string-append("-L", driver) } build-option := if native { list(string-append("--build=", triplet)) } else { list() } target-flags := if arm { "-O2 -g0 -mno-outline-atomics" } else { "-O2 -g0" } target-tools := if native { list() } else { 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=", prefix, "ar"), string-append("AS=", prefix, "as"), string-append("LD=", prefix, "ld"), string-append("NM=", prefix, "nm"), string-append("RANLIB=", prefix, "ranlib"), string-append("STRIP=", prefix, "strip"), string-append("AR_FOR_TARGET=", prefix, "ar"), string-append("AS_FOR_TARGET=", prefix, "as"), string-append("LD_FOR_TARGET=", prefix, "ld"), string-append("NM_FOR_TARGET=", prefix, "nm"), string-append("RANLIB_FOR_TARGET=", prefix, "ranlib"), string-append("STRIP_FOR_TARGET=", prefix, "strip")) } apply(run, append(list("env", "CC=vinix-cc", "CXX=vinix-c++", "CC_FOR_BUILD=gcc", "CXX_FOR_BUILD=g++", "CFLAGS=-O1 -g0", string-append("CFLAGS_FOR_TARGET=", target-flags), string-append("CXXFLAGS_FOR_TARGET=", target-flags)), 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-gmp=", root, "/usr"), string-append("--with-mpfr=", root, "/usr"), string-append("--with-mpc=", root, "/usr"), "--with-system-zlib", "--without-isl", "--disable-multilib", "--disable-nls", "--disable-libstdcxx-pch", "--disable-libsanitizer", "--disable-libquadmath", "--disable-libcc1", "--enable-libatomic", "--enable-libgomp", "--enable-shared", "--enable-threads=posix"))) apply(run, append(list("make"), target-tools, list("configure-gcc", "all-build-libiberty", "all-build-fixincludes", "all-libiberty", "all-libcpp", "all-libdecnumber", "all-libbacktrace"))) ; GCC's fixed-header rules query the compiler's predefined macros and ; multilib list. The bootstrap driver can answer both for the target. apply(run, append(list("make", "-C", "gcc", "-o", "xgcc", "-o", "specs", "-o", "cc1", "GCC_FOR_TARGET=vinix-cc"), target-tools, list("GENERATOR_CFLAGS=-O2 -g0", "libgcc-support", "tm.h", "options.h", "insn-constants.h", "insn-modes.h", "insn-modes-inline.h"))) target-make := append(list("make", "-o", "maybe-all-gcc", "-o", "all-gcc", "CC_FOR_TARGET=vinix-cc", "GCC_FOR_TARGET=vinix-cc", "CXX_FOR_TARGET=vinix-c++", "RAW_CXX_FOR_TARGET=vinix-c++"), target-tools) apply(run, append(target-make, list(string-append("LDFLAGS_FOR_TARGET=", driver-flags), "all-target-libgcc"))) ; The stage-one musl specs normally select static compiler support. ; Link libstdc++ to the shared unwinder built in the preceding step. support := string-append(srcdir(), "/", triplet, "/libgcc") run("test", "-f", string-append(support, "/libgcc_s.so.1")) ; Libtool filters a bare shared-object argument from LDFLAGS. Passing it ; explicitly to ld keeps the new runtime's SONAME in libstdc++.so.6. link-flags := string-append("LDFLAGS_FOR_TARGET=", driver-flags, " -Wl,--no-as-needed,", support, "/libgcc_s.so.1,--as-needed -Wl,-rpath-link,", root, "/lib -Wl,-rpath-link,", root, "/usr/lib") ; Preserve the completed unwinder. Recursing into libgcc with its own ; shared object on the link line produces a self-dependent library. libraries := append(target-make, list("-o", "maybe-all-target-libgcc", "-o", "all-target-libgcc")) apply(run, append(libraries, list(link-flags, "all-target-libstdc++-v3"))) apply(run, append(libraries, list(string-append("LDFLAGS_FOR_TARGET=", driver-flags), "all-target-libatomic", "all-target-libgomp"))) }, #:package, fn() { dest := string-append(pkgdir(), "/usr/lib") run("mkdir", "-p", dest) ; Copy only files linked by these four target build directories. The ; archive contains the versioned ELF and its SONAME, not seed libraries. for-each(fn(pattern) { for-each(fn(file) { run("cp", "-P", file, dest) }, glob(pattern)) }, list(string-append(triplet, "/libgcc/libgcc_s.so.*"), string-append(triplet, "/libstdc++-v3/src/.libs/libstdc++.so.*"), string-append(triplet, "/libatomic/.libs/libatomic.so.*"), string-append(triplet, "/libgomp/.libs/libgomp.so.*"))) for-each(fn(lib) { run("test", "-f", string-append(dest, "/", lib)) }, libs) run("sh", "-ec", "readelf -d \"$1\" | grep '(NEEDED)' | grep -F '[libgcc_s.so.1]'", "check-unwinder", string-append(dest, "/libstdc++.so.6")) if arm { for-each(fn(lib) { file := string-append(dest, "/", lib) run("vinix-elf-pages", arch, file) run("sh", "-ec", "readelf --wide --dyn-syms \"$1\" | awk '$7 == \"UND\" && $8 ~ /^__aarch64_(cas|swp|ldadd|ldclr|ldeor|ldset)/ { print $8; bad=1 } END { exit bad }'", "check-outlined-atomics", file) }, libs) } run("install", "-Dm644", "gcc-14.2.0/COPYING.RUNTIME", string-append(pkgdir(), "/usr/share/licenses/gcc-libs/COPYING.RUNTIME")) run("install", "-Dm644", "gcc-14.2.0/COPYING3", string-append(pkgdir(), "/usr/share/licenses/gcc-libs/COPYING3")) })