buildroot/boot
Julien Olivain 248c2d045e boot/arm-trusted-firmware: add -no-pie to LDFLAGS
Arm Trusted Firmware (TF-A) v2.11 fails to build in some situations
with the error message:

    ld: build/qemu/release/bl1/bl1.elf: error: PHDR segment not covered by LOAD segment

This error can be reproduced with the commands:

    make qemu_aarch64_ebbr_defconfig
    utils/config --set-str BR2_TARGET_ARM_TRUSTED_FIRMWARE_CUSTOM_VERSION_VALUE v2.11
    make olddefconfig
    make

This issue was reported in [1].

This error is coming from a check that was made more strict since
binutils ld 2.34. This error message is normally related to dynamic
linker, so it should normally not apply to a package like TF-A.

When BR2_SHARED_LIBS=y (shared libraries only) and BR2_PIC_PIE=y
(Build code with PIC/PIE), the Buildroot toolchain-wrapper will try
to enable position-independent code/executables. See [2]. This
configuration is a common default.

Arm Trusted Firmware (TF-A) build system, on its side, tries to detect
if the toolchain enables PIE automatically. It does so by checking if
--enable-default-pie is in the output of "$(CC) -v". If found, the TF-A
build system tries to disable PIE globally (it can be explicitly
enabled again with the ENABLE_PIE=1 build variable, in some specific
configurations). This detection mechanism is not working with the
Buildroot toolchain wrapper which is enabling PIE silently. See [3].

Commit 1061ed6c "boot/arm-trusted-firmware: add -fno-PIE to CFLAGS"
added the option -fno-PIE in CFLAGS for that reason. See [4].
TF-A >= v2.11 now needs the same treatment for LDFLAGS. This is
because TF-A switched the default linker from "ld" to "gcc", in
upstream commit [5]. This change makes the Buildroot toolchain wrapper
to enable PIE at link, without passing the "--no-dynamic-linker" option
that would normally avoids this ld error.

Also, even if there is no defconfigs using the
BR2_TARGET_ARM_TRUSTED_FIRMWARE_LATEST_VERSION config directive, it is
worth mentioning that the Buildroot TF-A "latest version" was updated
to v2.11 in commit 9c50759cd "boot/arm-trusted-firmware: bump to
v2.11". See [6]. This latest version is the default choice. So
Buildroot is subject to generate this build failure. This can be
reproduced with the commands:

    cat <<EOF >.config
    BR2_aarch64=y
    BR2_TARGET_ARM_TRUSTED_FIRMWARE=y
    BR2_TARGET_ARM_TRUSTED_FIRMWARE_PLATFORM="qemu"
    BR2_TOOLCHAIN_EXTERNAL=y
    EOF
    make olddefconfig
    make arm-trusted-firmware

This commit fixes the issue by adding the option "-no-pie" in LDFLAGS.
This will prevent the Buildroot toolchain wrapper to enable PIE, for
versions using "gcc" as a linker. This change should also remain
compatible with older TF-A < 2.11 using "ld" as a linker, since
"-no-pie" is also a valid ld option.

Fixes:

    ld: build/qemu/release/bl1/bl1.elf: error: PHDR segment not covered by LOAD segment

[1] https://github.com/TrustedFirmware-A/trusted-firmware-a/issues/26
[2] https://gitlab.com/buildroot.org/buildroot/-/blob/2024.08-rc3/toolchain/toolchain-wrapper.c?ref_type=tags#L403
[3] https://git.trustedfirmware.org/plugins/gitiles/TF-A/trusted-firmware-a.git/+/refs/tags/v2.11.0/Makefile#711
[4] 1061ed6c62
[5] 2f1c5e7eb1%5E%21/
[6] 9c50759cd1

Reported-by: Vincent Stehlé <vincent.stehle@arm.com>
Tested-by: Vincent Stehlé <vincent.stehle@arm.com>
Signed-off-by: Julien Olivain <ju.o@free.fr>
Signed-off-by: Yann E. MORIN <yann.morin.1998@free.fr>
2024-09-03 23:58:40 +02:00
..
afboot-stm32 boot/afboot-stm32: disable stack-protector 2023-02-08 16:54:35 +01:00
arm-trusted-firmware boot/arm-trusted-firmware: add -no-pie to LDFLAGS 2024-09-03 23:58:40 +02:00
at91bootstrap3 boot/at91bootstrap3: add svn repository method 2021-12-30 17:36:45 +01:00
barebox boot/barebox/Config.in: source argument needs quotation marks 2024-05-06 20:59:26 +02:00
binaries-marvell boot, package, support, toolchain: switch to 2 spaces for the hash file 2022-07-28 23:05:23 +02:00
boot-wrapper-aarch64 boot/boot-wrapper-aarch64: bump version 2023-02-23 23:43:32 +01:00
edk2 {boot, package}: update hashes for generated archives 2024-05-09 22:45:11 +02:00
grub2 boot/grub2: ignore CVE-2023-4001 2024-08-23 16:27:30 +02:00
mv-ddr-marvell boot/mv-ddr-marvell: fix build with gcc 12 2023-08-12 16:23:21 +02:00
mxs-bootlets boot/mxs-bootlets: fix build without any bootstream 2023-02-27 17:03:15 +01:00
opensbi boot/opensbi: Bump to version 1.3 2023-06-26 19:02:49 +02:00
optee-os boot/optee-os: bump to 4.3.0 2024-07-23 10:50:55 +02:00
s500-bootloader boot, package, support, toolchain: switch to 2 spaces for the hash file 2022-07-28 23:05:23 +02:00
shim boot/shim: force arm mode instead of Thumb mode 2024-03-01 19:05:28 +01:00
syslinux boot/syslinux: fix building with GCC 14.x 2024-07-10 22:20:25 +02:00
ti-k3-boot-firmware boot/ti-k3-boot-firmware: bump to version 09.02.00.009 2024-05-06 22:04:51 +02:00
ti-k3-r5-loader boot/ti-k3-r5-loader: share download files with uboot 2024-07-12 17:18:48 +02:00
uboot boot/uboot: use $(TARGET_OBJCOPY) for ZynqMP pmufw.elf 2024-08-19 22:29:27 +02:00
vexpress-firmware {boot, package}: update hashes for generated archives 2024-05-09 22:45:11 +02:00
xilinx-prebuilt boot/xilinx-prebuilt: support future AMD Vivado versions 2024-07-29 19:43:16 +02:00
common.mk Fix build reproducibility in Make 3.82 2013-09-06 23:27:42 +02:00
Config.in boot/beaglev-ddrinit: remove package 2024-07-13 16:53:04 +02:00