Skip to content

Commit 0562e3a

Browse files
rpardiniigorpecovnik
authored andcommitted
atf: once again no-warn-rwx-segment woes
- turns out everybody was wrong, including me - some (older?) ATF sources won't work, ever; thus - introduce ATF_SKIP_LDFLAGS=yes to skip it completely - introduce ATF_SKIP_LDFLAGS_WL=yes to only skip the `-Wl,` prefix - this is for ATF's that pass flag directly to linker, not gcc - artifact-uboot: hash atf-building code into artifact version
1 parent f60c1dc commit 0562e3a

File tree

2 files changed

+34
-9
lines changed

2 files changed

+34
-9
lines changed

lib/functions/artifacts/artifact-uboot.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,10 @@ function artifact_uboot_prepare_version() {
8080
declare hash_hooks="undetermined"
8181
hash_hooks="$(echo "${extension_hooks_hashed[@]}" | sha256sum | cut -d' ' -f1)"
8282

83-
# Hash the old-timey hooks
83+
# Hash the old-timey hooks and regular core functions (atf code, used by u-boot build process)
8484
declare hash_functions="undetermined"
85-
calculate_hash_for_function_bodies "uboot_custom_postprocess" "write_uboot_platform" "write_uboot_platform_mtd" "setup_write_uboot_platform"
85+
calculate_hash_for_function_bodies "uboot_custom_postprocess" "write_uboot_platform" "write_uboot_platform_mtd" \
86+
"setup_write_uboot_platform" "compile_atf"
8687
declare hash_uboot_functions="${hash_functions}"
8788

8889
# Hash those two together

lib/functions/compilation/atf.sh

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,38 @@ compile_atf() {
6666

6767
# - "--no-warn-rwx-segment" is *required* for binutils 2.39 - see https://developer.trustedfirmware.org/T996
6868
# - but *not supported* by 2.38, brilliant...
69-
declare binutils_version binutils_flags_atf=""
70-
binutils_version=$(env PATH="${toolchain}:${toolchain2}:${PATH}" aarch64-linux-gnu-ld.bfd --version | head -1 | cut -d ")" -f 2 | xargs echo -n)
71-
display_alert "Binutils version for ATF" "${binutils_version}" "info"
72-
73-
if linux-version compare "${binutils_version}" gt "2.39" && linux-version compare "${binutils_version}" lt "2.42"; then
74-
display_alert "Binutils version for ATF" ">= 2.39 and < 2.42, adding -Wl,--no-warn-rwx-segment" "info"
75-
binutils_flags_atf="--no-warn-rwx-segment"
69+
# 2026: turns out that *gcc* is the one that takes the flag, and it might or not accept it.
70+
# distros patch binutils and gcc independently, since it's a security-related flag,
71+
# might have been backported to one and not the other. what a freaking life.
72+
# test both -- and only add it if _both_ support it
73+
function gcc_accepts_flag() {
74+
{ echo 'int main(){}' | "${ATF_COMPILER}gcc" -Wl,"$1" -x c - -o /dev/null > /dev/null 2>&1; } && return 0
75+
return 1
76+
}
77+
function ld_supports_flag() {
78+
{ "$("${ATF_COMPILER}gcc" -print-prog-name=ld)" --help 2> /dev/null | grep -q -- "$1"; } && return 0
79+
return 1
80+
}
81+
if gcc_accepts_flag --no-warn-rwx-segment; then
82+
display_alert "GCC supports '--no-warn-rwx-segment'" "gcc:yes - ld:tba" "debug"
83+
if ld_supports_flag no-warn-rwx-segment; then
84+
display_alert "GCC/LD supports '--no-warn-rwx-segment'" "gcc:yes - ld:yes" "debug"
85+
if [[ "${ATF_SKIP_LDFLAGS:-"no"}" == "yes" ]]; then # IF ATF_SKIP_LDFLAGS==yes, then skip it completely
86+
display_alert "Skip adding LD flag '--no-warn-rwx-segment' to TF-A build" "ATF_SKIP_LDFLAGS=${ATF_SKIP_LDFLAGS}" "info"
87+
elif [[ "${ATF_SKIP_LDFLAGS_WL:-"no"}" == "yes" ]]; then # IF ATF_SKIP_LDFLAGS_WL==yes, then don't add the -Wl, prefix
88+
display_alert "Skip adding '-Wl,' prefix to LD flag '--no-warn-rwx-segment' for TF-A build" "ATF_SKIP_LDFLAGS_WL=${ATF_SKIP_LDFLAGS_WL}" "info"
89+
binutils_flags_atf="--no-warn-rwx-segment"
90+
else
91+
display_alert "Adding full LD flag '-Wl,--no-warn-rwx-segment' to TF-A build" "normal" "info"
92+
binutils_flags_atf="-Wl,--no-warn-rwx-segment"
93+
fi
94+
else
95+
display_alert "LD does not support '--no-warn-rwx-segment'" "gcc: yes - ld:no" "debug"
96+
fi
97+
else
98+
display_alert "GCC does not support '--no-warn-rwx-segment'" "gcc: no - ld: not tested" "debug"
7699
fi
100+
unset -f gcc_accepts_flag ld_supports_flag
77101

78102
# - ENABLE_BACKTRACE="0" has been added to workaround a regression in ATF. Check: https://github.com/armbian/build/issues/1157
79103

0 commit comments

Comments
 (0)