arch/armv6-m: add support of LLVM Clang

Signed-off-by: chao.an <anchao@xiaomi.com>
This commit is contained in:
chao.an 2022-04-20 21:44:30 +08:00 committed by Xiang Xiao
parent 48b81bda09
commit 67fbfda974
2 changed files with 68 additions and 15 deletions

View File

@ -20,4 +20,8 @@ config ARMV6M_TOOLCHAIN_GNU_EABI
This option should work for any modern GNU toolchain (GCC 4.5 or newer)
configured for arm-none-eabi.
config ARMV6M_TOOLCHAIN_CLANG
bool "Generic Clang toolchain"
select ARCH_TOOLCHAIN_GNU
endchoice

View File

@ -35,6 +35,10 @@ ifeq ($(filter y, $(CONFIG_ARMV6M_TOOLCHAIN_GNU_EABI)),y)
CONFIG_ARMV6M_TOOLCHAIN ?= GNU_EABI
endif
ifeq ($(filter y, $(CONFIG_ARMV6M_TOOLCHAIN_CLANG)),y)
CONFIG_ARMV6M_TOOLCHAIN ?= CLANG
endif
#
# Supported toolchains
#
@ -53,6 +57,8 @@ endif
ifeq ($(CONFIG_DEBUG_CUSTOMOPT),y)
MAXOPTIMIZATION := $(CONFIG_DEBUG_OPTLEVEL)
else ifeq ($(CONFIG_ARMV6M_TOOLCHAIN),CLANG)
MAXOPTIMIZATION ?= -Oz
else
MAXOPTIMIZATION ?= -Os
endif
@ -63,20 +69,68 @@ else
MAXOPTIMIZATION += -fomit-frame-pointer
endif
# Parametrization for ARCHCPUFLAGS
TOOLCHAIN_MTUNE := -mcpu=cortex-m0 -mthumb
TOOLCHAIN_MFLOAT := -mfloat-abi=soft
# Clang Configuration files
ifeq ($(CONFIG_ARMV6M_TOOLCHAIN),CLANG)
TOOLCHAIN_MARCH := --config armv6m_soft_nofp_nosys
endif
# NuttX buildroot under Linux or Cygwin
ifeq ($(CONFIG_ARMV6M_TOOLCHAIN),BUILDROOT)
CROSSDEV ?= arm-nuttx-eabi-
ARCHCPUFLAGS = -mcpu=cortex-m0 -mthumb -mfloat-abi=soft
ARCHCPUFLAGS = $(TOOLCHAIN_MARCH) $(TOOLCHAIN_MTUNE) $(TOOLCHAIN_MFLOAT)
endif
# Generic GNU EABI toolchain
ifeq ($(CONFIG_ARMV6M_TOOLCHAIN),GNU_EABI)
CROSSDEV ?= arm-none-eabi-
ARCHCPUFLAGS = -mcpu=cortex-m0 -mthumb -mfloat-abi=soft
ARCHCPUFLAGS = $(TOOLCHAIN_MARCH) $(TOOLCHAIN_MTUNE) $(TOOLCHAIN_MFLOAT)
endif
# Clang toolchain
ifeq ($(CONFIG_ARMV6M_TOOLCHAIN),CLANG)
ARCHCPUFLAGS = $(TOOLCHAIN_MARCH) $(TOOLCHAIN_MTUNE) $(TOOLCHAIN_MFLOAT)
CC = clang
CXX = clang++
CPP = clang -E -P -x c
LD = ld.lld -m armelf
STRIP = llvm-strip --strip-unneeded
AR = llvm-ar rcs
NM = llvm-nm
OBJCOPY = llvm-objcopy
OBJDUMP = llvm-objdump
# Since the no_builtin attribute is not fully supported on Clang
# disable the built-in functions, refer:
# https://github.com/apache/incubator-nuttx/pull/5971
MAXOPTIMIZATION += -fno-builtin
# Default toolchain
else
CC = $(CROSSDEV)gcc
CXX = $(CROSSDEV)g++
CPP = $(CROSSDEV)gcc -E -P -x c
LD = $(CROSSDEV)ld
STRIP = $(CROSSDEV)strip --strip-unneeded
AR = $(CROSSDEV)ar rcs
NM = $(CROSSDEV)nm
OBJCOPY = $(CROSSDEV)objcopy
OBJDUMP = $(CROSSDEV)objdump
endif
# Architecture flags
ifeq ($(CONFIG_MM_KASAN),y)
ARCHCPUFLAGS += -fsanitize=kernel-address
endif
@ -92,21 +146,16 @@ ifneq ($(CONFIG_CXX_RTTI),y)
ARCHCXXFLAGS += -fno-rtti
endif
# Default toolchain
CC = $(CROSSDEV)gcc
CXX = $(CROSSDEV)g++
CPP = $(CROSSDEV)gcc -E -P -x c
LD = $(CROSSDEV)ld
STRIP = $(CROSSDEV)strip --strip-unneeded
AR = $(CROSSDEV)ar rcs
NM = $(CROSSDEV)nm
OBJCOPY = $(CROSSDEV)objcopy
OBJDUMP = $(CROSSDEV)objdump
# Add the builtin library
EXTRA_LIBS += $(wildcard $(shell $(CC) $(ARCHCPUFLAGS) --print-libgcc-file-name))
COMPILER_RT_LIB = $(shell $(CC) $(ARCHCPUFLAGS) --print-libgcc-file-name)
ifeq ($(wildcard $(COMPILER_RT_LIB)),)
# if "--print-libgcc-file-name" unable to find the correct libgcc PATH
# then go ahead and try "--print-file-name"
COMPILER_RT_LIB := $(wildcard $(shell $(CC) $(ARCHCPUFLAGS) --print-file-name $(notdir $(COMPILER_RT_LIB))))
endif
EXTRA_LIBS += $(COMPILER_RT_LIB)
ifneq ($(CONFIG_LIBM),y)
EXTRA_LIBS += $(wildcard $(shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libm.a))