You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2022/09/16 06:47:36 UTC

[incubator-nuttx] 02/03: arch/arm: unify compile flags to common/Toolchain.defs

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/incubator-nuttx.git

commit 54aa91f02b59e67c19c0c74692e6c3369bf6c260
Author: chao an <an...@xiaomi.com>
AuthorDate: Thu Sep 15 22:06:54 2022 +0800

    arch/arm: unify compile flags to common/Toolchain.defs
    
    Signed-off-by: chao an <an...@xiaomi.com>
---
 arch/arm/src/arm/Toolchain.defs                    | 165 +---------------
 arch/arm/src/armv6-m/Toolchain.defs                | 208 +------------------
 arch/arm/src/armv7-a/Toolchain.defs                | 167 +---------------
 arch/arm/src/armv7-m/Toolchain.defs                | 219 +--------------------
 arch/arm/src/armv7-r/Toolchain.defs                | 167 +---------------
 arch/arm/src/armv8-m/Toolchain.defs                | 219 +--------------------
 arch/arm/src/{armv6-m => common}/Toolchain.defs    | 111 +++++------
 arch/arm/src/tlsr82/Toolchain.defs                 | 172 +---------------
 boards/arm/eoss3/quickfeather/scripts/Make.defs    |   2 +-
 .../arm/stm32/stm32f4discovery/scripts/Make.defs   |   2 +-
 10 files changed, 66 insertions(+), 1366 deletions(-)

diff --git a/arch/arm/src/arm/Toolchain.defs b/arch/arm/src/arm/Toolchain.defs
index 702990b5ce..6a2c34afe9 100644
--- a/arch/arm/src/arm/Toolchain.defs
+++ b/arch/arm/src/arm/Toolchain.defs
@@ -1,5 +1,5 @@
 ############################################################################
-# arch/arm/src/armv/Toolchain.defs
+# arch/arm/src/arm/Toolchain.defs
 #
 # Licensed to the Apache Software Foundation (ASF) under one or more
 # contributor license agreements.  See the NOTICE file distributed with
@@ -18,165 +18,4 @@
 #
 ############################################################################
 
-# Setup for the selected toolchain
-
-#
-# Handle old-style chip-specific toolchain names in the absence of
-# a new-style toolchain specification, force the selection of a single
-# toolchain and allow the selected toolchain to be overridden by a
-# command-line selection.
-#
-
-ifeq ($(filter y, \
-      $(CONFIG_ARM_TOOLCHAIN_BUILDROOT) \
-    ),y)
-  CONFIG_TOOLCHAIN ?= BUILDROOT
-endif
-
-ifeq ($(filter y, \
-      $(CONFIG_ARM_TOOLCHAIN_GNU_EABI) \
-    ),y)
-  CONFIG_TOOLCHAIN ?= GNU_EABI
-endif
-
-#
-# Supported toolchains
-#
-# TODO - It's likely that all of these toolchains now support the
-#        CortexM4.  Since they are all GCC-based, we could almost
-#        certainly simplify this further.
-#
-# Each toolchain definition should set:
-#
-#  CROSSDEV         The GNU toolchain triple (command prefix)
-#  ARCHCPUFLAGS     CPU-specific flags selecting the instruction set
-#                   FPU options, etc.
-#  ARCHOPTIMIZATION The optimization level that results in
-#                   reliable code generation.
-#
-
-ifeq ($(CONFIG_DEBUG_CUSTOMOPT),y)
-  ARCHOPTIMIZATION += $(CONFIG_DEBUG_OPTLEVEL)
-else ifeq ($(CONFIG_DEBUG_FULLOPT),y)
-  ARCHOPTIMIZATION += -Os
-endif
-
-ifneq ($(CONFIG_DEBUG_NOOPT),y)
-  ARCHOPTIMIZATION += -fno-strict-aliasing
-endif
-
-ifeq ($(CONFIG_FRAME_POINTER),y)
-  ARCHOPTIMIZATION += -fno-omit-frame-pointer -fno-optimize-sibling-calls
-else
-  ARCHOPTIMIZATION += -fomit-frame-pointer
-endif
-
-ifeq ($(CONFIG_STACK_CANARIES),y)
-  ARCHOPTIMIZATION += -fstack-protector-all
-endif
-
-ifeq ($(CONFIG_ARCH_COVERAGE_ALL),y)
-  ARCHOPTIMIZATION += -fprofile-generate -ftest-coverage
-endif
-
-ifeq ($(CONFIG_MM_KASAN_ALL),y)
-  ARCHOPTIMIZATION += -fsanitize=kernel-address
-endif
-
-ifeq ($(CONFIG_MM_UBSAN_ALL),y)
-  ARCHOPTIMIZATION += $(CONFIG_MM_UBSAN_OPTION)
-endif
-
-ifeq ($(CONFIG_MM_UBSAN_TRAP_ON_ERROR),y)
-  ARCHOPTIMIZATION += -fsanitize-undefined-trap-on-error
-endif
-
-# NuttX buildroot under Linux or Cygwin
-
-ifeq ($(CONFIG_ARM_TOOLCHAIN_BUILDROOT),y)
-  CROSSDEV ?= arm-nuttx-eabi-
-endif
-
-ifeq ($(CONFIG_ARM_TOOLCHAIN_BUILDROOT_OABI),y)
-  CROSSDEV ?= arm-nuttx-elf-
-endif
-
-# Generic GNU EABI toolchain
-
-ifeq ($(CONFIG_TOOLCHAIN),GNU_EABI)
-  CROSSDEV ?= arm-none-eabi-
-endif
-
-ARCHCFLAGS += -fno-common
-ARCHCXXFLAGS += -fno-common -nostdinc++
-
-ARCHCFLAGS += -Wall -Wstrict-prototypes -Wshadow -Wundef
-ARCHCXXFLAGS += -Wall -Wshadow -Wundef
-
-ifneq ($(CONFIG_CXX_EXCEPTION),y)
-  ARCHCXXFLAGS += -fno-exceptions -fcheck-new
-endif
-
-ifneq ($(CONFIG_CXX_RTTI),y)
-  ARCHCXXFLAGS += -fno-rtti
-endif
-
-LDFLAGS += -nostdlib
-
-# Optimization of unused sections
-
-ifeq ($(CONFIG_DEBUG_OPT_UNUSED_SECTIONS),y)
-  LDFLAGS          += --gc-sections
-  ARCHOPTIMIZATION += -ffunction-sections -fdata-sections
-endif
-
-# Debug link map
-
-ifeq ($(CONFIG_DEBUG_LINK_MAP),y)
-  LDFLAGS += --cref -Map=$(call CONVERT_PATH,$(TOPDIR)$(DELIM)nuttx.map)
-endif
-
-ifeq ($(CONFIG_DEBUG_SYMBOLS),y)
-  ARCHOPTIMIZATION += -g
-endif
-
-# Default toolchain
-
-CC      = $(CROSSDEV)gcc
-CXX     = $(CROSSDEV)g++
-CPP     = $(CROSSDEV)gcc -E -P -x c
-STRIP   = $(CROSSDEV)strip --strip-unneeded
-OBJCOPY = $(CROSSDEV)objcopy
-OBJDUMP = $(CROSSDEV)objdump
-LD      = $(CROSSDEV)ld
-AR      = $(CROSSDEV)ar rcs
-NM      = $(CROSSDEV)nm
-
-# Link Time Optimization
-
-ifeq ($(CONFIG_LTO_FULL),y)
-  ARCHOPTIMIZATION += -flto
-  ifeq ($(CONFIG_TOOLCHAIN),GNU_EABI)
-    LD := $(CROSSDEV)gcc
-    AR := $(CROSSDEV)gcc-ar rcs
-    NM := $(CROSSDEV)gcc-nm
-    ARCHOPTIMIZATION += -fuse-linker-plugin
-    ARCHOPTIMIZATION += -fno-builtin
-  endif
-endif
-
-# Add the builtin library
-
-EXTRA_LIBS += $(wildcard $(shell $(CC) $(ARCHCPUFLAGS) --print-libgcc-file-name))
-
-ifneq ($(CONFIG_LIBM),y)
-  EXTRA_LIBS += $(wildcard $(shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libm.a))
-endif
-
-ifeq ($(CONFIG_LIBSUPCXX),y)
-  EXTRA_LIBS += $(wildcard $(shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libsupc++.a))
-endif
-
-ifeq ($(CONFIG_ARCH_COVERAGE),y)
-  EXTRA_LIBS += $(wildcard $(shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libgcov.a))
-endif
+include $(TOPDIR)/arch/arm/src/common/Toolchain.defs
diff --git a/arch/arm/src/armv6-m/Toolchain.defs b/arch/arm/src/armv6-m/Toolchain.defs
index 102f803219..e3bcd7daef 100644
--- a/arch/arm/src/armv6-m/Toolchain.defs
+++ b/arch/arm/src/armv6-m/Toolchain.defs
@@ -18,71 +18,6 @@
 #
 ############################################################################
 
