From feb38c43f2b398a7509c2d65d1c08c9457dc1f6f Mon Sep 17 00:00:00 2001 From: cuiziwei Date: Tue, 19 Nov 2024 16:55:23 +0800 Subject: [PATCH] sim/m64: Fix ld error. /usr/bin/ld: nuttx.rel: relocation R_X86_64_32S against `.rodata' can not be used when making a PIE object; recompile with -fPIE /usr/bin/ld: failed to set dynamic section sizes: bad value Signed-off-by: cuiziwei --- arch/sim/src/cmake/Toolchain.cmake | 3 +++ boards/sim/sim/sim/scripts/Make.defs | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/arch/sim/src/cmake/Toolchain.cmake b/arch/sim/src/cmake/Toolchain.cmake index 9ce379bd48a3e..5c11be68a620e 100644 --- a/arch/sim/src/cmake/Toolchain.cmake +++ b/arch/sim/src/cmake/Toolchain.cmake @@ -179,6 +179,9 @@ endif() if(CONFIG_SIM_M32) add_compile_options(-m32) add_link_options(-m32) +elseif(NOT CONFIG_HOST_MACOS) + add_compile_options(-no-pie) + add_link_options(-Wl,-no-pie) endif() if(CONFIG_LIBCXX) diff --git a/boards/sim/sim/sim/scripts/Make.defs b/boards/sim/sim/sim/scripts/Make.defs index db49e7da2c593..98eced7bd50bf 100644 --- a/boards/sim/sim/sim/scripts/Make.defs +++ b/boards/sim/sim/sim/scripts/Make.defs @@ -322,6 +322,12 @@ ifeq ($(CONFIG_SIM_M32),y) LDMODULEFLAGS += -melf_i386 SHMODULEFLAGS += -melf_i386 LDELFFLAGS += -melf_i386 +else ifeq ($(CONFIG_HOST_MACOS),) + # To compile 64-bit Sim, adding no-pie is necessary to prevent linking errors + # but this may cause other issues on Ubuntu 20. + ARCHCFLAGS += -no-pie + ARCHPICFLAGS += -no-pie + LDFLAGS += -Wl,-no-pie endif ifeq ($(CONFIG_HOST_LINUX),y)