From b8b2ac4f2cc880359db7f821a53782b3061bb93c Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Wed, 1 Jul 2020 12:50:06 +0900 Subject: [PATCH] sim: Sync Linux CMODULEFLAGS with macOS Namely, always use -mcmodel=large. NuttX modules are loaded into the NuttX heap, which can be out of range for 32-bit relocations generated with -mcmodel=small. A possible alternative would be to use MAP_32BIT to allocate sim heap. But I prefer this approach because it's very convenient for me to be able to share modules between Linux and macOS sim. --- boards/sim/sim/sim/configs/cxxtest/Make.defs | 10 ++++++---- boards/sim/sim/sim/scripts/Make.defs | 10 ++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/boards/sim/sim/sim/configs/cxxtest/Make.defs b/boards/sim/sim/sim/configs/cxxtest/Make.defs index d689b5c0eb..b8b216a8ce 100644 --- a/boards/sim/sim/sim/configs/cxxtest/Make.defs +++ b/boards/sim/sim/sim/configs/cxxtest/Make.defs @@ -82,6 +82,12 @@ AFLAGS = $(CFLAGS) -D__ASSEMBLY__ CMODULEFLAGS = $(CFLAGS) # -fno-pic to avoid GOT relocations CMODULEFLAGS += -fno-pic +# It seems macOS/x86_64 loads the program text around 00000001_xxxxxxxx. +# The gcc default (-mcmodel=small) would produce out-of-range 32-bit +# relocations. +# Even on Linux, NuttX modules are loaded into the NuttX heap, which +# can be out of range with -mcmodel=small. +CMODULEFLAGS += -mcmodel=large LDMODULEFLAGS = -r -e module_initialize ifeq ($(CONFIG_CYGWIN_WINTOOL),y) @@ -97,10 +103,6 @@ ifeq ($(CONFIG_HOST_MACOS),y) MODULECC = x86_64-elf-gcc MODULELD = x86_64-elf-ld MODULESTRIP = x86_64-elf-strip --strip-unneeded - # It seems macOS/x86_64 loads the program text around 00000001_xxxxxxxx. - # The gcc default (-mcmodel=small) would produce out-of-range 32-bit - # relocations. - CMODULEFLAGS += -mcmodel=large endif # ELF module definitions diff --git a/boards/sim/sim/sim/scripts/Make.defs b/boards/sim/sim/sim/scripts/Make.defs index d2dca0bf6b..431fe24427 100644 --- a/boards/sim/sim/sim/scripts/Make.defs +++ b/boards/sim/sim/sim/scripts/Make.defs @@ -77,6 +77,12 @@ AFLAGS = $(CFLAGS) -D__ASSEMBLY__ CMODULEFLAGS = $(CFLAGS) # -fno-pic to avoid GOT relocations CMODULEFLAGS += -fno-pic +# It seems macOS/x86_64 loads the program text around 00000001_xxxxxxxx. +# The gcc default (-mcmodel=small) would produce out-of-range 32-bit +# relocations. +# Even on Linux, NuttX modules are loaded into the NuttX heap, which +# can be out of range with -mcmodel=small. +CMODULEFLAGS += -mcmodel=large LDMODULEFLAGS = -r -e module_initialize ifeq ($(CONFIG_CYGWIN_WINTOOL),y) @@ -92,10 +98,6 @@ ifeq ($(CONFIG_HOST_MACOS),y) MODULECC = x86_64-elf-gcc MODULELD = x86_64-elf-ld MODULESTRIP = x86_64-elf-strip --strip-unneeded - # It seems macOS/x86_64 loads the program text around 00000001_xxxxxxxx. - # The gcc default (-mcmodel=small) would produce out-of-range 32-bit - # relocations. - CMODULEFLAGS += -mcmodel=large endif # ELF module definitions