This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 7e342b3422 arch: Add --whole-archive linker option for some of
architectures
7e342b3422 is described below
commit 7e342b34220aac8ccee67ccebb298bbf5e0bfe3f
Author: yanghuatao <[email protected]>
AuthorDate: Thu Jun 27 16:59:08 2024 +0200
arch: Add --whole-archive linker option for some of architectures
Add Kconfig option that enable --whole-archive linker option for some of
architectures
Signed-off-by: yanghuatao <[email protected]>
---
Kconfig | 8 ++++++++
arch/arm/src/cmake/Toolchain.cmake | 6 ++++++
arch/arm/src/common/Toolchain.defs | 6 ++++++
arch/arm64/src/Toolchain.defs | 6 ++++++
arch/mips/src/mips32/Toolchain.defs | 6 ++++++
arch/risc-v/src/cmake/Toolchain.cmake | 6 ++++++
arch/risc-v/src/common/Toolchain.defs | 6 ++++++
arch/xtensa/src/lx6/Toolchain.defs | 6 ++++++
arch/xtensa/src/lx7/Toolchain.defs | 6 ++++++
arch/z80/src/ez80/Toolchain.defs | 6 ++++++
10 files changed, 62 insertions(+)
diff --git a/Kconfig b/Kconfig
index 43a53357af..0550e05c99 100644
--- a/Kconfig
+++ b/Kconfig
@@ -2483,6 +2483,14 @@ config DEBUG_OPT_UNUSED_SECTIONS
linker by compiling with " -ffunction-sections -fdata-sections
", and
linking with " --gc-sections ".
+config DEBUG_LINK_WHOLE_ARCHIVE
+ bool "Force every object to be included in the resulting shared
library."
+ default n
+ depends on DEBUG_OPT_UNUSED_SECTIONS
+ ---help---
+ Selecting this option will pass "--whole-archive" to ld
+ when linking NuttX ELF.
+
config DEBUG_LINK_MAP
bool "Generate link map file"
default y
diff --git a/arch/arm/src/cmake/Toolchain.cmake
b/arch/arm/src/cmake/Toolchain.cmake
index 0db1429891..546ce8e7df 100644
--- a/arch/arm/src/cmake/Toolchain.cmake
+++ b/arch/arm/src/cmake/Toolchain.cmake
@@ -157,6 +157,12 @@ if(CONFIG_DEBUG_OPT_UNUSED_SECTIONS)
add_compile_options(-ffunction-sections -fdata-sections)
endif()
+# Debug --whole-archive
+
+if(CONFIG_DEBUG_LINK_WHOLE_ARCHIVE)
+ add_link_options(-Wl,--whole-archive)
+endif()
+
if(CONFIG_ENDIAN_BIG)
add_compile_options(-mbig-endian)
endif()
diff --git a/arch/arm/src/common/Toolchain.defs
b/arch/arm/src/common/Toolchain.defs
index e64f23f95a..019fd852a4 100644
--- a/arch/arm/src/common/Toolchain.defs
+++ b/arch/arm/src/common/Toolchain.defs
@@ -351,6 +351,12 @@ ifeq ($(CONFIG_ARM_TOOLCHAIN_ARMCLANG),)
endif
endif
+# Debug --whole-archive
+
+ifeq ($(CONFIG_DEBUG_LINK_WHOLE_ARCHIVE),y)
+ LDFLAGS += --whole-archive
+endif
+
# Debug link map
ifeq ($(CONFIG_DEBUG_LINK_MAP),y)
diff --git a/arch/arm64/src/Toolchain.defs b/arch/arm64/src/Toolchain.defs
index 015622af49..162d4fd411 100644
--- a/arch/arm64/src/Toolchain.defs
+++ b/arch/arm64/src/Toolchain.defs
@@ -137,6 +137,12 @@ ifeq ($(CONFIG_DEBUG_OPT_UNUSED_SECTIONS),y)
ARCHOPTIMIZATION += -ffunction-sections -fdata-sections
endif
+# Debug --whole-archive
+
+ifeq ($(CONFIG_DEBUG_LINK_WHOLE_ARCHIVE),y)
+ LDFLAGS += --whole-archive
+endif
+
# Debug link map
ifeq ($(CONFIG_DEBUG_LINK_MAP),y)
diff --git a/arch/mips/src/mips32/Toolchain.defs
b/arch/mips/src/mips32/Toolchain.defs
index 92853e5880..24cc5a9746 100644
--- a/arch/mips/src/mips32/Toolchain.defs
+++ b/arch/mips/src/mips32/Toolchain.defs
@@ -249,6 +249,12 @@ ifeq ($(CONFIG_DEBUG_OPT_UNUSED_SECTIONS),y)
ARCHOPTIMIZATION += -ffunction-sections -fdata-sections
endif
+# Debug --whole-archive
+
+ifeq ($(CONFIG_DEBUG_LINK_WHOLE_ARCHIVE),y)
+ LDFLAGS += --whole-archive
+endif
+
# Debug link map
ifeq ($(CONFIG_DEBUG_LINK_MAP),y)
diff --git a/arch/risc-v/src/cmake/Toolchain.cmake
b/arch/risc-v/src/cmake/Toolchain.cmake
index fb0e9d1db5..6185d19592 100644
--- a/arch/risc-v/src/cmake/Toolchain.cmake
+++ b/arch/risc-v/src/cmake/Toolchain.cmake
@@ -197,6 +197,12 @@ if(CONFIG_DEBUG_OPT_UNUSED_SECTIONS)
add_compile_options(-ffunction-sections -fdata-sections)
endif()
+# Debug --whole-archive
+
+if(CONFIG_DEBUG_LINK_WHOLE_ARCHIVE)
+ add_link_options(-Wl,--whole-archive)
+endif()
+
add_link_options(-nostdlib)
add_link_options(-Wl,--entry=__start)
diff --git a/arch/risc-v/src/common/Toolchain.defs
b/arch/risc-v/src/common/Toolchain.defs
index ca7f8de05d..448a6baea3 100644
--- a/arch/risc-v/src/common/Toolchain.defs
+++ b/arch/risc-v/src/common/Toolchain.defs
@@ -137,6 +137,12 @@ endif
LDFLAGS += -nostdlib
ARCHOPTIMIZATION += -nostdlib
+# Debug --whole-archive
+
+ifeq ($(CONFIG_DEBUG_LINK_WHOLE_ARCHIVE),y)
+ LDFLAGS += --whole-archive
+endif
+
# Debug link map
ifeq ($(CONFIG_DEBUG_LINK_MAP),y)
diff --git a/arch/xtensa/src/lx6/Toolchain.defs
b/arch/xtensa/src/lx6/Toolchain.defs
index a02d98e147..7f5d7e9f19 100644
--- a/arch/xtensa/src/lx6/Toolchain.defs
+++ b/arch/xtensa/src/lx6/Toolchain.defs
@@ -149,6 +149,12 @@ ifeq ($(CONFIG_DEBUG_LINK_MAP),y)
LDFLAGS += --cref -Map=$(call CONVERT_PATH,$(TOPDIR)$(DELIM)nuttx.map)
endif
+# Debug --whole-archive
+
+ifeq ($(CONFIG_DEBUG_LINK_WHOLE_ARCHIVE),y)
+ LDFLAGS += --whole-archive
+endif
+
ifeq ($(CONFIG_DEBUG_SYMBOLS),y)
ARCHOPTIMIZATION += -g
endif
diff --git a/arch/xtensa/src/lx7/Toolchain.defs
b/arch/xtensa/src/lx7/Toolchain.defs
index e4a2b10b28..cf3347a3dc 100644
--- a/arch/xtensa/src/lx7/Toolchain.defs
+++ b/arch/xtensa/src/lx7/Toolchain.defs
@@ -147,6 +147,12 @@ ifeq ($(CONFIG_DEBUG_OPT_UNUSED_SECTIONS),y)
ARCHOPTIMIZATION += -ffunction-sections -fdata-sections
endif
+# Debug --whole-archive
+
+ifeq ($(CONFIG_DEBUG_LINK_WHOLE_ARCHIVE),y)
+ LDFLAGS += --whole-archive
+endif
+
# Debug link map
ifeq ($(CONFIG_DEBUG_LINK_MAP),y)
diff --git a/arch/z80/src/ez80/Toolchain.defs b/arch/z80/src/ez80/Toolchain.defs
index 0d0a98866b..03d55a7b26 100644
--- a/arch/z80/src/ez80/Toolchain.defs
+++ b/arch/z80/src/ez80/Toolchain.defs
@@ -79,6 +79,12 @@ ifeq ($(CONFIG_DEBUG_OPT_UNUSED_SECTIONS),y)
ARCHOPTIMIZATION += -ffunction-sections -fdata-sections
endif
+# Debug --whole-archive
+
+ifeq ($(CONFIG_DEBUG_LINK_WHOLE_ARCHIVE),y)
+ LDFLAGS += --whole-archive
+endif
+
# Debug link map
ifeq ($(CONFIG_DEBUG_LINK_MAP),y)