From 2dd979b2ae124a2603da47896d7f23ce978b2aca Mon Sep 17 00:00:00 2001 From: cuiziwei Date: Fri, 11 Oct 2024 23:48:31 +0800 Subject: [PATCH] Add GCCVER define to Toolchain.cmake Since GCCVER will also be used in the toolchain, it needs to be defined in advance. Signed-off-by: cuiziwei --- arch/arm/src/cmake/gcc.cmake | 22 ++++++++++++---------- arch/arm/src/common/Toolchain.defs | 23 ++++++++++++++--------- arch/arm64/src/Toolchain.defs | 8 +++++++- arch/arm64/src/cmake/Toolchain.cmake | 11 ++++++++++- arch/risc-v/Kconfig | 2 +- arch/risc-v/src/cmake/Toolchain.cmake | 11 ++++++++++- arch/risc-v/src/common/Toolchain.defs | 10 +++++++++- libs/libxx/libcxx.cmake | 8 ++++++++ libs/libxx/libcxx.defs | 4 ++++ tools/Config.mk | 5 ----- 10 files changed, 75 insertions(+), 29 deletions(-) diff --git a/arch/arm/src/cmake/gcc.cmake b/arch/arm/src/cmake/gcc.cmake index e4e91e3198623..1ebc6a2dfe316 100644 --- a/arch/arm/src/cmake/gcc.cmake +++ b/arch/arm/src/cmake/gcc.cmake @@ -62,16 +62,18 @@ endif() # array subscript [0] is outside array bounds: # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105523 -execute_process(COMMAND ${CMAKE_C_COMPILER} --version - OUTPUT_VARIABLE GCC_VERSION_OUTPUT) -string(REGEX MATCH "\\+\\+.* ([0-9]+)\\.[0-9]+" GCC_VERSION_REGEX - "${GCC_VERSION_OUTPUT}") -set(GCCVER ${CMAKE_MATCH_1}) - -if(GCCVER GREATER_EQUAL 12) - add_compile_options(--param=min-pagesize=0) - if(CONFIG_ARCH_RAMFUNCS) - add_link_options(-Wl,--no-warn-rwx-segments) +if(CONFIG_ARCH_TOOLCHAIN_GNU) + execute_process(COMMAND ${CMAKE_C_COMPILER} --version + OUTPUT_VARIABLE GCC_VERSION_OUTPUT) + string(REGEX MATCH "\\+\\+.* ([0-9]+)\\.[0-9]+" GCC_VERSION_REGEX + "${GCC_VERSION_OUTPUT}") + set(GCCVER ${CMAKE_MATCH_1}) + + if(GCCVER GREATER_EQUAL 12) + add_compile_options(--param=min-pagesize=0) + if(CONFIG_ARCH_RAMFUNCS) + add_link_options(-Wl,--no-warn-rwx-segments) + endif() endif() endif() diff --git a/arch/arm/src/common/Toolchain.defs b/arch/arm/src/common/Toolchain.defs index 5548aec7e7cba..202d989051a2c 100644 --- a/arch/arm/src/common/Toolchain.defs +++ b/arch/arm/src/common/Toolchain.defs @@ -306,15 +306,20 @@ else endif # Workaround to skip -Warray-bounds check due to bug of GCC-12: - # Wrong warning array subscript [0] is outside array bounds: - # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105523 - - ifeq ($(shell expr "$(GCCVER)" \>= 12), 1) - ARCHOPTIMIZATION += --param=min-pagesize=0 - ifeq ($(CONFIG_ARCH_RAMFUNCS),y) - LDFLAGS += --no-warn-rwx-segments - endif - endif + # Wrong warning array subscript [0] is outside array bounds: + # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105523 + + ifeq ($(CONFIG_ARCH_TOOLCHAIN_GNU),y) + ifeq ($(GCCVER),) + export GCCVER := $(shell $(CC) --version | grep gcc | sed -E "s/.* ([0-9]+\.[0-9]+).*/\1/" | cut -d'.' -f1) + endif + ifeq ($(shell expr "$(GCCVER)" \>= 12), 1) + ARCHOPTIMIZATION += --param=min-pagesize=0 + ifeq ($(CONFIG_ARCH_RAMFUNCS),y) + LDFLAGS += --no-warn-rwx-segments + endif + endif + endif LDFLAGS += --entry=__start diff --git a/arch/arm64/src/Toolchain.defs b/arch/arm64/src/Toolchain.defs index 3cfc20ab5d252..d61f4c692f140 100644 --- a/arch/arm64/src/Toolchain.defs +++ b/arch/arm64/src/Toolchain.defs @@ -180,8 +180,14 @@ ifeq ($(CONFIG_LTO_FULL),y) endif endif +ifeq ($(GCCVER),) + export GCCVER := $(shell $(CC) --version | grep gcc | sed -E "s/.* ([0-9]+\.[0-9]+).*/\1/" | cut -d'.' -f1) +endif + ifeq ($(CONFIG_ARCH_TOOLCHAIN_GNU),y) - LDFLAGS += --no-warn-rwx-segments + ifeq ($(shell expr "$(GCCVER)" \>= 12), 1) + LDFLAGS += --no-warn-rwx-segments + endif endif # Add the builtin library diff --git a/arch/arm64/src/cmake/Toolchain.cmake b/arch/arm64/src/cmake/Toolchain.cmake index a8f9838ed1ec6..0da4b19fbbe88 100644 --- a/arch/arm64/src/cmake/Toolchain.cmake +++ b/arch/arm64/src/cmake/Toolchain.cmake @@ -190,5 +190,14 @@ if(CONFIG_DEBUG_SYMBOLS) endif() if(CONFIG_ARCH_TOOLCHAIN_GNU) - add_link_options(-Wl,--no-warn-rwx-segments) + if(NOT GCCVER) + execute_process(COMMAND ${CMAKE_C_COMPILER} --version + OUTPUT_VARIABLE GCC_VERSION_INFO) + string(REGEX MATCH "[0-9]+\\.[0-9]+" GCC_VERSION ${GCC_VERSION_INFO}) + string(REGEX REPLACE "\\..*" "" GCCVER ${GCC_VERSION}) + set(GCCVER ${CMAKE_MATCH_1}) + endif() + if(GCCVER GREATER_EQUAL 12) + add_link_options(-Wl,--no-warn-rwx-segments) + endif() endif() diff --git a/arch/risc-v/Kconfig b/arch/risc-v/Kconfig index 052954b6d0c65..5cfffe9bcc7bb 100644 --- a/arch/risc-v/Kconfig +++ b/arch/risc-v/Kconfig @@ -412,7 +412,7 @@ config ARCH_RV_MACHINE_ISA_1_13 which extend the range of exception codes from 0 ~ 15 to 0 ~ 19. config ARCH_RV_ISA_ZICSR_ZIFENCEI - bool + bool "Enable Zicsr and Zifencei extensions (GCC >= 12.1.0.)" default y ---help--- https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=aed44286efa8ae8717a77d94b51ac3614e2ca6dc diff --git a/arch/risc-v/src/cmake/Toolchain.cmake b/arch/risc-v/src/cmake/Toolchain.cmake index caac1972ae3fe..4997d151d1953 100644 --- a/arch/risc-v/src/cmake/Toolchain.cmake +++ b/arch/risc-v/src/cmake/Toolchain.cmake @@ -259,7 +259,16 @@ if(CONFIG_RISCV_TOOLCHAIN STREQUAL GNU_RVG) endif() if(CONFIG_ARCH_RV_ISA_ZICSR_ZIFENCEI) - set(ARCHCPUEXTFLAGS ${ARCHCPUEXTFLAGS}_zicsr_zifencei) + if(NOT DEFINED GCCVER) + execute_process(COMMAND ${CMAKE_CXX_COMPILER} --version + OUTPUT_VARIABLE GCC_VERSION_OUTPUT) + string(REGEX MATCH "\\+\\+.* ([0-9]+)\\.[0-9]+" GCC_VERSION_REGEX + "${GCC_VERSION_OUTPUT}") + set(GCCVER ${CMAKE_MATCH_1}) + endif() + if(GCCVER GREATER_EQUAL 12 OR CONFIG_ARCH_TOOLCHAIN_CLANG) + set(ARCHCPUEXTFLAGS ${ARCHCPUEXTFLAGS}_zicsr_zifencei) + endif() endif() if(CONFIG_ARCH_RV_EXPERIMENTAL_EXTENSIONS) diff --git a/arch/risc-v/src/common/Toolchain.defs b/arch/risc-v/src/common/Toolchain.defs index 4de10db89c97b..d3f2126b49b7d 100644 --- a/arch/risc-v/src/common/Toolchain.defs +++ b/arch/risc-v/src/common/Toolchain.defs @@ -210,7 +210,15 @@ ifeq ($(CONFIG_RISCV_TOOLCHAIN),GNU_RVG) endif ifeq ($(CONFIG_ARCH_RV_ISA_ZICSR_ZIFENCEI),y) - ARCHCPUEXTFLAGS := $(ARCHCPUEXTFLAGS)_zicsr_zifencei + ifeq ($(GCCVER),) + export GCCVER = ${shell $(CROSSDEV)gcc --version | grep gcc | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | tail -n 1 | cut -d"." -f1 } + endif + ifeq ($(shell expr "$(GCCVER)" \>= 12), 1) + ARCHCPUEXTFLAGS := $(ARCHCPUEXTFLAGS)_zicsr_zifencei + endif + ifeq ($(CONFIG_ARCH_TOOLCHAIN_CLANG),y) + ARCHCPUEXTFLAGS := $(ARCHCPUEXTFLAGS)zicsr_zifencei + endif endif ARCH_RV_EXPERIMENTAL_EXTENSIONS = $(strip $(subst ",,$(CONFIG_ARCH_RV_EXPERIMENTAL_EXTENSIONS))) diff --git a/libs/libxx/libcxx.cmake b/libs/libxx/libcxx.cmake index 2bea3136caa65..df030db311729 100644 --- a/libs/libxx/libcxx.cmake +++ b/libs/libxx/libcxx.cmake @@ -95,6 +95,14 @@ list(APPEND SRCS ${SRCSTMP}) set(FLAGS -Wno-attributes -Wno-deprecated-declarations -Wno-shadow -Wno-sign-compare) +if(NOT GCCVER) + execute_process(COMMAND ${CMAKE_C_COMPILER} --version + OUTPUT_VARIABLE GCC_VERSION_INFO) + string(REGEX MATCH "[0-9]+\\.[0-9]+" GCC_VERSION ${GCC_VERSION_INFO}) + string(REGEX REPLACE "\\..*" "" GCCVER ${GCC_VERSION}) + set(GCCVER ${CMAKE_MATCH_1}) +endif() + if(GCCVER GREATER_EQUAL 12) list(APPEND FLAGS -Wno-maybe-uninitialized -Wno-alloc-size-larger-than) endif() diff --git a/libs/libxx/libcxx.defs b/libs/libxx/libcxx.defs index d84e9419def05..620e3392df543 100644 --- a/libs/libxx/libcxx.defs +++ b/libs/libxx/libcxx.defs @@ -61,6 +61,10 @@ endif CXXFLAGS += -Wno-shadow -Wno-sign-compare CXXFLAGS += -Wno-attributes -Wno-deprecated-declarations +ifeq ($(GCCVER),) + export GCCVER := $(shell $(CC) --version | grep gcc | sed -E "s/.* ([0-9]+\.[0-9]+).*/\1/" | cut -d'.' -f1) +endif + ifeq ($(shell expr "$(GCCVER)" \>= 12), 1) CXXFLAGS += -Wno-maybe-uninitialized -Wno-alloc-size-larger-than endif diff --git a/tools/Config.mk b/tools/Config.mk index 244f853066e11..2637786f0eb77 100644 --- a/tools/Config.mk +++ b/tools/Config.mk @@ -732,11 +732,6 @@ export DEFINE_PREFIX ?= $(subst X,,${shell $(DEFINE) "$(CC)" X 2> ${EMPTYFILE}}) export INCDIR_PREFIX ?= $(subst "X",,${shell $(INCDIR) "$(CC)" X 2> ${EMPTYFILE}}) export INCSYSDIR_PREFIX ?= $(subst "X",,${shell $(INCDIR) -s "$(CC)" X 2> ${EMPTYFILE}}) -# Get the GCC version number -ifeq ($(CONFIG_ARCH_TOOLCHAIN_GNU), y) - export GCCVER = $(shell $(CXX) --version | grep ++ | sed -E 's/.* ([0-9]+\.[0-9]+).*/\1/' | cut -d'.' -f1) -endif - # ARCHxxx means the predefined setting(either toolchain, arch, or system specific) ARCHDEFINES += ${DEFINE_PREFIX}__NuttX__ ifeq ($(CONFIG_NDEBUG),y)