arch/arm: add support for GCC LTO

1. Enable GCC link-time optimizer
2. Enable use of a linker plugin during link-time optimization

Signed-off-by: chao.an <anchao@xiaomi.com>
This commit is contained in:
chao.an 2022-04-21 22:48:02 +08:00 committed by Xiang Xiao
parent cbef8681fe
commit 042640abbf
7 changed files with 117 additions and 29 deletions

View File

@ -89,8 +89,15 @@ LDFLAGS += $(addprefix -T,$(call CONVERT_PATH,$(ARCHSCRIPT))) $(EXTRALINKCMDS)
# Override in Make.defs if linker is not 'ld'
LDSTARTGROUP ?= --start-group
LDENDGROUP ?= --end-group
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
BOARDMAKE = $(if $(wildcard board$(DELIM)Makefile),y,)

View File

@ -118,15 +118,29 @@ 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
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)
MAXOPTIMIZATION += -flto
ifeq ($(CONFIG_ARM_TOOLCHAIN),GNU_EABI)
LD := $(CROSSDEV)gcc
AR := $(CROSSDEV)gcc-ar rcs
NM := $(CROSSDEV)gcc-nm
MAXOPTIMIZATION += -fuse-linker-plugin
MAXOPTIMIZATION += -fno-builtin
MAXOPTIMIZATION += -nodefaultlibs
endif
endif
# Add the builtin library

View File

@ -86,6 +86,9 @@ ifeq ($(CONFIG_LTO_THIN),y)
MAXOPTIMIZATION += -flto=thin
else ifeq ($(CONFIG_LTO_FULL),y)
MAXOPTIMIZATION += -flto
ifeq ($(CONFIG_ARMV6M_TOOLCHAIN),GNU_EABI)
MAXOPTIMIZATION += -fuse-linker-plugin
endif
endif
# NuttX buildroot under Linux or Cygwin
@ -129,12 +132,22 @@ 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
LD = $(CROSSDEV)ld
AR = $(CROSSDEV)ar rcs
NM = $(CROSSDEV)nm
ifeq ($(CONFIG_LTO_FULL),y)
ifeq ($(CONFIG_ARMV6M_TOOLCHAIN),GNU_EABI)
LD := $(CROSSDEV)gcc
AR := $(CROSSDEV)gcc-ar rcs
NM := $(CROSSDEV)gcc-nm
MAXOPTIMIZATION += -fno-builtin
MAXOPTIMIZATION += -nodefaultlibs
endif
endif
endif
# Architecture flags

View File

@ -165,15 +165,29 @@ 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
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)
MAXOPTIMIZATION += -flto
ifeq ($(CONFIG_ARMV7A_TOOLCHAIN),GNU_EABI)
LD := $(CROSSDEV)gcc
AR := $(CROSSDEV)gcc-ar rcs
NM := $(CROSSDEV)gcc-nm
MAXOPTIMIZATION += -fuse-linker-plugin
MAXOPTIMIZATION += -fno-builtin
MAXOPTIMIZATION += -nodefaultlibs
endif
endif
# Add the builtin library

View File

@ -136,6 +136,9 @@ ifeq ($(CONFIG_LTO_THIN),y)
MAXOPTIMIZATION += -flto=thin
else ifeq ($(CONFIG_LTO_FULL),y)
MAXOPTIMIZATION += -flto
ifeq ($(CONFIG_ARMV7M_TOOLCHAIN),GNU_EABI)
MAXOPTIMIZATION += -fuse-linker-plugin
endif
endif
# NuttX buildroot under Linux or Cygwin
@ -188,12 +191,22 @@ 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
LD = $(CROSSDEV)ld
AR = $(CROSSDEV)ar rcs
NM = $(CROSSDEV)nm
ifeq ($(CONFIG_LTO_FULL),y)
ifeq ($(CONFIG_ARMV7M_TOOLCHAIN),GNU_EABI)
LD := $(CROSSDEV)gcc
AR := $(CROSSDEV)gcc-ar rcs
NM := $(CROSSDEV)gcc-nm
MAXOPTIMIZATION += -fno-builtin
MAXOPTIMIZATION += -nodefaultlibs
endif
endif
endif
# Architecture flags

View File

@ -141,15 +141,29 @@ 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
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)
MAXOPTIMIZATION += -flto
ifeq ($(CONFIG_ARMV7R_TOOLCHAIN),GNU_EABI)
LD := $(CROSSDEV)gcc
AR := $(CROSSDEV)gcc-ar rcs
NM := $(CROSSDEV)gcc-nm
MAXOPTIMIZATION += -fuse-linker-plugin
MAXOPTIMIZATION += -fno-builtin
MAXOPTIMIZATION += -nodefaultlibs
endif
endif
# Add the builtin library

View File

@ -145,6 +145,9 @@ ifeq ($(CONFIG_LTO_THIN),y)
MAXOPTIMIZATION += -flto=thin
else ifeq ($(CONFIG_LTO_FULL),y)
MAXOPTIMIZATION += -flto
ifeq ($(CONFIG_ARMV8M_TOOLCHAIN),GNU_EABI)
MAXOPTIMIZATION += -fuse-linker-plugin
endif
endif
# NuttX buildroot under Linux or Cygwin
@ -203,6 +206,16 @@ else
NM = $(CROSSDEV)nm
OBJCOPY = $(CROSSDEV)objcopy
OBJDUMP = $(CROSSDEV)objdump
ifeq ($(CONFIG_LTO_FULL),y)
ifeq ($(CONFIG_ARMV8M_TOOLCHAIN),GNU_EABI)
LD := $(CROSSDEV)gcc
AR := $(CROSSDEV)gcc-ar rcs
NM := $(CROSSDEV)gcc-nm
MAXOPTIMIZATION += -fno-builtin
MAXOPTIMIZATION += -nodefaultlibs
endif
endif
endif
# Architecture flags