@@ -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