diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index c54e25f61b..19721ae34a 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -42,6 +42,10 @@ config ARM_TOOLCHAIN_CLANG bool "Generic Clang toolchain" select ARCH_TOOLCHAIN_CLANG +config ARM_TOOLCHAIN_ARMCLANG + bool "ARM Compiler Clang toolchain" + select ARCH_TOOLCHAIN_CLANG + endchoice choice diff --git a/arch/arm/src/Makefile b/arch/arm/src/Makefile index b84db3f744..a3e401c85a 100644 --- a/arch/arm/src/Makefile +++ b/arch/arm/src/Makefile @@ -85,37 +85,45 @@ UOBJS = $(UAOBJS) $(UCOBJS) KBIN = libkarch$(LIBEXT) BIN = libarch$(LIBEXT) -LDFLAGS += $(addprefix -T,$(call CONVERT_PATH,$(ARCHSCRIPT))) $(EXTRALINKCMDS) - # Override in Make.defs if linker is not 'ld' -ifeq ($(LD),$(CC)) - LDSTARTGROUP ?= -Wl,--start-group - LDENDGROUP ?= -Wl,--end-group - LDFLAGS := $(addprefix -Xlinker ,$(LDFLAGS)) - LDFLAGS += $(CFLAGS) +ifeq ($(CONFIG_ARM_TOOLCHAIN_ARMCLANG),) + ifeq ($(LD),$(CC)) + LDSTARTGROUP ?= -Wl,--start-group + LDENDGROUP ?= -Wl,--end-group + LDFLAGS := $(addprefix -Xlinker ,$(LDFLAGS)) + LDFLAGS += $(CFLAGS) + else + LDSTARTGROUP ?= --start-group + LDENDGROUP ?= --end-group + endif + + LIBPATH_OPT = -L + SCRIPT_OPT = -T else - LDSTARTGROUP ?= --start-group - LDENDGROUP ?= --end-group + LIBPATH_OPT = --userlibpath + EXTRA_LIBS += arm_vectors.o + SCRIPT_OPT = --scatter= endif +LDFLAGS += $(addprefix $(SCRIPT_OPT),$(call CONVERT_PATH,$(ARCHSCRIPT))) $(EXTRALINKCMDS) +LIBPATHS += $(LIBPATH_OPT) $(call CONVERT_PATH,$(TOPDIR)$(DELIM)staging) + BOARDMAKE = $(if $(wildcard board$(DELIM)Makefile),y,) - -LIBPATHS += -L $(call CONVERT_PATH,$(TOPDIR)$(DELIM)staging) ifeq ($(BOARDMAKE),y) - LIBPATHS += -L $(call CONVERT_PATH,$(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board) + LIBPATHS += $(LIBPATH_OPT) $(call CONVERT_PATH,$(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board) endif -LDLIBS = $(patsubst %.a,%,$(patsubst lib%,-l%,$(LINKLIBS))) +LDLIBS = $(patsubst %.a,%,$(patsubst lib%,--library=%,$(LINKLIBS))) ifeq ($(BOARDMAKE),y) - LDLIBS += -lboard + LDLIBS += --library=board endif VPATH += chip VPATH += common VPATH += $(ARCH_SUBDIR) -ifeq ($(CONFIG_ARCH_TOOLCHAIN_IAR),y) +ifeq ($(CONFIG_ARM_TOOLCHAIN_IAR),y) VPATH += common$(DELIM)iar else # ifeq ($(CONFIG_ARCH_TOOLCHAIN_GNU),y) VPATH += common$(DELIM)gnu diff --git a/arch/arm/src/armv6-m/Toolchain.defs b/arch/arm/src/armv6-m/Toolchain.defs index e3bcd7daef..c18787a736 100644 --- a/arch/arm/src/armv6-m/Toolchain.defs +++ b/arch/arm/src/armv6-m/Toolchain.defs @@ -27,6 +27,8 @@ TOOLCHAIN_MFLOAT := -mfloat-abi=soft ifeq ($(CONFIG_ARM_TOOLCHAIN_CLANG),y) TOOLCHAIN_MARCH := --config armv6m_soft_nofp_nosys +else ifeq ($(CONFIG_ARM_TOOLCHAIN_ARMCLANG),y) + LDFLAGS += --cpu=Cortex-M0 endif include $(TOPDIR)/arch/arm/src/common/Toolchain.defs diff --git a/arch/arm/src/armv7-a/Toolchain.defs b/arch/arm/src/armv7-a/Toolchain.defs index 1d44918a10..0968fa1727 100644 --- a/arch/arm/src/armv7-a/Toolchain.defs +++ b/arch/arm/src/armv7-a/Toolchain.defs @@ -61,4 +61,26 @@ else ARCHCPUFLAGS += -mfloat-abi=soft endif +ifeq ($(CONFIG_ARM_TOOLCHAIN_ARMCLANG),y) + + ifeq ($(CONFIG_ARCH_CORTEXA5),y) + LDCPUFLAGS = Cortex-A5 + else ifeq ($(CONFIG_ARCH_CORTEXA7),y) + LDCPUFLAGS = Cortex-A7 + else ifeq ($(CONFIG_ARCH_CORTEXA8),y) + LDCPUFLAGS = Cortex-A8 + else ifeq ($(CONFIG_ARCH_CORTEXA9),y) + LDCPUFLAGS = Cortex-A9 + endif + + ifeq ($(CONFIG_ARCH_FPU),) + LDFLAGS += --cpu=$(LDCPUFLAGS).no_neon.no_vfp + else ifeq ($(CONFIG_ARM_NEON),) + LDFLAGS += --cpu=$(LDCPUFLAGS).no_neon + else + LDFLAGS += --cpu=$(LDCPUFLAGS) + endif + +endif + include $(TOPDIR)/arch/arm/src/common/Toolchain.defs diff --git a/arch/arm/src/armv7-m/Toolchain.defs b/arch/arm/src/armv7-m/Toolchain.defs index 07f939ec38..07c942c38b 100644 --- a/arch/arm/src/armv7-m/Toolchain.defs +++ b/arch/arm/src/armv7-m/Toolchain.defs @@ -75,6 +75,28 @@ ifeq ($(CONFIG_ARM_TOOLCHAIN_CLANG),y) TOOLCHAIN_MARCH += --config armv7m_soft_nofp_nosys endif +else ifeq ($(CONFIG_ARM_TOOLCHAIN_ARMCLANG),y) + + ifeq ($(CONFIG_ARCH_CORTEXM4),y) + ifeq ($(CONFIG_ARCH_FPU),y) + LDFLAGS += --cpu=Cortex-M4 + else + LDFLAGS += --cpu=Cortex-M4.no_fp + endif + else ifeq ($(CONFIG_ARCH_CORTEXM7),y) + ifeq ($(CONFIG_ARCH_FPU),y) + ifeq ($(CONFIG_ARCH_DPFPU),y) + LDFLAGS += --cpu=Cortex-M7 + else + LDFLAGS += --cpu=Cortex-M7.fp.sp + endif + else + LDFLAGS += --cpu=Cortex-M7.no_fp + endif + else # ifeq ($(CONFIG_ARCH_CORTEXM3),y) + LDFLAGS += --cpu=Cortex-M3 + endif + endif ifeq ($(CONFIG_ARMV7M_STACKCHECK),y) diff --git a/arch/arm/src/armv7-r/Toolchain.defs b/arch/arm/src/armv7-r/Toolchain.defs index 6ee10178f3..ba3ff79eca 100644 --- a/arch/arm/src/armv7-r/Toolchain.defs +++ b/arch/arm/src/armv7-r/Toolchain.defs @@ -37,4 +37,24 @@ else ARCHCPUFLAGS += -mfloat-abi=soft endif +ifeq ($(CONFIG_ARM_TOOLCHAIN_ARMCLANG),y) + + ifeq ($(CONFIG_ARCH_CORTEXR4),y) + LDFLAGS += --cpu=Cortex-R4 + else ifeq ($(CONFIG_ARCH_CORTEXR5),y) + ifeq ($(CONFIG_ARCH_FPU),y) + LDFLAGS += --cpu=Cortex-R5 + else + LDFLAGS += --cpu=Cortex-R5.no_vfp + endif + else ifeq ($(CONFIG_ARCH_CORTEXR7),y) + ifeq ($(CONFIG_ARCH_FPU),y) + LDFLAGS += --cpu=Cortex-R7 + else + LDFLAGS += --cpu=Cortex-R7.no_vfp + endif + endif + +endif + include $(TOPDIR)/arch/arm/src/common/Toolchain.defs diff --git a/arch/arm/src/armv8-m/Toolchain.defs b/arch/arm/src/armv8-m/Toolchain.defs index 8ad07e0def..8407e7cd8c 100644 --- a/arch/arm/src/armv8-m/Toolchain.defs +++ b/arch/arm/src/armv8-m/Toolchain.defs @@ -84,6 +84,38 @@ ifeq ($(CONFIG_ARM_TOOLCHAIN_CLANG),y) endif endif +else ifeq ($(CONFIG_ARM_TOOLCHAIN_ARMCLANG),y) + + ifeq ($(CONFIG_ARCH_CORTEXM23),y) + LDFLAGS += --cpu=Cortex-M23 + else ifeq ($(CONFIG_ARCH_CORTEXM33),y) + ifeq ($(CONFIG_ARCH_FPU),y) + LDFLAGS += --cpu=Cortex-M33 + else + LDFLAGS += --cpu=Cortex-M33.no_fp + endif + else ifeq ($(CONFIG_ARCH_CORTEXM35P),y) + ifeq ($(CONFIG_ARCH_FPU),y) + LDFLAGS += --cpu=Cortex-M35P + else + LDFLAGS += --cpu=Cortex-M35P.no_fp + endif + else ifeq ($(CONFIG_ARCH_CORTEXM55),y) + ifeq ($(CONFIG_ARM_HAVE_MVE),y) + ifeq ($(CONFIG_ARCH_FPU),y) + LDFLAGS += --cpu=Cortex-M55 + else + LDFLAGS += --cpu=Cortex-M55.no_fp + endif + else + ifeq ($(CONFIG_ARCH_FPU),y) + LDFLAGS += --cpu=Cortex-M55.no_mve + else + LDFLAGS += --cpu=Cortex-M55.no_mve.no_fp + endif + endif + endif + endif ifeq ($(CONFIG_ARMV8M_STACKCHECK),y) diff --git a/arch/arm/src/common/Toolchain.defs b/arch/arm/src/common/Toolchain.defs index 29ad342faa..fb2b45ecf1 100644 --- a/arch/arm/src/common/Toolchain.defs +++ b/arch/arm/src/common/Toolchain.defs @@ -131,6 +131,32 @@ ifeq ($(CONFIG_ARM_TOOLCHAIN_CLANG),y) ARCHOPTIMIZATION += -fno-builtin +# ARM Compiler Clang toolchain + +else ifeq ($(CONFIG_ARM_TOOLCHAIN_ARMCLANG),y) + + CC = armclang + CXX = armclang + CPP = armclang -E -P -x c + LD = armlink + STRIP = llvm-strip --strip-unneeded + AR = armar -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 + + ARCHOPTIMIZATION += -fno-builtin + ARCHOPTIMIZATION += --target=arm-arm-none-eabi + + # Suppress license warning + + ARCHCPUFLAGS += -Wno-license-management + LDFLAGS += --diag_suppress=9931 + # Default toolchain else @@ -174,23 +200,35 @@ endif ARCHOPTIMIZATION += -fno-common -Wall -Wshadow -Wundef ARCHOPTIMIZATION += -nostdlib -LDFLAGS += -nostdlib +ifeq ($(CONFIG_ARM_TOOLCHAIN_ARMCLANG),) + LDFLAGS += -nostdlib +endif # Optimization of unused sections -ifeq ($(CONFIG_DEBUG_OPT_UNUSED_SECTIONS),y) - LDFLAGS += --gc-sections - ARCHOPTIMIZATION += -ffunction-sections -fdata-sections +ifeq ($(CONFIG_ARM_TOOLCHAIN_ARMCLANG),) + ifeq ($(CONFIG_DEBUG_OPT_UNUSED_SECTIONS),y) + LDFLAGS += --gc-sections + ARCHOPTIMIZATION += -ffunction-sections -fdata-sections + endif endif # Debug link map ifeq ($(CONFIG_DEBUG_LINK_MAP),y) - LDFLAGS += --cref -Map=$(call CONVERT_PATH,$(TOPDIR)$(DELIM)nuttx.map) + ifeq ($(CONFIG_ARM_TOOLCHAIN_ARMCLANG),) + LDFLAGS += --cref -Map=$(call CONVERT_PATH,$(TOPDIR)$(DELIM)nuttx.map) + else + LDFLAGS += --strict --map --xref --symbols --info=unused --info=veneers + LDFLAGS += --info=summarysizes --info=summarystack + endif endif ifeq ($(CONFIG_DEBUG_SYMBOLS),y) ARCHOPTIMIZATION += -g + ifeq ($(CONFIG_ARM_TOOLCHAIN_ARMCLANG),y) + LDFLAGS += --debug + endif endif # Add the builtin library