-# Setup for the selected toolchain
-
-#
-# Handle old-style chip-specific toolchain names in the absence of
-# a new-style toolchain specification, force the selection of a single
-# toolchain and allow the selected toolchain to be overridden by a
-# command-line selection.
-#
-
-ifeq ($(filter y, $(CONFIG_ARM_TOOLCHAIN_BUILDROOT)),y)
-  CONFIG_TOOLCHAIN ?= BUILDROOT
-endif
-
-ifeq ($(filter y, $(CONFIG_ARM_TOOLCHAIN_GNU_EABI)),y)
-  CONFIG_TOOLCHAIN ?= GNU_EABI
-endif
-
-ifeq ($(filter y, $(CONFIG_ARM_TOOLCHAIN_CLANG)),y)
-  CONFIG_TOOLCHAIN ?= CLANG
-endif
-
-#
-# Supported toolchains
-#
-# TODO - It's likely that all of these toolchains now support the
-#        CortexM0.  Since they are all GCC-based, we could almost
-#        certainly simplify this further.
-#
-# Each toolchain definition should set:
-#
-#  CROSSDEV         The GNU toolchain triple (command prefix)
-#  ARCHCPUFLAGS     CPU-specific flags selecting the instruction set
-#                   options, etc.
-#  ARCHOPTIMIZATION The optimization level that results in
-#                   reliable code generation.
-#
-
-ifeq ($(CONFIG_DEBUG_CUSTOMOPT),y)
-  ARCHOPTIMIZATION += $(CONFIG_DEBUG_OPTLEVEL)
-else ifeq ($(CONFIG_DEBUG_FULLOPT),y)
-  ifeq ($(CONFIG_TOOLCHAIN),CLANG)
-    ARCHOPTIMIZATION += -Oz
-  else
-    ARCHOPTIMIZATION += -Os
-  endif
-endif
-
-ifneq ($(CONFIG_DEBUG_NOOPT),y)
-  ARCHOPTIMIZATION += -fno-strict-aliasing
-endif
-
-ifeq ($(CONFIG_FRAME_POINTER),y)
-  ARCHOPTIMIZATION += -fno-omit-frame-pointer -fno-optimize-sibling-calls
-else
-  ARCHOPTIMIZATION += -fomit-frame-pointer
-endif
-
-ifeq ($(CONFIG_STACK_CANARIES),y)
-  ARCHOPTIMIZATION += -fstack-protector-all
-endif
-
-ifeq ($(CONFIG_ARCH_COVERAGE_ALL),y)
-  ARCHOPTIMIZATION += -fprofile-generate -ftest-coverage
-endif
-
 # Parametrization for ARCHCPUFLAGS
 
 TOOLCHAIN_MTUNE  := -mcpu=cortex-m0 -mthumb
@@ -90,147 +25,8 @@ TOOLCHAIN_MFLOAT := -mfloat-abi=soft
 
 # Clang Configuration files
 
-ifeq ($(CONFIG_TOOLCHAIN),CLANG)
+ifeq ($(CONFIG_ARM_TOOLCHAIN_CLANG),y)
   TOOLCHAIN_MARCH := --config armv6m_soft_nofp_nosys
 endif
 
