From e48451db92cf84f1ae045db0dc79398d01e8ee75 Mon Sep 17 00:00:00 2001 From: Mingcong Bai Date: Sat, 2 Aug 2025 00:22:34 +0800 Subject: [PATCH 1/6] arch: enable packed relative relocation via DT_RELR This feature is supported by Binutils on amd64, arm64, loongarch64, and ppc64el. --- arch/amd64.sh | 1 + arch/arm64.sh | 1 + arch/loongarch64.sh | 1 + arch/ppc64el.sh | 1 + 4 files changed, 4 insertions(+) diff --git a/arch/amd64.sh b/arch/amd64.sh index d2edc3e..2b77e46 100644 --- a/arch/amd64.sh +++ b/arch/amd64.sh @@ -9,6 +9,7 @@ HWCAPS=('x86-64-v2' 'x86-64-v3' 'x86-64-v4') # Default -march and μarch specific tuning. # No need to reference CFLAGS_COMMON_ARCH_BASE, it will be concatenated. CFLAGS_COMMON_ARCH=('-march=x86-64' '-mtune=znver4' '-msse2' '-mno-omit-leaf-frame-pointer') +LDFLAGS_COMMON_ARCH=('-Wl,-z,pack-relative-relocs') RUSTFLAGS_COMMON_ARCH=('-Ctarget-cpu=x86-64') # HWCAPS subtargets in x86-64 are based on the microarchitecture levels diff --git a/arch/arm64.sh b/arch/arm64.sh index fefa2b7..a6e6020 100644 --- a/arch/arm64.sh +++ b/arch/arm64.sh @@ -2,5 +2,6 @@ ##arch/arm64.sh: Build definitions for arm64. ##@copyright GPL-2.0+ CFLAGS_COMMON_ARCH=('-march=armv8-a' '-mtune=generic' '-mno-omit-leaf-frame-pointer') +LDFLAGS_COMMON_ARCH=('-Wl,-z,pack-relative-relocs') RUSTFLAGS_COMMON_ARCH=('-Ctarget-cpu=generic') # LDFLAGS_COMMON_CROSS=('-Wl,-rpath -Wl,/usr/lib -Wl,-rpath-link -Wl,/var/ab/cross-root/arm64/usr/lib -L/var/ab/cross-root/arm64/usr/lib ') diff --git a/arch/loongarch64.sh b/arch/loongarch64.sh index eb77c41..e0c6cc5 100644 --- a/arch/loongarch64.sh +++ b/arch/loongarch64.sh @@ -33,4 +33,5 @@ else CFLAGS_COMMON_ARCH+=('-march=loongarch64' '-mtune=la464') fi +LDFLAGS_COMMON_ARCH=('-Wl,-z,pack-relative-relocs') RUSTFLAGS_COMMON_ARCH=('-Ctarget-cpu=generic-la64' '-Ctarget-feature=+lsx,+d' '-Clink-arg=-mabi=lp64d') diff --git a/arch/ppc64el.sh b/arch/ppc64el.sh index 2cf039a..11442b7 100644 --- a/arch/ppc64el.sh +++ b/arch/ppc64el.sh @@ -2,6 +2,7 @@ ##arch/ppc64el.sh: Build definitions for ppc64el. ##@copyright GPL-2.0+ CFLAGS_COMMON_ARCH_BASE=('-msecure-plt' '-mabi=ieeelongdouble') +LDFLAGS_COMMON_ARCH=('-Wl,-z,pack-relative-relocs') CFLAGS_COMMON_ARCH=('-mcpu=power8' '-mtune=power10' '-mvsx') RUSTFLAGS_COMMON_ARCH=('-Ctarget-cpu=pwr8' '-Ctarget-feature=+vsx,+altivec,+secure-plt' '-Clink-arg=-mabi=ieeelongdouble') From 8111009309f78cefc50fda65b1e1303c2787f140 Mon Sep 17 00:00:00 2001 From: Mingcong Bai Date: Mon, 18 Aug 2025 16:52:00 +0800 Subject: [PATCH 2/6] arch/_common_switches.sh: append -O2 if AB_FLAGS_FTF is enabled -D_FORTIFY_SOURCE requires optimisation (-O) and may cause build failures if a build system passes only CPPFLAGS but not C/CXXFLAGS (i.e., Binutils and GCC, and we are not sure if this has caused further silent failures elsewhere). Since it would not do much harm to pass our lowest optimisation level on its own, pass -O2 as part of the AB_FLAGS_FTF condition. --- arch/_common_switches.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/_common_switches.sh b/arch/_common_switches.sh index 3143c89..35060f4 100644 --- a/arch/_common_switches.sh +++ b/arch/_common_switches.sh @@ -5,7 +5,7 @@ if ((AB_FLAGS_SSP)); then CFLAGS_COMMON+=('-fstack-protector-strong' '--param=ss if ((AB_FLAGS_SCP)); then CFLAGS_GCC_COMMON+=('-fstack-clash-protection'); fi if ((AB_FLAGS_RRO)); then LDFLAGS_COMMON+=('-Wl,-z,relro'); fi if ((AB_FLAGS_NOW)); then LDFLAGS_COMMON+=('-Wl,-z,now'); fi -if ((AB_FLAGS_FTF)); then CPPFLAGS_COMMON+=('-U_FORTIFY_SOURCE' '-D_FORTIFY_SOURCE=3'); fi +if ((AB_FLAGS_FTF)); then CPPFLAGS_COMMON+=('-U_FORTIFY_SOURCE' '-D_FORTIFY_SOURCE=3' '-O2'); fi if ((AB_FLAGS_SPECS)); then CFLAGS_GCC_OPTI+=('-specs=/usr/lib/gcc/specs/hardened-cc1'); fi if ((AB_FLAGS_O3)); then CFLAGS_COMMON_OPTI="${CFLAGS_COMMON_OPTI/O2/O3}"; fi if ((AB_FLAGS_OS)); then CFLAGS_COMMON_OPTI="${CFLAGS_COMMON_OPTI/O2/Os}"; fi From 503cd25201c86a3dde0c2400086509b944d928e4 Mon Sep 17 00:00:00 2001 From: Xinhui Yang Date: Sat, 4 Oct 2025 22:32:33 +0800 Subject: [PATCH 3/6] arch/_common.sh: add NOPERMISSIVE feature for C++ and ObjC++ --- arch/_common.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/_common.sh b/arch/_common.sh index 657ef47..1fb2c65 100644 --- a/arch/_common.sh +++ b/arch/_common.sh @@ -22,6 +22,7 @@ CFLAGS_COMMON_WEIRD=() CXXFLAGS_GCC_OPTI=("-fdeclone-ctor-dtor") CXXFLAGS_COMMON_WEIRD=() CXXFLAGS_COMMON_PERMISSIVE=("-fpermissive") +CXXFLAGS_COMMON_NOPERMISSIVE=("-fno-permissive") # Preprocesser Flags. CPPFLAGS_COMMON=("-D_GLIBCXX_ASSERTIONS") # OBJC Flags. @@ -29,6 +30,7 @@ OBJCFLAGS_COMMON_WEIRD=() # OBJCXX Flags. OBJCXXFLAGS_COMMON_WEIRD=() OBJCXXFLAGS_COMMON_PERMISSIVE=('-fpermissive') +OBJCXXFLAGS_COMMON_NOPERMISSIVE=('-fno-permissive') # RUST Flags. RUSTFLAGS_COMMON=() RUSTFLAGS_COMMON_OPTI=('-Ccodegen-units=1' '-Copt-level=3' '-Cdebuginfo=line-tables-only' '-Cforce-frame-pointers=yes') From 105e534ea714c8cbdf71ce2702373653385c05eb Mon Sep 17 00:00:00 2001 From: Xinhui Yang Date: Sat, 4 Oct 2025 22:32:56 +0800 Subject: [PATCH 4/6] proc/12-arch-flags: disable -fpermissive by default We choose to add NOPERMISSIVE instead of removing it completely, because plenty of (old) C++ projects requires this to build using newer GCC versions, such as ncurses (C++ bindings and implementation), and libstdc++ on some architectures. --- proc/12-arch-flags.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proc/12-arch-flags.sh b/proc/12-arch-flags.sh index cc703c0..59f1ba0 100644 --- a/proc/12-arch-flags.sh +++ b/proc/12-arch-flags.sh @@ -4,7 +4,7 @@ ab_arch_setflags() { - local AB_FLAGS_FEATURES=(LTO PERMISSIVE) + local AB_FLAGS_FEATURES=(LTO NOPERMISSIVE) local AB_FLAGS_TYPES=('' _OPTI _ARCH_BASE _ARCH) local flagtypes=(LDFLAGS CFLAGS CPPFLAGS CXXFLAGS OBJCFLAGS OBJCXXFLAGS RUSTFLAGS) local features=('') From 5f02918b2631e01eaa0f4096c55f64304066f906 Mon Sep 17 00:00:00 2001 From: Icenowy Zheng Date: Thu, 27 Nov 2025 18:18:31 +0800 Subject: [PATCH 5/6] arch/riscv64.sh: Disable emitting fence.tso on GCC 15+ GCC 15 introduces a new compiler flag, `-m{,no-}fence-tso`, to control the usage of `fence.tso` instruction (which is not supported on some old T-Head cores, such as the ones used on TH1520/SG2042). When it's disabled, more strong `fence rw,rw` is emitted and correctness is then not affected. Disable emitting this instruction now, because all buildbots of riscv64 are currently SG2042, and no CPU cores are known to benefit from `fence.tso` yet. Signed-off-by: Icenowy Zheng --- arch/riscv64.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arch/riscv64.sh b/arch/riscv64.sh index 8c08286..f6b0642 100644 --- a/arch/riscv64.sh +++ b/arch/riscv64.sh @@ -6,6 +6,10 @@ if ! bool "$USECLANG" && [ "$(echo __GNUC__ | $CC -E -xc - | tail -n 1)" -ge 14 ]; then CFLAGS_COMMON_ARCH=('-mno-omit-leaf-frame-pointer') fi +# `-mno-fence-tso` is only available on GCC >= 15 +if ! bool "$USECLANG" && [ "$(echo __GNUC__ | $CC -E -xc - | tail -n 1)" -ge 15 ]; then + CFLAGS_COMMON_ARCH+=('-mno-fence-tso') +fi LDFLAGS_CLANG_ARCH=('-fuse-ld=lld' '-Wl,-mllvm=-mattr=+rva20u64') LDFLAGS_COMMON_CROSS=('-Wl,-rpath -Wl,/usr/lib -Wl,-rpath-link' '-Wl,/var/ab/cross-root/riscv64/usr/lib' '-L/var/ab/cross-root/riscv64/usr/lib') RUSTFLAGS_COMMON_ARCH=("-Clink-arg=-mabi=lp64d") From b116af36b91ea79937fe4a434d8190a1e3f34bad Mon Sep 17 00:00:00 2001 From: Xinhui Yang Date: Sun, 30 Nov 2025 22:26:04 +0800 Subject: [PATCH 6/6] spiral: allow manually appending __AB_SONAMES This will be stored on a separated list and will be passed along with __AB_SONAMES for manually specifying sonames for Spiral. See core-devel/gcc/01-runtime/beyond for details. --- proc/53-spiral.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/proc/53-spiral.sh b/proc/53-spiral.sh index 688ff16..aad787b 100644 --- a/proc/53-spiral.sh +++ b/proc/53-spiral.sh @@ -4,8 +4,8 @@ if bool "$ABSPIRAL"; then __ABSPIRAL_PROVIDES=() - if [[ "${#__AB_SONAMES[@]}" != 0 ]]; then - abspiral_from_sonames "${__AB_SONAMES[@]}" + if [[ "${#__AB_SONAMES[@]}" != 0 ]] || [[ "${#__AB_SONAMES_MANUADD[@]}" != 0 ]]; then + abspiral_from_sonames "${__AB_SONAMES[@]}" "${__AB_SONAMES_MANUADD[@]}" for SPIRAL_PROV in "${__ABSPIRAL_PROVIDES_SONAMES[@]}"; do # Ignore architecture notation for duplication detection if [[ "${SPIRAL_PROV%%:*}" = "$PKGNAME" ]]; then