mirror of
https://github.com/apache/nuttx.git
synced 2026-05-27 11:26:12 +08:00
arch/clang: add support for Clang LTO
add support of Clang's Link Time Optimization (LTO) on NuttX build system Reference: https://gcc.gnu.org/onlinedocs/gccint/LTO-Overview.html https://llvm.org/docs/LinkTimeOptimization.html Signed-off-by: chao.an <anchao@xiaomi.com>
This commit is contained in:
@@ -222,6 +222,49 @@ config ARCH_TOOLCHAIN_GNU
|
|||||||
bool
|
bool
|
||||||
default n
|
default n
|
||||||
|
|
||||||
|
config ARCH_TOOLCHAIN_CLANG
|
||||||
|
bool
|
||||||
|
select ARCH_TOOLCHAIN_GNU
|
||||||
|
default n
|
||||||
|
|
||||||
|
choice
|
||||||
|
prompt "Link Time Optimization (LTO)"
|
||||||
|
default LTO_NONE
|
||||||
|
---help---
|
||||||
|
This option enables Link Time Optimization (LTO), which allows the
|
||||||
|
compiler to optimize binaries globally.
|
||||||
|
|
||||||
|
If unsure, select LTO_NONE. Note that LTO is very resource-intensive
|
||||||
|
so it's disabled by default.
|
||||||
|
|
||||||
|
config LTO_NONE
|
||||||
|
bool "None"
|
||||||
|
---help---
|
||||||
|
Build the kernel normally, without Link Time Optimization (LTO).
|
||||||
|
|
||||||
|
config LTO_FULL
|
||||||
|
bool "GNU Full LTO (EXPERIMENTAL)"
|
||||||
|
depends on ARCH_TOOLCHAIN_GNU || ARCH_TOOLCHAIN_CLANG
|
||||||
|
---help---
|
||||||
|
Link time optimization is implemented as a GCC front end for a bytecode
|
||||||
|
bytecode representation of GIMPLE that is emitted in special sections
|
||||||
|
of .o files. Currently, LTO support is enabled in most ELF-based systems,
|
||||||
|
as well as darwin, cygwin and mingw systems.
|
||||||
|
|
||||||
|
config LTO_THIN
|
||||||
|
bool "Clang ThinLTO (EXPERIMENTAL)"
|
||||||
|
depends on ARCH_TOOLCHAIN_CLANG
|
||||||
|
---help---
|
||||||
|
This option enables Clang's ThinLTO, which allows for parallel
|
||||||
|
optimization and faster incremental compiles compared to the
|
||||||
|
CONFIG_LTO_FULL option. More information can be found
|
||||||
|
from Clang's documentation:
|
||||||
|
|
||||||
|
https://clang.llvm.org/docs/ThinLTO.html
|
||||||
|
|
||||||
|
If unsure, say Y.
|
||||||
|
endchoice
|
||||||
|
|
||||||
config ARCH_GNU_NO_WEAKFUNCTIONS
|
config ARCH_GNU_NO_WEAKFUNCTIONS
|
||||||
bool
|
bool
|
||||||
depends on ARCH_TOOLCHAIN_GNU
|
depends on ARCH_TOOLCHAIN_GNU
|
||||||
|
|||||||
@@ -22,6 +22,6 @@ config ARMV6M_TOOLCHAIN_GNU_EABI
|
|||||||
|
|
||||||
config ARMV6M_TOOLCHAIN_CLANG
|
config ARMV6M_TOOLCHAIN_CLANG
|
||||||
bool "Generic Clang toolchain"
|
bool "Generic Clang toolchain"
|
||||||
select ARCH_TOOLCHAIN_GNU
|
select ARCH_TOOLCHAIN_CLANG
|
||||||
|
|
||||||
endchoice
|
endchoice
|
||||||
|
|||||||
@@ -80,6 +80,14 @@ ifeq ($(CONFIG_ARMV6M_TOOLCHAIN),CLANG)
|
|||||||
TOOLCHAIN_MARCH := --config armv6m_soft_nofp_nosys
|
TOOLCHAIN_MARCH := --config armv6m_soft_nofp_nosys
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
# Link Time Optimization
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_LTO_THIN),y)
|
||||||
|
MAXOPTIMIZATION += -flto=thin
|
||||||
|
else ifeq ($(CONFIG_LTO_FULL),y)
|
||||||
|
MAXOPTIMIZATION += -flto
|
||||||
|
endif
|
||||||
|
|
||||||
# NuttX buildroot under Linux or Cygwin
|
# NuttX buildroot under Linux or Cygwin
|
||||||
|
|
||||||
ifeq ($(CONFIG_ARMV6M_TOOLCHAIN),BUILDROOT)
|
ifeq ($(CONFIG_ARMV6M_TOOLCHAIN),BUILDROOT)
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ config ARMV7M_TOOLCHAIN_GNU_EABI
|
|||||||
|
|
||||||
config ARMV7M_TOOLCHAIN_CLANG
|
config ARMV7M_TOOLCHAIN_CLANG
|
||||||
bool "Generic Clang toolchain"
|
bool "Generic Clang toolchain"
|
||||||
select ARCH_TOOLCHAIN_GNU
|
select ARCH_TOOLCHAIN_CLANG
|
||||||
|
|
||||||
endchoice
|
endchoice
|
||||||
|
|
||||||
|
|||||||
@@ -130,6 +130,14 @@ ifeq ($(CONFIG_ARMV7M_TOOLCHAIN),CLANG)
|
|||||||
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
# Link Time Optimization
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_LTO_THIN),y)
|
||||||
|
MAXOPTIMIZATION += -flto=thin
|
||||||
|
else ifeq ($(CONFIG_LTO_FULL),y)
|
||||||
|
MAXOPTIMIZATION += -flto
|
||||||
|
endif
|
||||||
|
|
||||||
# NuttX buildroot under Linux or Cygwin
|
# NuttX buildroot under Linux or Cygwin
|
||||||
|
|
||||||
ifeq ($(CONFIG_ARMV7M_TOOLCHAIN),BUILDROOT)
|
ifeq ($(CONFIG_ARMV7M_TOOLCHAIN),BUILDROOT)
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ config ARMV8M_TOOLCHAIN_GNU_EABI
|
|||||||
|
|
||||||
config ARMV8M_TOOLCHAIN_CLANG
|
config ARMV8M_TOOLCHAIN_CLANG
|
||||||
bool "Generic Clang toolchain"
|
bool "Generic Clang toolchain"
|
||||||
select ARCH_TOOLCHAIN_GNU
|
select ARCH_TOOLCHAIN_CLANG
|
||||||
|
|
||||||
endchoice
|
endchoice
|
||||||
|
|
||||||
|
|||||||
@@ -139,6 +139,14 @@ ifeq ($(CONFIG_ARMV8M_TOOLCHAIN),CLANG)
|
|||||||
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
# Link Time Optimization
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_LTO_THIN),y)
|
||||||
|
MAXOPTIMIZATION += -flto=thin
|
||||||
|
else ifeq ($(CONFIG_LTO_FULL),y)
|
||||||
|
MAXOPTIMIZATION += -flto
|
||||||
|
endif
|
||||||
|
|
||||||
# NuttX buildroot under Linux or Cygwin
|
# NuttX buildroot under Linux or Cygwin
|
||||||
|
|
||||||
ifeq ($(CONFIG_ARMV8M_TOOLCHAIN),BUILDROOT)
|
ifeq ($(CONFIG_ARMV8M_TOOLCHAIN),BUILDROOT)
|
||||||
|
|||||||
Reference in New Issue
Block a user