-# Link Time Optimization
-
-ifeq ($(CONFIG_LTO_THIN),y)
-  ARCHOPTIMIZATION += -flto=thin
-else ifeq ($(CONFIG_LTO_FULL),y)
-  ARCHOPTIMIZATION += -flto
-  ifeq ($(CONFIG_TOOLCHAIN),GNU_EABI)
-    ARCHOPTIMIZATION += -fuse-linker-plugin
-  endif
-endif
-
-# NuttX buildroot under Linux or Cygwin
-
-ifeq ($(CONFIG_TOOLCHAIN),BUILDROOT)
-  CROSSDEV ?= arm-nuttx-eabi-
-  ARCHCPUFLAGS = $(TOOLCHAIN_MARCH) $(TOOLCHAIN_MTUNE) $(TOOLCHAIN_MFLOAT)
-endif
-
-# Generic GNU EABI toolchain
-
-ifeq ($(CONFIG_TOOLCHAIN),GNU_EABI)
-  CROSSDEV ?= arm-none-eabi-
-  ARCHCPUFLAGS = $(TOOLCHAIN_MARCH) $(TOOLCHAIN_MTUNE) $(TOOLCHAIN_MFLOAT)
-endif
-
-# Clang toolchain
-
-ifeq ($(CONFIG_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
-
-  ARCHOPTIMIZATION += -fno-builtin
-
-# Default toolchain
-
-else
-  CC      = $(CROSSDEV)gcc
-  CXX     = $(CROSSDEV)g++
-  CPP     = $(CROSSDEV)gcc -E -P -x c
-  STRIP   = $(CROSSDEV)strip --strip-unneeded
-  OBJCOPY = $(CROSSDEV)objcopy
-  OBJDUMP = $(CROSSDEV)objdump
-  LD      = $(CROSSDEV)ld
-  AR      = $(CROSSDEV)ar rcs
-  NM      = $(CROSSDEV)nm
-
-  ifeq ($(CONFIG_LTO_FULL),y)
-    ifeq ($(CONFIG_TOOLCHAIN),GNU_EABI)
-      LD := $(CROSSDEV)gcc
-      AR := $(CROSSDEV)gcc-ar rcs
-      NM := $(CROSSDEV)gcc-nm
-      ARCHOPTIMIZATION += -fno-builtin
-    endif
-  endif
-endif
-
-# Architecture flags
-
-ifeq ($(CONFIG_MM_KASAN_ALL),y)
-  ARCHOPTIMIZATION += -fsanitize=kernel-address
-endif
-
-ifeq ($(CONFIG_MM_UBSAN_ALL),y)
-  ARCHOPTIMIZATION += $(CONFIG_MM_UBSAN_OPTION)
-endif
-
-ifeq ($(CONFIG_MM_UBSAN_TRAP_ON_ERROR),y)
-  ARCHOPTIMIZATION += -fsanitize-undefined-trap-on-error
-endif
-
-ARCHCFLAGS += -fno-common
-ARCHCXXFLAGS += -fno-common -nostdinc++
-
-ARCHCFLAGS += -Wall -Wstrict-prototypes -Wshadow -Wundef
-ARCHCXXFLAGS += -Wall -Wshadow -Wundef
-
-ifneq ($(CONFIG_CXX_EXCEPTION),y)
-  ARCHCXXFLAGS += -fno-exceptions -fcheck-new
-endif
-
-ifneq ($(CONFIG_CXX_RTTI),y)
-  ARCHCXXFLAGS += -fno-rtti
-endif
-
-LDFLAGS += -nostdlib
-
-# Optimization of unused sections
-
-ifeq ($(CONFIG_DEBUG_OPT_UNUSED_SECTIONS),y)
-  LDFLAGS          += --gc-sections
-  ARCHOPTIMIZATION += -ffunction-sections -fdata-sections
-endif
-
-# Debug link map
-
-ifeq ($(CONFIG_DEBUG_LINK_MAP),y)
-  LDFLAGS += --cref -Map=$(call CONVERT_PATH,$(TOPDIR)$(DELIM)nuttx.map)
-endif
-
-ifeq ($(CONFIG_DEBUG_SYMBOLS),y)
-  ARCHOPTIMIZATION += -g
-endif
-
-# Add the builtin library
-
-COMPILER_RT_LIB = $(shell $(CC) $(ARCHCPUFLAGS) --print-libgcc-file-name)
-ifeq ($(CONFIG_TOOLCHAIN),CLANG)
-  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
-endif
-
-EXTRA_LIBS += $(COMPILER_RT_LIB)
-
-ifneq ($(CONFIG_LIBM),y)
-  EXTRA_LIBS += $(wildcard $(shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libm.a))
-endif
-
-ifeq ($(CONFIG_LIBSUPCXX),y)
-  EXTRA_LIBS += $(wildcard $(shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libsupc++.a))
-endif
-
-ifeq ($(CONFIG_ARCH_COVERAGE),y)
-  EXTRA_LIBS += $(wildcard $(shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libgcov.a))
-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 9cb0273223..1d44918a10 100644
--- a/arch/arm/src/armv7-a/Toolchain.defs
+++ b/arch/arm/src/armv7-a/Toolchain.defs
@@ -18,41 +18,6 @@
 #
 ############################################################################
 
-# Setup for the selected toolchain
-
-#
-# Select and allow the selected toolchain to be overridden by a command-line
-#selection.
-#
-
-ifeq ($(filter y, \
-      $(CONFIG_ARM_TOOLCHAIN_BUILDROOT) \
-    ),y)
-  CONFIG_TOOLCHAIN ?= BUILDROOT
-endif
-
-ifeq ($(filter y, \
-      $(CONFIG_ARM_TOOLCHAIN_GNU_EABI) \
-    ),y)
-  CONFIG_TOOLCHAIN ?= GNU_EABI
-endif
-
-#
-# Supported toolchains
-#
-# Each toolchain definition should set:
-#
-#  CROSSDEV         The GNU toolchain triple (command prefix)
-#  ARCHCPUFLAGS     CPU-specific flags selecting the instruction set
-#                   FPU options, etc.
-#  ARCHOPTIMIZATION The optimization level that results in
-#                   reliable code generation.
-#
-
-ifeq ($(CONFIG_ARM_THUMB),y)
-  ARCHCPUFLAGS += -mthumb
-endif
-
 ifeq ($(CONFIG_ARCH_CORTEXA5),y)
   ARCHCPUFLAGS += -mcpu=cortex-a5
 else ifeq ($(CONFIG_ARCH_CORTEXA7),y)
@@ -96,134 +61,4 @@ else
   ARCHCPUFLAGS += -mfloat-abi=soft
 endif
 
-ifeq ($(CONFIG_MM_KASAN_ALL),y)
-  ARCHOPTIMIZATION += -fsanitize=kernel-address
-endif
-
-ifeq ($(CONFIG_DEBUG_CUSTOMOPT),y)
-  ARCHOPTIMIZATION += $(CONFIG_DEBUG_OPTLEVEL)
-else ifeq ($(CONFIG_DEBUG_FULLOPT),y)
-  ARCHOPTIMIZATION += -Os
-endif
-
-ifneq ($(CONFIG_DEBUG_NOOPT),y)
-  ARCHOPTIMIZATION += -fno-strict-aliasing
-endif
-
-ifeq ($(CONFIG_FRAME_POINTER),y)
-  ARCHOPTIMIZATION += -fno-omit-frame-pointer -fno-optimize-sibling-calls
-else
-  ARCHOPTIMIZATION += -fomit-frame-pointer
-endif
-
-ifeq ($(CONFIG_STACK_CANARIES),y)
-  ARCHOPTIMIZATION += -fstack-protector-all
-endif
-
-ifeq ($(CONFIG_ARCH_COVERAGE_ALL),y)
-  ARCHOPTIMIZATION += -fprofile-generate -ftest-coverage
-endif
-
-ifeq ($(CONFIG_MM_UBSAN_ALL),y)
-  ARCHOPTIMIZATION += $(CONFIG_MM_UBSAN_OPTION)
-endif
-
-ifeq ($(CONFIG_MM_UBSAN_TRAP_ON_ERROR),y)
-  ARCHOPTIMIZATION += -fsanitize-undefined-trap-on-error
-endif
-
-ifeq ($(CONFIG_ENDIAN_BIG),y)
-  TARGET_ARCH := armeb
-else
-  TARGET_ARCH := arm
-endif
-
-ARCHCFLAGS += -fno-common
-ARCHCXXFLAGS += -fno-common -nostdinc++
-
-ARCHCFLAGS += -Wall -Wstrict-prototypes -Wshadow -Wundef
-ARCHCXXFLAGS += -Wall -Wshadow -Wundef
-
-ifneq ($(CONFIG_CXX_EXCEPTION),y)
-  ARCHCXXFLAGS += -fno-exceptions -fcheck-new
-endif
-
-ifneq ($(CONFIG_CXX_RTTI),y)
-  ARCHCXXFLAGS += -fno-rtti
-endif
-
-LDFLAGS += -nostdlib
-
-# Optimization of unused sections
-
-ifeq ($(CONFIG_DEBUG_OPT_UNUSED_SECTIONS),y)
-  LDFLAGS          += --gc-sections
-  ARCHOPTIMIZATION += -ffunction-sections -fdata-sections
-endif
-
-# Debug link map
-
-ifeq ($(CONFIG_DEBUG_LINK_MAP),y)
-  LDFLAGS += --cref -Map=$(call CONVERT_PATH,$(TOPDIR)$(DELIM)nuttx.map)
-endif
-
-ifeq ($(CONFIG_DEBUG_SYMBOLS),y)
-  ARCHOPTIMIZATION += -g
-endif
-
-# NuttX buildroot under Linux or Cygwin
-
-ifeq ($(CONFIG_ARM_TOOLCHAIN_BUILDROOT),y)
-  CROSSDEV ?= $(TARGET_ARCH)-nuttx-eabi-
-endif
-
-ifeq ($(CONFIG_ARM_TOOLCHAIN_BUILDROOT_OABI),y)
-  CROSSDEV ?= $(TARGET_ARCH)-nuttx-elf-
-endif
-
-# Generic GNU EABI toolchain
-
-ifeq ($(CONFIG_TOOLCHAIN),GNU_EABI)
-  CROSSDEV ?= $(TARGET_ARCH)-none-eabi-
-endif
-
-# Default toolchain
-
-CC      = $(CROSSDEV)gcc
-CXX     = $(CROSSDEV)g++
-CPP     = $(CROSSDEV)gcc -E -P -x c
-STRIP   = $(CROSSDEV)strip --strip-unneeded
-OBJCOPY = $(CROSSDEV)objcopy
-OBJDUMP = $(CROSSDEV)objdump
-LD      = $(CROSSDEV)ld
-AR      = $(CROSSDEV)ar rcs
-NM      = $(CROSSDEV)nm
-
-# Link Time Optimization
-
-ifeq ($(CONFIG_LTO_FULL),y)
-  ARCHOPTIMIZATION += -flto
-  ifeq ($(CONFIG_TOOLCHAIN),GNU_EABI)
-    LD := $(CROSSDEV)gcc
-    AR := $(CROSSDEV)gcc-ar rcs
-    NM := $(CROSSDEV)gcc-nm
-    ARCHOPTIMIZATION += -fuse-linker-plugin
-    ARCHOPTIMIZATION += -fno-builtin
-  endif
-endif
-
-# Add the builtin library
-
-EXTRA_LIBS += $(wildcard $(shell $(CC) $(ARCHCPUFLAGS) --print-libgcc-file-name))
-
-ifneq ($(CONFIG_LIBM),y)
-  EXTRA_LIBS += $(wildcard $(shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libm.a))
-endif
-
-ifeq ($(CONFIG_LIBSUPCXX),y)
-  EXTRA_LIBS += $(wildcard $(shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libsupc++.a))
-endif
-
-ifeq ($(CONFIG_ARCH_COVERAGE),y)
-  EXTRA_LIBS += $(wildcard $(shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libgcov.a))
-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 5e7f6c63b5..07f939ec38 100644
--- a/arch/arm/src/armv7-m/Toolchain.defs
+++ b/arch/arm/src/armv7-m/Toolchain.defs
@@ -18,85 +18,6 @@
 #
 ############################################################################
 
-# Setup for the selected toolchain
-
-#
-# Handle old-style chip-specific toolchain names in the absence of
-# a new-style toolchain specification, force the selection of a single
-# toolchain and allow the selected toolchain to be overridden by a
-# command-line selection.
-#
-
-ifeq ($(filter y, \
-      $(CONFIG_ARM_TOOLCHAIN_BUILDROOT) \
-    ),y)
-  CONFIG_TOOLCHAIN ?= BUILDROOT
-endif
-
-ifeq ($(filter y, \
-      $(CONFIG_ARM_TOOLCHAIN_GNU_EABI) \
-    ),y)
-  CONFIG_TOOLCHAIN ?= GNU_EABI
-endif
-
-ifeq ($(filter y, \
-      $(CONFIG_ARM_TOOLCHAIN_CLANG) \
-    ),y)
-  CONFIG_TOOLCHAIN ?= CLANG
-endif
-
-#
-# Supported toolchains
-#
-# Each toolchain definition should set:
-#
-#  CROSSDEV         The GNU toolchain triple (command prefix)
-#  ARCHCPUFLAGS     CPU-specific flags selecting the instruction set
-#                   FPU options, etc.
-#  ARCHOPTIMIZATION The optimization level that results in
-#                   reliable code generation.
-#
-
-ifeq ($(CONFIG_DEBUG_CUSTOMOPT),y)
-  ARCHOPTIMIZATION += $(CONFIG_DEBUG_OPTLEVEL)
-else ifeq ($(CONFIG_DEBUG_FULLOPT),y)
-  ifeq ($(CONFIG_TOOLCHAIN),CLANG)
-    ARCHOPTIMIZATION += -Oz
-  else
-    ARCHOPTIMIZATION += -Os
-  endif
-endif
-
-ifneq ($(CONFIG_DEBUG_NOOPT),y)
-  ARCHOPTIMIZATION += -fno-strict-aliasing
-endif
-
-ifeq ($(CONFIG_FRAME_POINTER),y)
-  ARCHOPTIMIZATION += -fno-omit-frame-pointer -fno-optimize-sibling-calls
-else
-  ARCHOPTIMIZATION += -fomit-frame-pointer
-endif
-
-ifeq ($(CONFIG_STACK_CANARIES),y)
-  ARCHOPTIMIZATION += -fstack-protector-all
-endif
-
-ifeq ($(CONFIG_ARCH_COVERAGE_ALL),y)
-  ARCHOPTIMIZATION += -fprofile-generate -ftest-coverage
-endif
-
-ifeq ($(CONFIG_ARMV7M_STACKCHECK),y)
-  ARCHOPTIMIZATION += -finstrument-functions -ffixed-r10
-endif
-
-ifeq ($(CONFIG_MM_UBSAN_ALL),y)
-  ARCHOPTIMIZATION += $(CONFIG_MM_UBSAN_OPTION)
-endif
-
-ifeq ($(CONFIG_MM_UBSAN_TRAP_ON_ERROR),y)
-  ARCHOPTIMIZATION += -fsanitize-undefined-trap-on-error
-endif
-
 # Parametrization for ARCHCPUFLAGS
 
 ifeq ($(CONFIG_ARCH_CORTEXM4),y)
@@ -136,7 +57,7 @@ endif
 
 # Clang Configuration files
 
-ifeq ($(CONFIG_TOOLCHAIN),CLANG)
+ifeq ($(CONFIG_ARM_TOOLCHAIN_CLANG),y)
 
   ifeq ($(CONFIG_ARCH_CORTEXM4),y)
     ifeq ($(CONFIG_ARCH_FPU),y)
@@ -156,140 +77,8 @@ ifeq ($(CONFIG_TOOLCHAIN),CLANG)
 
 endif
 
-# Link Time Optimization
-
-ifeq ($(CONFIG_LTO_THIN),y)
-  ARCHOPTIMIZATION += -flto=thin
-else ifeq ($(CONFIG_LTO_FULL),y)
-  ARCHOPTIMIZATION += -flto
-  ifeq ($(CONFIG_TOOLCHAIN),GNU_EABI)
-    ARCHOPTIMIZATION += -fuse-linker-plugin
-  endif
-endif
-
-# NuttX buildroot under Linux or Cygwin
-
-ifeq ($(CONFIG_ARM_TOOLCHAIN_BUILDROOT),y)
-  CROSSDEV ?= arm-nuttx-eabi-
-  ARCHCPUFLAGS = $(TOOLCHAIN_MARCH) $(TOOLCHAIN_MTUNE) -mthumb $(TOOLCHAIN_MFLOAT)
-endif
-
-ifeq ($(CONFIG_ARM_TOOLCHAIN_BUILDROOT_OABI),y)
-  CROSSDEV ?= arm-nuttx-elf-
-  ARCHCPUFLAGS = $(TOOLCHAIN_MARCH) $(TOOLCHAIN_MTUNE) $(TOOLCHAIN_MFLOAT)
-endif
-
-ifeq ($(CONFIG_MM_KASAN_ALL),y)
-  ARCHOPTIMIZATION += -fsanitize=kernel-address
-endif
-
-# Generic GNU EABI toolchain
-
-ifeq ($(CONFIG_TOOLCHAIN),GNU_EABI)
-  CROSSDEV ?= arm-none-eabi-
-  ARCHCPUFLAGS = $(TOOLCHAIN_MARCH) $(TOOLCHAIN_MTUNE) -mthumb $(TOOLCHAIN_MFLOAT)
-endif
-
-# Clang toolchain
-
-ifeq ($(CONFIG_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
-
-  ARCHOPTIMIZATION += -fno-builtin
-
-# Default toolchain
-
-else
-  CC      = $(CROSSDEV)gcc
-  CXX     = $(CROSSDEV)g++
-  CPP     = $(CROSSDEV)gcc -E -P -x c
-  STRIP   = $(CROSSDEV)strip --strip-unneeded
-  OBJCOPY = $(CROSSDEV)objcopy
-  OBJDUMP = $(CROSSDEV)objdump
-  LD      = $(CROSSDEV)ld
-  AR      = $(CROSSDEV)ar rcs
-  NM      = $(CROSSDEV)nm
-
-  ifeq ($(CONFIG_LTO_FULL),y)
-    ifeq ($(CONFIG_TOOLCHAIN),GNU_EABI)
-      LD := $(CROSSDEV)gcc
-      AR := $(CROSSDEV)gcc-ar rcs
-      NM := $(CROSSDEV)gcc-nm
-      ARCHOPTIMIZATION += -fno-builtin
-    endif
-  endif
-endif
-
-# Architecture flags
-
-ARCHCFLAGS += -fno-common
-ARCHCXXFLAGS += -fno-common -nostdinc++
-
-ARCHCFLAGS += -Wall -Wstrict-prototypes -Wshadow -Wundef
-ARCHCXXFLAGS += -Wall -Wshadow -Wundef
-
-ifneq ($(CONFIG_CXX_EXCEPTION),y)
-  ARCHCXXFLAGS += -fno-exceptions -fcheck-new
-endif
-
-ifneq ($(CONFIG_CXX_RTTI),y)
-  ARCHCXXFLAGS += -fno-rtti
-endif
-
-LDFLAGS += -nostdlib
-
-# Optimization of unused sections
-
-ifeq ($(CONFIG_DEBUG_OPT_UNUSED_SECTIONS),y)
-  LDFLAGS          += --gc-sections
-  ARCHOPTIMIZATION += -ffunction-sections -fdata-sections
-endif
-
-# Debug link map
-
-ifeq ($(CONFIG_DEBUG_LINK_MAP),y)
-  LDFLAGS += --cref -Map=$(call CONVERT_PATH,$(TOPDIR)$(DELIM)nuttx.map)
-endif
-
-ifeq ($(CONFIG_DEBUG_SYMBOLS),y)
-  ARCHOPTIMIZATION += -g
-endif
-
-# Add the builtin library
-
-COMPILER_RT_LIB = $(shell $(CC) $(ARCHCPUFLAGS) --print-libgcc-file-name)
-ifeq ($(CONFIG_TOOLCHAIN),CLANG)
-  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
-endif
-
-EXTRA_LIBS += $(COMPILER_RT_LIB)
-
-ifneq ($(CONFIG_LIBM),y)
-  EXTRA_LIBS += $(wildcard $(shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libm.a))
-endif
-
-ifeq ($(CONFIG_LIBSUPCXX),y)
-  EXTRA_LIBS += $(wildcard $(shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libsupc++.a))
+ifeq ($(CONFIG_ARMV7M_STACKCHECK),y)
+  ARCHOPTIMIZATION += -finstrument-functions -ffixed-r10
 endif
 
-ifeq ($(CONFIG_ARCH_COVERAGE),y)
-  EXTRA_LIBS += $(wildcard $(shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libgcov.a))
-endif
+include $(TOPDIR)/arch/arm/src/common/Toolchain.defs
diff --git a/arch/arm/src/armv7-r/Toolchain.defs b/arch/arm/src/armv7-r/Toolchain.defs
index 627f50556d..6ee10178f3 100644
--- a/arch/arm/src/armv7-r/Toolchain.defs
+++ b/arch/arm/src/armv7-r/Toolchain.defs
@@ -18,61 +18,6 @@
 #
 ############################################################################
 
-# Setup for the selected toolchain
-
-#
-# Select and allow the selected toolchain to be overridden by a command-line
-#selection.
-#
-
-ifeq ($(filter y, \
-      $(CONFIG_ARM_TOOLCHAIN_BUILDROOT) \
-    ),y)
-  CONFIG_TOOLCHAIN ?= BUILDROOT
-endif
-
-ifeq ($(filter y, \
-      $(CONFIG_ARM_TOOLCHAIN_GNU_EABI) \
-    ),y)
-  CONFIG_TOOLCHAIN ?= GNU_EABI
-endif
-
-#
-# Supported toolchains
-#
-# Each toolchain definition should set:
-#
-#  CROSSDEV         The GNU toolchain triple (command prefix)
-#  ARCHCPUFLAGS     CPU-specific flags selecting the instruction set
-#                   FPU options, etc.
-#  ARCHOPTIMIZATION The optimization level that results in
-#                   reliable code generation.
-#
-
-ifeq ($(CONFIG_DEBUG_CUSTOMOPT),y)
-  ARCHOPTIMIZATION += $(CONFIG_DEBUG_OPTLEVEL)
-else ifeq ($(CONFIG_DEBUG_FULLOPT),y)
-  ARCHOPTIMIZATION += -Os
-endif
-
-ifneq ($(CONFIG_DEBUG_NOOPT),y)
-  ARCHOPTIMIZATION += -fno-strict-aliasing
-endif
-
-ifeq ($(CONFIG_FRAME_POINTER),y)
-  ARCHOPTIMIZATION += -fno-omit-frame-pointer -fno-optimize-sibling-calls
-else
-  ARCHOPTIMIZATION += -fomit-frame-pointer
-endif
-
-ifeq ($(CONFIG_STACK_CANARIES),y)
-  ARCHOPTIMIZATION += -fstack-protector-all
-endif
-
-ifeq ($(CONFIG_ARCH_COVERAGE_ALL),y)
-  ARCHOPTIMIZATION += -fprofile-generate -ftest-coverage
-endif
-
 ifeq ($(CONFIG_ARCH_CORTEXR4),y)
   ARCHCPUFLAGS += -mcpu=cortex-r4
 else ifeq ($(CONFIG_ARCH_CORTEXR5),y)
@@ -92,114 +37,4 @@ else
   ARCHCPUFLAGS += -mfloat-abi=soft
 endif
 
-ifeq ($(CONFIG_ENDIAN_BIG),y)
-  ARCHCPUFLAGS += -mbig-endian
-endif
-
-ifeq ($(CONFIG_MM_KASAN_ALL),y)
-  ARCHOPTIMIZATION += -fsanitize=kernel-address
-endif
-
-ifeq ($(CONFIG_MM_UBSAN_ALL),y)
-  ARCHOPTIMIZATION += $(CONFIG_MM_UBSAN_OPTION)
-endif
-
-ifeq ($(CONFIG_MM_UBSAN_TRAP_ON_ERROR),y)
-  ARCHOPTIMIZATION += -fsanitize-undefined-trap-on-error
-endif
-
-ifeq ($(CONFIG_ENDIAN_BIG),y)
-  TARGET_ARCH := armeb
-else
-  TARGET_ARCH := arm
-endif
-
-# NuttX buildroot under Linux or Cygwin
-
-ifeq ($(CONFIG_ARM_TOOLCHAIN_BUILDROOT),y)
-  CROSSDEV ?= $(TARGET_ARCH)-nuttx-eabi-
-endif
-
-ifeq ($(CONFIG_ARM_TOOLCHAIN_BUILDROOT_OABI),y)
-  CROSSDEV ?= $(TARGET_ARCH)-nuttx-elf-
-endif
-
-# Generic GNU EABI toolchain
-
-ifeq ($(CONFIG_TOOLCHAIN),GNU_EABI)
-  CROSSDEV ?= $(TARGET_ARCH)-none-eabi-
-endif
-
-ARCHCFLAGS += -fno-common
-ARCHCXXFLAGS += -fno-common -nostdinc++
-
-ARCHCFLAGS += -Wall -Wstrict-prototypes -Wshadow -Wundef
-ARCHCXXFLAGS += -Wall -Wshadow -Wundef
-
-ifneq ($(CONFIG_CXX_EXCEPTION),y)
-  ARCHCXXFLAGS += -fno-exceptions -fcheck-new
-endif
-
-ifneq ($(CONFIG_CXX_RTTI),y)
-  ARCHCXXFLAGS += -fno-rtti
-endif
-
-LDFLAGS += -nostdlib
-
-# Optimization of unused sections
-
-ifeq ($(CONFIG_DEBUG_OPT_UNUSED_SECTIONS),y)
-  LDFLAGS          += --gc-sections
-  ARCHOPTIMIZATION += -ffunction-sections -fdata-sections
-endif
-
-# Debug link map
-
-ifeq ($(CONFIG_DEBUG_LINK_MAP),y)
-  LDFLAGS += --cref -Map=$(call CONVERT_PATH,$(TOPDIR)$(DELIM)nuttx.map)
-endif
-
-ifeq ($(CONFIG_DEBUG_SYMBOLS),y)
-  ARCHOPTIMIZATION += -g
-endif
-
-# Default toolchain
-
-CC      = $(CROSSDEV)gcc
-CXX     = $(CROSSDEV)g++
-CPP     = $(CROSSDEV)gcc -E -P -x c
-STRIP   = $(CROSSDEV)strip --strip-unneeded
-OBJCOPY = $(CROSSDEV)objcopy
-OBJDUMP = $(CROSSDEV)objdump
-LD      = $(CROSSDEV)ld
-AR      = $(CROSSDEV)ar rcs
-NM      = $(CROSSDEV)nm
-
-# Link Time Optimization
-
-ifeq ($(CONFIG_LTO_FULL),y)
-  ARCHOPTIMIZATION += -flto
-  ifeq ($(CONFIG_TOOLCHAIN),GNU_EABI)
-    LD := $(CROSSDEV)gcc
-    AR := $(CROSSDEV)gcc-ar rcs
-    NM := $(CROSSDEV)gcc-nm
-    ARCHOPTIMIZATION += -fuse-linker-plugin
-    ARCHOPTIMIZATION += -fno-builtin
-  endif
-endif
-
-# Add the builtin library
-
-EXTRA_LIBS += $(wildcard $(shell $(CC) $(ARCHCPUFLAGS) --print-libgcc-file-name))
-
-ifneq ($(CONFIG_LIBM),y)
-  EXTRA_LIBS += $(wildcard $(shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libm.a))
-endif
-
-ifeq ($(CONFIG_LIBSUPCXX),y)
-  EXTRA_LIBS += $(wildcard $(shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libsupc++.a))
-endif
-
-ifeq ($(CONFIG_ARCH_COVERAGE),y)
-  EXTRA_LIBS += $(wildcard $(shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libgcov.a))
-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 cd228683ba..8ad07e0def 100644
--- a/arch/arm/src/armv8-m/Toolchain.defs
+++ b/arch/arm/src/armv8-m/Toolchain.defs
@@ -18,85 +18,6 @@
 #
 ############################################################################
 
-# Setup for the selected toolchain
-
-#
-# Handle old-style chip-specific toolchain names in the absence of
-# a new-style toolchain specification, force the selection of a single
-# toolchain and allow the selected toolchain to be overridden by a
-# command-line selection.
-#
-
-ifeq ($(filter y, \
-      $(CONFIG_ARM_TOOLCHAIN_BUILDROOT) \
-    ),y)
-  CONFIG_TOOLCHAIN ?= BUILDROOT
-endif
-
-ifeq ($(filter y, \
-      $(CONFIG_ARM_TOOLCHAIN_GNU_EABI) \
-    ),y)
-  CONFIG_TOOLCHAIN ?= GNU_EABI
-endif
-
-ifeq ($(filter y, \
-      $(CONFIG_ARM_TOOLCHAIN_CLANG) \
-    ),y)
-  CONFIG_TOOLCHAIN ?= CLANG
-endif
-
-#
-# Supported toolchains
-#
-# Each toolchain definition should set:
-#
-#  CROSSDEV         The GNU toolchain triple (command prefix)
-#  ARCHCPUFLAGS     CPU-specific flags selecting the instruction set
-#                   FPU options, etc.
-#  ARCHOPTIMIZATION The optimization level that results in
-#                   reliable code generation.
-#
-
-ifeq ($(CONFIG_DEBUG_CUSTOMOPT),y)
-  ARCHOPTIMIZATION += $(CONFIG_DEBUG_OPTLEVEL)
-else ifeq ($(CONFIG_DEBUG_FULLOPT),y)
-  ifeq ($(CONFIG_TOOLCHAIN),CLANG)
-    ARCHOPTIMIZATION += -Oz
-  else
-    ARCHOPTIMIZATION += -Os
-  endif
-endif
-
-ifneq ($(CONFIG_DEBUG_NOOPT),y)
-  ARCHOPTIMIZATION += -fno-strict-aliasing
-endif
-
-ifeq ($(CONFIG_FRAME_POINTER),y)
-  ARCHOPTIMIZATION += -fno-omit-frame-pointer -fno-optimize-sibling-calls
-else
-  ARCHOPTIMIZATION += -fomit-frame-pointer
-endif
-
-ifeq ($(CONFIG_STACK_CANARIES),y)
-  ARCHOPTIMIZATION += -fstack-protector-all
-endif
-
-ifeq ($(CONFIG_ARCH_COVERAGE_ALL),y)
-  ARCHOPTIMIZATION += -fprofile-generate -ftest-coverage
-endif
-
-ifeq ($(CONFIG_ARMV8M_STACKCHECK),y)
-  ARCHOPTIMIZATION += -finstrument-functions -ffixed-r10
-endif
-
-ifeq ($(CONFIG_MM_UBSAN_ALL),y)
-  ARCHOPTIMIZATION += $(CONFIG_MM_UBSAN_OPTION)
-endif
-
-ifeq ($(CONFIG_MM_UBSAN_TRAP_ON_ERROR),y)
-  ARCHOPTIMIZATION += -fsanitize-undefined-trap-on-error
-endif
-
 # Parametrization for ARCHCPUFLAGS
 
 ifeq ($(CONFIG_ARCH_CORTEXM23),y)
@@ -139,7 +60,7 @@ endif
 
 # Clang Configuration files
 
-ifeq ($(CONFIG_TOOLCHAIN),CLANG)
+ifeq ($(CONFIG_ARM_TOOLCHAIN_CLANG),y)
 
   ifeq ($(CONFIG_ARCH_CORTEXM23),y)
     TOOLCHAIN_MARCH += --config armv8m.main_soft_nofp_nosys
@@ -165,140 +86,8 @@ ifeq ($(CONFIG_TOOLCHAIN),CLANG)
 
 endif
 
-# Link Time Optimization
-
-ifeq ($(CONFIG_LTO_THIN),y)
-  ARCHOPTIMIZATION += -flto=thin
-else ifeq ($(CONFIG_LTO_FULL),y)
-  ARCHOPTIMIZATION += -flto
-  ifeq ($(CONFIG_TOOLCHAIN),GNU_EABI)
-    ARCHOPTIMIZATION += -fuse-linker-plugin
-  endif
-endif
-
-# NuttX buildroot under Linux or Cygwin
-
-ifeq ($(CONFIG_ARM_TOOLCHAIN_BUILDROOT),y)
-  CROSSDEV ?= arm-nuttx-eabi-
-  ARCHCPUFLAGS = $(TOOLCHAIN_MARCH) $(TOOLCHAIN_MTUNE) -mthumb $(TOOLCHAIN_MFLOAT)
-endif
-
-ifeq ($(CONFIG_ARM_TOOLCHAIN_BUILDROOT_OABI),y)
-  CROSSDEV ?= arm-nuttx-elf-
-  ARCHCPUFLAGS = $(TOOLCHAIN_MARCH) $(TOOLCHAIN_MTUNE) $(TOOLCHAIN_MFLOAT)
-endif
-
-ifeq ($(CONFIG_MM_KASAN_ALL),y)
-  ARCHOPTIMIZATION += -fsanitize=kernel-address
-endif
-
-# Generic GNU EABI toolchain
-
-ifeq ($(CONFIG_TOOLCHAIN),GNU_EABI)
-  CROSSDEV ?= arm-none-eabi-
-  ARCHCPUFLAGS = $(TOOLCHAIN_MARCH) $(TOOLCHAIN_MTUNE) -mthumb $(TOOLCHAIN_MFLOAT)
-endif
-
-# Clang toolchain
-
-ifeq ($(CONFIG_TOOLCHAIN),CLANG)
-  ARCHCPUFLAGS = $(TOOLCHAIN_MARCH) $(TOOLCHAIN_MTUNE) -mthumb $(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
-
-  ARCHOPTIMIZATION += -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
-
-  ifeq ($(CONFIG_LTO_FULL),y)
-    ifeq ($(CONFIG_TOOLCHAIN),GNU_EABI)
-      LD := $(CROSSDEV)gcc
-      AR := $(CROSSDEV)gcc-ar rcs
-      NM := $(CROSSDEV)gcc-nm
-      ARCHOPTIMIZATION += -fno-builtin
-    endif
-  endif
-endif
-
-# Architecture flags
-
-ARCHCFLAGS += -fno-common
-ARCHCXXFLAGS += -fno-common -nostdinc++
-
-ARCHCFLAGS += -Wall -Wstrict-prototypes -Wshadow -Wundef
-ARCHCXXFLAGS += -Wall -Wshadow -Wundef
-
-ifneq ($(CONFIG_CXX_EXCEPTION),y)
-  ARCHCXXFLAGS += -fno-exceptions -fcheck-new
-endif
-
-ifneq ($(CONFIG_CXX_RTTI),y)
-  ARCHCXXFLAGS += -fno-rtti
-endif
-
-LDFLAGS += -nostdlib
-
-# Optimization of unused sections
-
-ifeq ($(CONFIG_DEBUG_OPT_UNUSED_SECTIONS),y)
-  LDFLAGS          += --gc-sections
-  ARCHOPTIMIZATION += -ffunction-sections -fdata-sections
-endif
-
-# Debug link map
-
-ifeq ($(CONFIG_DEBUG_LINK_MAP),y)
-  LDFLAGS += --cref -Map=$(call CONVERT_PATH,$(TOPDIR)$(DELIM)nuttx.map)
-endif
-
-ifeq ($(CONFIG_DEBUG_SYMBOLS),y)
-  ARCHOPTIMIZATION += -g
-endif
-
-# Add the builtin library
-
-COMPILER_RT_LIB = $(shell $(CC) $(ARCHCPUFLAGS) --print-libgcc-file-name)
-ifeq ($(CONFIG_TOOLCHAIN),CLANG)
-  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
-endif
-
-EXTRA_LIBS += $(COMPILER_RT_LIB)
-
-ifneq ($(CONFIG_LIBM),y)
-  EXTRA_LIBS += $(wildcard $(shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libm.a))
-endif
-
-ifeq ($(CONFIG_LIBSUPCXX),y)
-  EXTRA_LIBS += $(wildcard $(shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libsupc++.a))
+ifeq ($(CONFIG_ARMV8M_STACKCHECK),y)
+  ARCHOPTIMIZATION += -finstrument-functions -ffixed-r10
 endif
 
-ifeq ($(CONFIG_ARCH_COVERAGE),y)
-  EXTRA_LIBS += $(wildcard $(shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libgcov.a))
-endif
+include $(TOPDIR)/arch/arm/src/common/Toolchain.defs
diff --git a/arch/arm/src/armv6-m/Toolchain.defs b/arch/arm/src/common/Toolchain.defs
similarity index 73%
copy from arch/arm/src/armv6-m/Toolchain.defs
copy to arch/arm/src/common/Toolchain.defs
index 102f803219..29ad342faa 100644
--- a/arch/arm/src/armv6-m/Toolchain.defs
+++ b/arch/arm/src/common/Toolchain.defs
@@ -1,5 +1,5 @@
 ############################################################################
-# arch/arm/src/armv6-m/Toolchain.defs
+# arch/arm/src/armv8-m/Toolchain.defs
 #
 # Licensed to the Apache Software Foundation (ASF) under one or more
 # contributor license agreements.  See the NOTICE file distributed with
@@ -18,39 +18,14 @@
 #
 ############################################################################
 
-# Setup for the selected toolchain
-
-#
-# Handle old-style chip-specific toolchain names in the absence of
-# a new-style toolchain specification, force the selection of a single
-# toolchain and allow the selected toolchain to be overridden by a
-# command-line selection.
-#
-
-ifeq ($(filter y, $(CONFIG_ARM_TOOLCHAIN_BUILDROOT)),y)
-  CONFIG_TOOLCHAIN ?= BUILDROOT
-endif
-
-ifeq ($(filter y, $(CONFIG_ARM_TOOLCHAIN_GNU_EABI)),y)
-  CONFIG_TOOLCHAIN ?= GNU_EABI
-endif
-
-ifeq ($(filter y, $(CONFIG_ARM_TOOLCHAIN_CLANG)),y)
-  CONFIG_TOOLCHAIN ?= CLANG
-endif
-
 #
 # Supported toolchains
 #
-# TODO - It's likely that all of these toolchains now support the
-#        CortexM0.  Since they are all GCC-based, we could almost
-#        certainly simplify this further.
-#
 # Each toolchain definition should set:
 #
 #  CROSSDEV         The GNU toolchain triple (command prefix)
 #  ARCHCPUFLAGS     CPU-specific flags selecting the instruction set
-#                   options, etc.
+#                   FPU options, etc.
 #  ARCHOPTIMIZATION The optimization level that results in
 #                   reliable code generation.
 #
@@ -58,7 +33,7 @@ endif
 ifeq ($(CONFIG_DEBUG_CUSTOMOPT),y)
   ARCHOPTIMIZATION += $(CONFIG_DEBUG_OPTLEVEL)
 else ifeq ($(CONFIG_DEBUG_FULLOPT),y)
-  ifeq ($(CONFIG_TOOLCHAIN),CLANG)
+  ifeq ($(CONFIG_ARCH_TOOLCHAIN_CLANG),y)
     ARCHOPTIMIZATION += -Oz
   else
     ARCHOPTIMIZATION += -Os
@@ -83,15 +58,20 @@ ifeq ($(CONFIG_ARCH_COVERAGE_ALL),y)
   ARCHOPTIMIZATION += -fprofile-generate -ftest-coverage
 endif
 
-# Parametrization for ARCHCPUFLAGS
+ifeq ($(CONFIG_MM_UBSAN_ALL),y)
+  ARCHOPTIMIZATION += $(CONFIG_MM_UBSAN_OPTION)
+endif
 
-TOOLCHAIN_MTUNE  := -mcpu=cortex-m0 -mthumb
-TOOLCHAIN_MFLOAT := -mfloat-abi=soft
+ifeq ($(CONFIG_MM_UBSAN_TRAP_ON_ERROR),y)
+  ARCHOPTIMIZATION += -fsanitize-undefined-trap-on-error
+endif
 
-# Clang Configuration files
+ifeq ($(CONFIG_MM_KASAN_ALL),y)
+  ARCHOPTIMIZATION += -fsanitize=kernel-address
+endif
 
-ifeq ($(CONFIG_TOOLCHAIN),CLANG)
-  TOOLCHAIN_MARCH := --config armv6m_soft_nofp_nosys
+ifeq ($(CONFIG_ARM_THUMB),y)
+  ARCHOPTIMIZATION += -mthumb
 endif
 
 # Link Time Optimization
@@ -100,29 +80,40 @@ ifeq ($(CONFIG_LTO_THIN),y)
   ARCHOPTIMIZATION += -flto=thin
 else ifeq ($(CONFIG_LTO_FULL),y)
   ARCHOPTIMIZATION += -flto
-  ifeq ($(CONFIG_TOOLCHAIN),GNU_EABI)
+  ifeq ($(CONFIG_ARM_TOOLCHAIN_GNU_EABI),y)
     ARCHOPTIMIZATION += -fuse-linker-plugin
   endif
 endif
 
 # NuttX buildroot under Linux or Cygwin
 
-ifeq ($(CONFIG_TOOLCHAIN),BUILDROOT)
-  CROSSDEV ?= arm-nuttx-eabi-
-  ARCHCPUFLAGS = $(TOOLCHAIN_MARCH) $(TOOLCHAIN_MTUNE) $(TOOLCHAIN_MFLOAT)
+ifeq ($(CONFIG_ENDIAN_BIG),y)
+  ARCHCPUFLAGS += -mbig-endian
+  TARGET_ARCH := armeb
+else
+  ARCHCPUFLAGS += -mlittle-endian
+  TARGET_ARCH := arm
+endif
+
+ARCHCPUFLAGS += $(TOOLCHAIN_MARCH) $(TOOLCHAIN_MTUNE) $(TOOLCHAIN_MFLOAT)
+
+ifeq ($(CONFIG_ARM_TOOLCHAIN_BUILDROOT),y)
+  CROSSDEV ?= $(TARGET_ARCH)-nuttx-eabi-
+endif
+
+ifeq ($(CONFIG_ARM_TOOLCHAIN_BUILDROOT_OABI),y)
+  CROSSDEV ?= $(TARGET_ARCH)-nuttx-elf-
 endif
 
 # Generic GNU EABI toolchain
 
-ifeq ($(CONFIG_TOOLCHAIN),GNU_EABI)
-  CROSSDEV ?= arm-none-eabi-
-  ARCHCPUFLAGS = $(TOOLCHAIN_MARCH) $(TOOLCHAIN_MTUNE) $(TOOLCHAIN_MFLOAT)
+ifeq ($(CONFIG_ARM_TOOLCHAIN_GNU_EABI),y)
+  CROSSDEV ?= $(TARGET_ARCH)-none-eabi-
 endif
 
 # Clang toolchain
 
-ifeq ($(CONFIG_TOOLCHAIN),CLANG)
-  ARCHCPUFLAGS = $(TOOLCHAIN_MARCH) $(TOOLCHAIN_MTUNE) $(TOOLCHAIN_MFLOAT)
+ifeq ($(CONFIG_ARM_TOOLCHAIN_CLANG),y)
 
   CC      = clang
   CXX     = clang++
@@ -146,15 +137,15 @@ else
   CC      = $(CROSSDEV)gcc
   CXX     = $(CROSSDEV)g++
   CPP     = $(CROSSDEV)gcc -E -P -x c
-  STRIP   = $(CROSSDEV)strip --strip-unneeded
-  OBJCOPY = $(CROSSDEV)objcopy
-  OBJDUMP = $(CROSSDEV)objdump
   LD      = $(CROSSDEV)ld
+  STRIP   = $(CROSSDEV)strip --strip-unneeded
   AR      = $(CROSSDEV)ar rcs
   NM      = $(CROSSDEV)nm
+  OBJCOPY = $(CROSSDEV)objcopy
+  OBJDUMP = $(CROSSDEV)objdump
 
   ifeq ($(CONFIG_LTO_FULL),y)
-    ifeq ($(CONFIG_TOOLCHAIN),GNU_EABI)
+    ifeq ($(CONFIG_ARM_TOOLCHAIN_GNU_EABI),y)
       LD := $(CROSSDEV)gcc
       AR := $(CROSSDEV)gcc-ar rcs
       NM := $(CROSSDEV)gcc-nm
@@ -163,25 +154,14 @@ else
   endif
 endif
 
-# Architecture flags
-
-ifeq ($(CONFIG_MM_KASAN_ALL),y)
-  ARCHOPTIMIZATION += -fsanitize=kernel-address
-endif
-
-ifeq ($(CONFIG_MM_UBSAN_ALL),y)
-  ARCHOPTIMIZATION += $(CONFIG_MM_UBSAN_OPTION)
+ifeq ($(CONFIG_ARCH_TOOLCHAIN_CLANG),y)
+  ARCHOPTIMIZATION += -fshort-enums
 endif
 
-ifeq ($(CONFIG_MM_UBSAN_TRAP_ON_ERROR),y)
-  ARCHOPTIMIZATION += -fsanitize-undefined-trap-on-error
-endif
-
-ARCHCFLAGS += -fno-common
-ARCHCXXFLAGS += -fno-common -nostdinc++
+# Architecture flags
 
-ARCHCFLAGS += -Wall -Wstrict-prototypes -Wshadow -Wundef
-ARCHCXXFLAGS += -Wall -Wshadow -Wundef
+ARCHCFLAGS += -Wstrict-prototypes
+ARCHCXXFLAGS += -nostdinc++
 
 ifneq ($(CONFIG_CXX_EXCEPTION),y)
   ARCHCXXFLAGS += -fno-exceptions -fcheck-new
@@ -191,6 +171,9 @@ ifneq ($(CONFIG_CXX_RTTI),y)
   ARCHCXXFLAGS += -fno-rtti
 endif
 
+ARCHOPTIMIZATION += -fno-common -Wall -Wshadow -Wundef
+ARCHOPTIMIZATION += -nostdlib
+
 LDFLAGS += -nostdlib
 
 # Optimization of unused sections
@@ -213,7 +196,7 @@ endif
 # Add the builtin library
 
 COMPILER_RT_LIB = $(shell $(CC) $(ARCHCPUFLAGS) --print-libgcc-file-name)
-ifeq ($(CONFIG_TOOLCHAIN),CLANG)
+ifeq ($(CONFIG_ARCH_TOOLCHAIN_CLANG),y)
   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"
diff --git a/arch/arm/src/tlsr82/Toolchain.defs b/arch/arm/src/tlsr82/Toolchain.defs
index d4180df13c..410eae8aa9 100644
--- a/arch/arm/src/tlsr82/Toolchain.defs
+++ b/arch/arm/src/tlsr82/Toolchain.defs
@@ -18,182 +18,16 @@
 #
 ############################################################################
 
-# Setup for the selected toolchain
-
-#
-# Handle old-style chip-specific toolchain names in the absence of
-# a new-style toolchain specification, force the selection of a single
-# toolchain and allow the selected toolchain to be overridden by a
-# command-line selection.
-#
-
-ifeq ($(filter y, $(CONFIG_ARM_TOOLCHAIN_BUILDROOT)),y)
-  CONFIG_TOOLCHAIN ?= BUILDROOT
-endif
-
-ifeq ($(filter y, $(CONFIG_ARM_TOOLCHAIN_GNU_EABI)),y)
-  CONFIG_TOOLCHAIN ?= GNU_EABI
-endif
-
-ifeq ($(filter y, $(CONFIG_ARM_TOOLCHAIN_CLANG)),y)
-  CONFIG_TOOLCHAIN ?= CLANG
-endif
-
-#
-# Supported toolchains
-#
-# Each toolchain definition should set:
-#
-#  CROSSDEV         The GNU toolchain triple (command prefix)
-#  ARCHCPUFLAGS     CPU-specific flags selecting the instruction set
-#                   options, etc.
-#  ARCHOPTIMIZATION The optimization level that results in
-#                   reliable code generation.
-#
-
-ifeq ($(CONFIG_DEBUG_CUSTOMOPT),y)
-  ARCHOPTIMIZATION += $(CONFIG_DEBUG_OPTLEVEL)
-else ifeq ($(CONFIG_DEBUG_FULLOPT),y)
-  ifeq ($(CONFIG_TOOLCHAIN),CLANG)
-    ARCHOPTIMIZATION += -Oz
-  else
-    ARCHOPTIMIZATION += -Os
-  endif
-endif
-
-ifneq ($(CONFIG_DEBUG_NOOPT),y)
-  ARCHOPTIMIZATION += -fno-strict-aliasing
-endif
-
-ifeq ($(CONFIG_FRAME_POINTER),y)
-  ARCHOPTIMIZATION += -fno-omit-frame-pointer -fno-optimize-sibling-calls
-else
-  ARCHOPTIMIZATION += -fomit-frame-pointer
-endif
-
-ifeq ($(CONFIG_STACK_CANARIES),y)
-  ARCHOPTIMIZATION += -fstack-protector-all
-endif
-
 # Clang Configuration files
 
-ifeq ($(CONFIG_TOOLCHAIN),CLANG)
+ifeq ($(CONFIG_ARM_TOOLCHAIN_CLANG),y)
   TOOLCHAIN_MARCH := --config armv6m_soft_nofp_nosys
 endif
 
-# Link Time Optimization
-
-ifeq ($(CONFIG_LTO_THIN),y)
-  ARCHOPTIMIZATION += -flto=thin
-else ifeq ($(CONFIG_LTO_FULL),y)
-  ARCHOPTIMIZATION += -flto
-endif
-
-# NuttX buildroot under Linux or Cygwin
-
-ifeq ($(CONFIG_TOOLCHAIN),BUILDROOT)
-  CROSSDEV ?= arm-nuttx-eabi-
-  ARCHCPUFLAGS = $(TOOLCHAIN_MARCH) $(TOOLCHAIN_MTUNE) $(TOOLCHAIN_MFLOAT)
-endif
-
 # Generic GNU EABI toolchain
 
-ifeq ($(CONFIG_TOOLCHAIN),GNU_EABI)
+ifeq ($(CONFIG_ARM_TOOLCHAIN_GNU_EABI),y)
   CROSSDEV ?= tc32-elf-
-  ARCHCPUFLAGS = $(TOOLCHAIN_MARCH) $(TOOLCHAIN_MTUNE) $(TOOLCHAIN_MFLOAT)
-endif
-
-# Clang toolchain
-
-ifeq ($(CONFIG_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
-
-  ARCHOPTIMIZATION += -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_ALL),y)
-  ARCHOPTIMIZATION += -fsanitize=kernel-address
-endif
-
-ARCHCFLAGS += -fno-common
-ARCHCXXFLAGS += -fno-common -nostdinc++
-
-ARCHCFLAGS += -Wall -Wstrict-prototypes -Wshadow -Wundef
-ARCHCXXFLAGS += -Wall -Wshadow -Wundef
-
-ifneq ($(CONFIG_CXX_EXCEPTION),y)
-  ARCHCXXFLAGS += -fno-exceptions -fcheck-new
-endif
-
-ifneq ($(CONFIG_CXX_RTTI),y)
-  ARCHCXXFLAGS += -fno-rtti
 endif
 
-LDFLAGS += -nostdlib
-
-# Optimization of unused sections
-
-ifeq ($(CONFIG_DEBUG_OPT_UNUSED_SECTIONS),y)
-  LDFLAGS          += --gc-sections
-  ARCHOPTIMIZATION += -ffunction-sections -fdata-sections
-endif
-
-# Debug link map
-
-ifeq ($(CONFIG_DEBUG_LINK_MAP),y)
-  LDFLAGS += --cref -Map=$(call CONVERT_PATH,$(TOPDIR)$(DELIM)nuttx.map)
-endif
-
-ifeq ($(CONFIG_DEBUG_SYMBOLS),y)
-  ARCHOPTIMIZATION += -g
-endif
-
-# Add the builtin library
-
-COMPILER_RT_LIB = $(shell $(CC) $(ARCHCPUFLAGS) --print-libgcc-file-name)
-ifeq ($(CONFIG_TOOLCHAIN),CLANG)
-  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
-endif
-
-EXTRA_LIBS += $(COMPILER_RT_LIB)
-
-ifneq ($(CONFIG_LIBM),y)
-  EXTRA_LIBS += $(wildcard $(shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libm.a))
-endif
-
-ifeq ($(CONFIG_LIBSUPCXX),y)
-  EXTRA_LIBS += $(wildcard $(shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libsupc++.a))
-endif
+include $(TOPDIR)/arch/arm/src/common/Toolchain.defs
diff --git a/boards/arm/eoss3/quickfeather/scripts/Make.defs b/boards/arm/eoss3/quickfeather/scripts/Make.defs
index 151f043d9f..a9a3a43921 100644
--- a/boards/arm/eoss3/quickfeather/scripts/Make.defs
+++ b/boards/arm/eoss3/quickfeather/scripts/Make.defs
@@ -27,7 +27,7 @@ ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)$(LDSCRIPT)
 
 ARCHPICFLAGS = -fpic -msingle-pic-base -mpic-register=r10
 
-ifneq ($(CONFIG_ARM_TOOLCHAIN_CLANG),y)
+ifneq ($(CONFIG_ARCH_TOOLCHAIN_CLANG),y)
   ARCHCFLAGS += -funwind-tables
   ARCHCXXFLAGS += -funwind-tables
 endif
diff --git a/boards/arm/stm32/stm32f4discovery/scripts/Make.defs b/boards/arm/stm32/stm32f4discovery/scripts/Make.defs
index de6e0fde6b..c309ae1a9f 100644
--- a/boards/arm/stm32/stm32f4discovery/scripts/Make.defs
+++ b/boards/arm/stm32/stm32f4discovery/scripts/Make.defs
@@ -27,7 +27,7 @@ ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)$(LDSCRIPT)
 
 ARCHPICFLAGS = -fpic -msingle-pic-base -mpic-register=r10
 
-ifneq ($(CONFIG_ARM_TOOLCHAIN_CLANG),y)
+ifneq ($(CONFIG_ARCH_TOOLCHAIN_CLANG),y)
   ARCHCFLAGS += -funwind-tables
   ARCHCXXFLAGS += -funwind-tables
 endif