diff --git a/gcc-bolt/PKGBUILD b/gcc-bolt/PKGBUILD new file mode 100644 index 00000000..2a9b2a8f --- /dev/null +++ b/gcc-bolt/PKGBUILD @@ -0,0 +1,223 @@ +# Maintainer: Giancarlo Razzolini +# Maintainer: Frederik Schwan +# Contributor: Bartłomiej Piotrowski +# Contributor: Allan McRae +# Contributor: Daniel Kozak + +# toolchain build order: linux-api-headers->glibc->binutils->gcc->glibc->binutils->gcc +# NOTE: libtool requires rebuilt with each new gcc version + +pkgname=(gcc-bolt) +pkgver=13.2.1 +_majorver=${pkgver%%.*} +_commit=79d0dd71302daf51448a07e42ab77a397e2cf0a8 +pkgrel=1 +pkgdesc='The GNU Compiler Collection' +arch=(x86_64) +license=(GPL3 LGPL FDL custom) +url='https://gcc.gnu.org' +makedepends=( + binutils + git + libisl + libmpc + python + zstd + libisl + cloog + perf + llvm-bolt +) +checkdepends=( + dejagnu + expect + inetutils + python-pytest + tcl + libisl + cloog +) +options=(!emptydirs !lto) +_libdir=usr/lib/gcc/$CHOST/13.2.1 +source=(git+https://sourceware.org/git/gcc.git#commit=${_commit} + https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.7.3.tar.xz + c89 c99 + gcc-ada-repro.patch + tune-inline.patch + fix-asan-allocator-aslr.patch +) +validpgpkeys=(F3691687D867B81B51CE07D9BBE43771487328A9 # bpiotrowski@archlinux.org + 86CFFCA918CF3AF47147588051E8B148A9999C34 # evangelos@foutrelis.com + 13975A70E63C361C73AE69EF6EEB81F8981C74C7 # richard.guenther@gmail.com + D3A93CAD751C2AF4F8C7AD516C35B99309B5FA62) # Jakub Jelinek +sha256sums=('SKIP' + 'de48736f6e4153f03d0a5d38ceb6c6fdb7f054e8f47ddd6af0a3dbf14f27b931' + '2513c6d9984dd0a2058557bf00f06d8d5181734e41dcfe07be7ed86f2959622a' + '1773f5137f08ac1f48f0f7297e324d5d868d55201c03068670ee4602babdef2f') +prepare() { + [[ ! -d gcc ]] && ln -s gcc-${pkgver/+/-} gcc + cd gcc + + # Do not run fixincludes + sed -i 's@\./fixinc\.sh@-c true@' gcc/Makefile.in + + # Arch Linux installs x86_64 libraries /lib + sed -i '/m64=/s/lib64/lib/' gcc/config/i386/t-linux64 + + patch -Np3 -d libsanitizer/ <"$srcdir/fix-asan-allocator-aslr.patch" + + # Reproducible gcc-ada + patch -Np0 <"$srcdir/gcc-ada-repro.patch" + patch -Np1 <"$srcdir/tune-inline.patch" + + mkdir -p "$srcdir/gcc-build" + mkdir -p "$srcdir/libgccjit-build" +} + +build() { + local _confflags=( + --prefix=/usr + --libdir=/usr/lib + --libexecdir=/usr/lib + --mandir=/usr/share/man + --infodir=/usr/share/info + --with-build-config=bootstrap-lto + --with-linker-hash-style=gnu + --with-system-zlib + --enable-__cxa_atexit + --enable-cet=auto + --enable-checking=release + --enable-clocale=gnu + --enable-default-pie + --enable-default-ssp + --enable-gnu-indirect-function + --enable-gnu-unique-object + --enable-libstdcxx-backtrace + --enable-link-serialization=1 + --enable-linker-build-id + --enable-lto + --disable-multilib + --enable-plugin + --enable-shared + --enable-threads=posix + --disable-libssp + --enable-libstdcxx-pch + --disable-werror + --with-cloog + --with-isl + --disable-vtable-verify + --enable-linux-futex + --enable-version-specific-runtime-libs + --with-pkgversion='CachyOS GCC 13.2.1' + + ) + + cd gcc-build + + CFLAGS=${CFLAGS/-Werror=format-security/} + CXXFLAGS=${CXXFLAGS/-Werror=format-security/} + export CFLAGS+=" -fno-semantic-interposition" + export CXXFLAGS+=" -fno-semantic-interposition" + export CFLAGS+=" -fno-reorder-blocks-and-partition" + export CXXFLAGS+=" -fno-reorder-blocks-and-partition" + export LDFLAGS+=",--emit-relocs" + "$srcdir/gcc/configure" \ + --enable-languages=c,c++,lto \ + --enable-bootstrap \ + "${_confflags[@]:?_confflags unset}" + + + make -O STAGE1_CFLAGS="-O3" \ + BOOT_CFLAGS="$CFLAGS" \ + BOOT_LDFLAGS="$LDFLAGS" \ + LDFLAGS_FOR_TARGET="$LDFLAGS" \ + profiledbootstrap + + + BOLTDIR="${srcdir}"/gcc-bolt + mkdir -p "${BOLTDIR}" + cd $srcdir/gcc-build + make DESTDIR="$BOLTDIR" install + + PATH="$BOLTDIR/usr/bin:$PATH" + + cd $srcdir/linux-6.7.3 + make distclean + yes "" | make oldconfig + + perf record -o ${srcdir}/cc1.data --max-size=4G -F 1700 -e cycles:u -j any,u -- make -j$(nproc) || true + + cd "${srcdir}" + + mkdir -p "${srcdir}/gcc-bolted" + cd "${srcdir}/gcc-bolted" + "${srcdir}/gcc/configure" \ + --enable-languages=c,c++,lto \ + --enable-bootstrap \ + "${_confflags[@]:?_confflags unset}" + + perf record -o ${srcdir}/cc1plus.data --max-size=4G -F 1700 -e cycles:u -j any,u -- make -j$(nproc) all-gcc || true + +} + +package_gcc-bolt() { + pkgdesc="The GNU Compiler Collection - C and C++ frontends" + depends=('binutils>=2.28' libmpc zstd libisl.so) + provides=($pkgname) + replaces=($pkgname) + options=(!emptydirs staticlibs !strip !lto) + + cd gcc-build + + make DESTDIR="$pkgdir" install + + LD_PRELOAD=/usr/lib/libjemalloc.so perf2bolt $pkgdir/usr/lib/gcc/x86_64-pc-linux-gnu/13.2.1/cc1 \ + -p $srcdir/cc1.data \ + -o $srcdir/cc1.fdata + + LD_PRELOAD=/usr/lib/libjemalloc.so llvm-bolt $pkgdir/usr/lib/gcc/x86_64-pc-linux-gnu/13.2.1/cc1 \ + --data $srcdir/cc1.fdata \ + -o $pkgdir/usr/lib/gcc/x86_64-pc-linux-gnu/13.2.1/cc1.bolt \ + -reorder-blocks=ext-tsp \ + -reorder-functions=hfsort+ \ + -split-functions \ + -split-all-cold \ + -split-eh \ + -dyno-stats \ + -icf=1 \ + -use-gnu-stack \ + -plt=hot || ( + echo "Could not optimize binary for cc1" + exit 1 + ) + + LD_PRELOAD=/usr/lib/libjemalloc.so perf2bolt $pkgdir/usr/lib/gcc/x86_64-pc-linux-gnu/13.2.1/cc1plus \ + -p $srcdir/cc1plus.data \ + -o $srcdir/cc1plus.fdata + + LD_PRELOAD=/usr/lib/libjemalloc.so llvm-bolt $pkgdir/usr/lib/gcc/x86_64-pc-linux-gnu/13.2.1/cc1plus \ + --data $srcdir/cc1plus.fdata \ + -o $pkgdir/usr/lib/gcc/x86_64-pc-linux-gnu/13.2.1/cc1plus.bolt \ + -reorder-blocks=ext-tsp \ + -reorder-functions=hfsort+ \ + -split-functions \ + -split-all-cold \ + -split-eh \ + -dyno-stats \ + -icf=1 \ + -use-gnu-stack \ + -plt=hot || ( + echo "Could not optimize binary for cc1plus" + exit 1 + ) + + mv $pkgdir/usr/lib/gcc/x86_64-pc-linux-gnu/13.2.1/cc1 $pkgdir/usr/lib/gcc/x86_64-pc-linux-gnu/13.2.1/cc1.orig + mv $pkgdir/usr/lib/gcc/x86_64-pc-linux-gnu/13.2.1/cc1plus $pkgdir/usr/lib/gcc/x86_64-pc-linux-gnu/13.2.1/cc1plus.orig + + mv $pkgdir/usr/lib/gcc/x86_64-pc-linux-gnu/13.2.1/cc1.bolt $pkgdir/usr/lib/gcc/x86_64-pc-linux-gnu/13.2.1/cc1 + mv $pkgdir/usr/lib/gcc/x86_64-pc-linux-gnu/13.2.1/cc1plus.bolt $pkgdir/usr/lib/gcc/x86_64-pc-linux-gnu/13.2.1/cc1plus + + mv ${pkgdir}/usr ${pkgdir}/opt + install -Dm755 "$srcdir/c89" "$pkgdir/opt/bin/c89" + install -Dm755 "$srcdir/c99" "$pkgdir/opt/bin/c99" +} diff --git a/gcc-bolt/c89 b/gcc-bolt/c89 new file mode 100644 index 00000000..35486ea8 --- /dev/null +++ b/gcc-bolt/c89 @@ -0,0 +1,10 @@ +#!/bin/sh +fl="-std=c89" +for opt; do + case "$opt" in + -ansi|-std=c89|-std=iso9899:1990) fl="";; + -std=*) echo "`basename $0` called with non ANSI/ISO C option $opt" >&2 + exit 1;; + esac +done +exec gcc $fl ${1+"$@"} diff --git a/gcc-bolt/c99 b/gcc-bolt/c99 new file mode 100644 index 00000000..88dd8064 --- /dev/null +++ b/gcc-bolt/c99 @@ -0,0 +1,10 @@ +#!/bin/sh +fl="-std=c99" +for opt; do + case "$opt" in + -std=c99|-std=iso9899:1999) fl="";; + -std=*) echo "`basename $0` called with non ISO C99 option $opt" >&2 + exit 1;; + esac +done +exec gcc $fl ${1+"$@"} diff --git a/gcc-bolt/fix-asan-allocator-aslr.patch b/gcc-bolt/fix-asan-allocator-aslr.patch new file mode 100644 index 00000000..af7cea86 --- /dev/null +++ b/gcc-bolt/fix-asan-allocator-aslr.patch @@ -0,0 +1,60 @@ +From fb77ca05ffb4f8e666878f2f6718a9fb4d686839 Mon Sep 17 00:00:00 2001 +From: Thurston Dang +Date: Thu, 13 Apr 2023 23:55:01 +0000 +Subject: [PATCH] Re-land 'ASan: move allocator base to avoid conflict with + high-entropy ASLR for x86-64 Linux' + +D147984 was reverted because it broke lit tests on Mac. This revision is based on D147984 +but maintains the old behavior for Apple. + +Note that, per the follow-up discussion with MaskRay in D147984, this patch excludes Apple +but includes other platforms (e.g., aarch64, MIPS64) and OSes (e.g., FreeBSD, S390X), not just +x86-64 Linux. + +Original commit message from D147984: + +Users have discovered [*] that when CONFIG_ARCH_MMAP_RND_BITS == 32, +it will frequently conflict with ASan's allocator on x86-64 Linux, because the +PIE program segment base address of 0x555555555554 plus an ASLR shift of up to +((2**32) * 4K == 0x100000000000) will sometimes exceed ASan's hardcoded +base address of 0x600000000000. We fix this by simply moving the allocator base +to 0x500000000000, which is below the PIE program segment base address. This is +cleaner than trying to move it to another location that is sandwiched between +the PIE program and library segments, because if either of those grow too large, +it will collide with the allocator region. + +Note that we will never need to change this base address again (unless we want to increase +the size of the allocator), because ASLR cannot be set above 32-bits for x86-64 Linux (the +PIE program segment and library segments would collide with each other; see also +ARCH_MMAP_RND_BITS_MAX in https://github.com/torvalds/linux/blob/master/arch/x86/Kconfig). + +[*] see https://b.corp.google.com/issues/276925478 +and https://groups.google.com/a/google.com/g/chrome-os-gardeners/c/BbfzCP3dEeo/m/h3C_vVUxCQAJ + +Differential Revision: https://reviews.llvm.org/D148280 +--- + compiler-rt/lib/asan/asan_allocator.h | 8 ++++++-- + 1 file changed, 6 insertions(+), 2 deletions(-) + +diff --git a/compiler-rt/lib/asan/asan_allocator.h b/compiler-rt/lib/asan/asan_allocator.h +index 0b4dbf03bb9d5..6a12a6c602528 100644 +--- a/compiler-rt/lib/asan/asan_allocator.h ++++ b/compiler-rt/lib/asan/asan_allocator.h +@@ -143,11 +143,15 @@ typedef DefaultSizeClassMap SizeClassMap; + const uptr kAllocatorSpace = ~(uptr)0; + const uptr kAllocatorSize = 0x8000000000ULL; // 500G + typedef DefaultSizeClassMap SizeClassMap; +-# else ++# elif SANITIZER_APPLE + const uptr kAllocatorSpace = 0x600000000000ULL; + const uptr kAllocatorSize = 0x40000000000ULL; // 4T. + typedef DefaultSizeClassMap SizeClassMap; +-# endif ++# else ++const uptr kAllocatorSpace = 0x500000000000ULL; ++const uptr kAllocatorSize = 0x40000000000ULL; // 4T. ++typedef DefaultSizeClassMap SizeClassMap; ++# endif + template + struct AP64 { // Allocator64 parameters. Deliberately using a short name. + static const uptr kSpaceBeg = kAllocatorSpace; diff --git a/gcc-bolt/gcc-ada-repro.patch b/gcc-bolt/gcc-ada-repro.patch new file mode 100644 index 00000000..66256369 --- /dev/null +++ b/gcc-bolt/gcc-ada-repro.patch @@ -0,0 +1,15 @@ +Avoid leaking current data on generated file for Ada. + +Index: gcc/ada/gcc-interface/Makefile.in +=================================================================== +--- gcc/ada/gcc-interface/Makefile.in (revision 268977) ++++ gcc/ada/gcc-interface/Makefile.in (working copy) +@@ -2407,6 +2407,7 @@ $(RTSDIR)/s-oscons.ads: ../stamp-gnatlib + $(OSCONS_CPP) ; \ + $(OSCONS_EXTRACT) ; \ + ../bldtools/oscons/xoscons s-oscons) ++ touch -r $(fsrcpfx)ada/gsocket.h $@ + + gnatlib: ../stamp-gnatlib1-$(RTSDIR) ../stamp-gnatlib2-$(RTSDIR) $(RTSDIR)/s-oscons.ads + test -f $(RTSDIR)/s-oscons.ads || exit 1 + diff --git a/gcc-bolt/tune-inline.patch b/gcc-bolt/tune-inline.patch new file mode 100644 index 00000000..a89366d9 --- /dev/null +++ b/gcc-bolt/tune-inline.patch @@ -0,0 +1,11 @@ +--- gcc-10.2.0/gcc/params.opt~ 2020-07-23 06:35:17.000000000 +0000 ++++ gcc-10.2.0/gcc/params.opt 2020-09-10 20:54:20.249498992 +0000 +@@ -183,7 +183,7 @@ + The minimal estimated speedup allowing inliner to ignore inline-insns-single and inline-insns-auto. + + -param=inline-unit-growth= +-Common Joined UInteger Var(param_inline_unit_growth) Init(40) Optimization Param ++Common Joined UInteger Var(param_inline_unit_growth) Init(80) Optimization Param + How much can given compilation unit grow because of the inlining (in percent). + + -param=integer-share-limit=