From c103ef655d3f1844ee6ee0d66bd5162505ad2bd4 Mon Sep 17 00:00:00 2001 From: Jian Jun Chen Date: Thu, 11 Sep 2025 14:08:42 +0800 Subject: [PATCH] hv: riscv: specifiy -fpie / -fno-pie explicitly Without -fpie or -fno-pie specified in the CFLAGS and ASFLAGS, different versions of riscv64-linux-gnu-gcc have different behavior, for example, Ubuntu 13.3.0-6ubuntu2~24.04 will compile as if -fpie, but 15.1.0 will compile as if -fno-pie. To make the build consistent specify -fpie when CONFIG_RELOC=y and -fno-pie otherwize explicitly. Tracked-On: #8791 Signed-off-by: Jian Jun Chen Acked-by: Wang, Yu1 --- hypervisor/arch/riscv/Makefile | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/hypervisor/arch/riscv/Makefile b/hypervisor/arch/riscv/Makefile index 5d9ff4803..af4d7c2ac 100644 --- a/hypervisor/arch/riscv/Makefile +++ b/hypervisor/arch/riscv/Makefile @@ -14,6 +14,15 @@ ASFLAGS += LDFLAGS += -Wl,--no-warn-rwx-segments +ifeq (y, $(CONFIG_RELOC)) +# -fpie is already added into CFLAGS in common Makefile +#CFLAGS += -fpie +ASFLAGS += -fpie +else +CFLAGS += -fno-pie +ASFLAGS += -fno-pie +endif + # g expands to i, m, a, f, d, zicsr and zifencei. # h for hypervisor extension RV_ISA += gh