Skip to content

Commit

Permalink
Add GCCVER define to Toolchain.cmake
Browse files Browse the repository at this point in the history
Since GCCVER will also be used in the toolchain, it needs to be defined in advance.

Signed-off-by: cuiziwei <[email protected]>
  • Loading branch information
cuiziweizw committed Oct 16, 2024
1 parent 39690a9 commit 6333af2
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 4 deletions.
4 changes: 4 additions & 0 deletions arch/arm/src/common/Toolchain.defs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,10 @@ else
# Wrong warning array subscript [0] is outside array bounds:
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105523

ifeq ($(GCCVER),)
export GCCVER := $(shell $(CC) --version | grep gcc | sed -E "s/.* ([0-9]+\.[0-9]+).*/\1/" | cut -d'.' -f1)
endif

ifeq ($(GCCVER),12)
ARCHOPTIMIZATION += --param=min-pagesize=0
ifeq ($(CONFIG_ARCH_RAMFUNCS),y)
Expand Down
5 changes: 4 additions & 1 deletion arch/arm64/src/Toolchain.defs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,10 @@ ifeq ($(CONFIG_LTO_FULL),y)
endif

ifeq ($(CONFIG_ARCH_TOOLCHAIN_GNU),y)
LDFLAGS += --no-warn-rwx-segments
ifeq ($(GCCVER),)
export GCCVER := $(shell $(CC) --version | grep gcc | sed -E "s/.* ([0-9]+\.[0-9]+).*/\1/" | cut -d'.' -f1)
endif
LDFLAGS += --no-warn-rwx-segments
endif

# Add the builtin library
Expand Down
6 changes: 6 additions & 0 deletions arch/arm64/src/cmake/Toolchain.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -190,5 +190,11 @@ if(CONFIG_DEBUG_SYMBOLS)
endif()

if(CONFIG_ARCH_TOOLCHAIN_GNU)
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})
endif()
add_link_options(-Wl,--no-warn-rwx-segments)
endif()
2 changes: 1 addition & 1 deletion arch/risc-v/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion arch/risc-v/src/cmake/Toolchain.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,18 @@ if(CONFIG_RISCV_TOOLCHAIN STREQUAL GNU_RVG)
set(ARCHCPUEXTFLAGS ${ARCHCPUEXTFLAGS}v)
endif()

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(CONFIG_ARCH_RV_ISA_ZICSR_ZIFENCEI)
set(ARCHCPUEXTFLAGS ${ARCHCPUEXTFLAGS}_zicsr_zifencei)
if(GCCVER GREATER_EQUAL 12 OR CONFIG_ARCH_TOOLCHAIN_CLANG)
set(ARCHCPUEXTFLAGS ${ARCHCPUEXTFLAGS}_zicsr_zifencei)
endif()
endif()

if(CONFIG_ARCH_RV_EXPERIMENTAL_EXTENSIONS)
Expand Down
8 changes: 7 additions & 1 deletion arch/risc-v/src/common/Toolchain.defs
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,14 @@ ifeq ($(CONFIG_RISCV_TOOLCHAIN),GNU_RVG)
ARCHCPUEXTFLAGS := $(ARCHCPUEXTFLAGS)v
endif

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 ($(CONFIG_ARCH_RV_ISA_ZICSR_ZIFENCEI),y)
ARCHCPUEXTFLAGS := $(ARCHCPUEXTFLAGS)_zicsr_zifencei
ifeq ($(shell expr $(GCCVER) \>= 12), 1)
ARCHCPUEXTFLAGS := $(ARCHCPUEXTFLAGS)_zicsr_zifencei
endif
endif

ARCH_RV_EXPERIMENTAL_EXTENSIONS = $(strip $(subst ",,$(CONFIG_ARCH_RV_EXPERIMENTAL_EXTENSIONS)))
Expand Down

0 comments on commit 6333af2

Please sign in to comment.