From 31f80efeefaee2c59db50a46cabe2b5fdf20e4ae Mon Sep 17 00:00:00 2001 From: Andrey Skvortsov Date: Fri, 8 Dec 2023 18:04:51 +0300 Subject: [PATCH] fix(build): enforce single partition for LTO build For example, build for PLAT=fvp SPD=spmd fails with a following error when LTO is enabled using GCC 13.2.1: aarch64-none-elf/bin/ld: /tmp/ccrG0Z8D.ltrans0.ltrans.o: in function `spmd_smc_forward': arm-trusted-firmware/services/std_svc/spmd/spmd_main.c:749:(.text+0xbe50): undefined reference to `rdist_ctx' aarch64-none-elf/bin/ld: arm-trusted-firmware/services/std_svc/spmd/spmd_main.c:749:(.text+0xbe58): undefined reference to `dist_ctx' collect2: error: ld returned 1 exit status Access to rdist_ctx and dist_ctx is defined using inline assembler like __asm__ volatile ("ldr %0, =rdist_ctx" : "=r" (v) : "X" (rdist_ctx)); Access assembler function definitions moved to a different ltrans then actual variables. Partitioner doesn't take into account defined and used symbols in inline assembler. Depending on compiler partitioner decision the same code builds for some platforms successfully. This is a known gcc problem 1. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57703 2. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=46820 TF-A source code isn't that big and enforcing single partitioning will not affect build performance, but will fix problems with 'undefined references' related to inline assembler. Change-Id: I72955ab0318f72b588d3a246824f99a48a92d8ef Signed-off-by: Andrey Skvortsov --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 2892f215a..4fc8a7045 100644 --- a/Makefile +++ b/Makefile @@ -325,6 +325,7 @@ else ifeq ($($(ARCH)-ld-id),gnu-gcc) ifeq ($(ENABLE_LTO),1) ifeq (${ARCH},aarch64) TF_LDFLAGS += -flto -fuse-linker-plugin + TF_LDFLAGS += -flto-partition=one endif endif #(ENABLE_LTO)