From ca268938737467947a77017197799cc63f310b5d Mon Sep 17 00:00:00 2001 From: Mingcong Bai Date: Sat, 2 Aug 2025 00:22:34 +0800 Subject: [PATCH 1/4] 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 28f2ec83e759c917859e5407aa3875a5c5a3356d Mon Sep 17 00:00:00 2001 From: Mingcong Bai Date: Mon, 18 Aug 2025 16:52:00 +0800 Subject: [PATCH 2/4] 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 a398681c849c78a5dc14ded687cd646507304a34 Mon Sep 17 00:00:00 2001 From: Xinhui Yang Date: Sat, 4 Oct 2025 22:32:33 +0800 Subject: [PATCH 3/4] 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 f92fce22f6a37adc19651dbb6b32b3ca3b65efbb Mon Sep 17 00:00:00 2001 From: Xinhui Yang Date: Sat, 4 Oct 2025 22:32:56 +0800 Subject: [PATCH 4/4] 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 9b40276..47781e8 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=('')