diff --git a/BUILD.gn b/BUILD.gn index ea2e9ebe..110c1ac1 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -88,6 +88,10 @@ exec_script("//build/lite/run_shell_cmd.py", import("liteos.gni") +assert(ARCH != "", "ARCH not set!") +assert(ARCH == arch, "ARCH not match! details: $ARCH != $arch") +assert(tee_enable == defined(LOSCFG_TEE_ENABLE), "TEE switch not match!") + generate_notice_file("kernel_notice_file") { module_name = "kernel" module_source_dir_list = [ @@ -200,7 +204,13 @@ config("optimize_config") { } else { optimization_cflag = "-Os" } - cflags += [ "-flto" ] + } + if (defined(LOSCFG_COMPILE_LTO)) { + if (defined(LOSCFG_COMPILER_CLANG_LLVM)) { + cflags += [ "-flto=thin" ] + } else { + cflags += [ "-flto" ] + } } cflags += [ optimization_cflag ] asmflags = cflags @@ -223,11 +233,6 @@ config("warn_config") { "-Winvalid-pch", "-Wno-address-of-packed-member", ] - - if (defined(LOSCFG_QUICK_START)) { - cflags -= [ "-Werror" ] - } - asmflags = cflags } @@ -279,7 +284,7 @@ config("los_config") { executable("liteos") { configs = [] # clear default configs - configs += [ ":los_config" ] + configs += [ ":arch_config" ] configs += [ ":public" ] ldflags = [ @@ -304,18 +309,17 @@ executable("liteos") { inputs += [ "$root_out_dir/board.ld" ] output_dir = target_out_dir - output_name = liteos_name deps = [ - "platform:board.ld", + "platform:copy_board.ld", ":modules", ] } copy("copy_liteos") { deps = [ ":liteos" ] - sources = [ "$target_out_dir/unstripped/bin/$liteos_name" ] - outputs = [ "$root_out_dir/{{source_file_part}}" ] + sources = [ "$target_out_dir/unstripped/bin/liteos" ] + outputs = [ "$root_out_dir/$liteos_name" ] } build_ext_component("build_kernel_image") { diff --git a/Kconfig b/Kconfig index 75703e0b..2eb6b244 100644 --- a/Kconfig +++ b/Kconfig @@ -74,6 +74,14 @@ config COMPILE_OPTIMIZE_SIZE help Answer Y to add optimization options for small code size. The final binary size will be smaller. + But the compile time may be a bit longer. + +config COMPILE_LTO + bool "Enable link time optimization (LTO)" if COMPILE_OPTIMIZE_SIZE + default y + help + Answer Y to add lto options for more smaller code size. + The final binary size will be smaller. But the compile time may be much longer. endmenu diff --git a/Makefile b/Makefile index 9f6fda2b..258cd398 100644 --- a/Makefile +++ b/Makefile @@ -27,7 +27,7 @@ # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -LITEOSTOPDIR := $(realpath $(dir $(firstword $(MAKEFILE_LIST)))) +LITEOSTOPDIR := $(realpath $(dir $(lastword $(MAKEFILE_LIST)))) export LITEOSTOPDIR APPS = apps diff --git a/kernel/common/patchfs/BUILD.gn b/kernel/common/patchfs/BUILD.gn index 28d5e761..bf74298c 100644 --- a/kernel/common/patchfs/BUILD.gn +++ b/kernel/common/patchfs/BUILD.gn @@ -40,5 +40,4 @@ kernel_module(module_name) { } config("public") { - include_dirs = [ "." ] } diff --git a/kernel/common/patchfs/Makefile b/kernel/common/patchfs/Makefile index 64d68764..eab29ad3 100644 --- a/kernel/common/patchfs/Makefile +++ b/kernel/common/patchfs/Makefile @@ -4,10 +4,4 @@ MODULE_NAME := $(notdir $(shell pwd)) LOCAL_SRCS := $(wildcard *.c) -LOCAL_INCLUDE := \ - -I $(LITEOSTOPDIR)/kernel/common \ - -I $(LITEOSTOPDIR)/kernel/common/patchfs \ - -LOCAL_FLAGS := $(LOCAL_INCLUDE) $(LITEOS_GCOV_OPTS) - include $(MODULE) diff --git a/liteos.gni b/liteos.gni index dcbf1410..bfff15e5 100644 --- a/liteos.gni +++ b/liteos.gni @@ -40,9 +40,6 @@ if (defined(LOSCFG_ARCH_ARM_AARCH32)) { ARCH = "aarch64" } -assert(ARCH != "", "ARCH not set!") -assert(ARCH == arch, "ARCH not match! details: $ARCH != $arch") - template("kernel_module") { current_dir_name = get_path_info(rebase_path("."), "file") if (target_name != current_dir_name) { diff --git a/platform/BUILD.gn b/platform/BUILD.gn index 444695c5..d2d4a74f 100644 --- a/platform/BUILD.gn +++ b/platform/BUILD.gn @@ -66,23 +66,16 @@ config("public") { include_dirs = [ "." ] } -source_set("board") { +kernel_module("board.ld") { sources = [ "board.ld.S" ] - - configs = [] - configs += [ - "$LITEOSTOPDIR:los_config", - "$LITEOSTOPDIR:public", - ] - asmflags = [ "-P", "-E", ] } -copy("board.ld") { - deps = [ ":board" ] - sources = [ "$target_out_dir/board.board.ld.o" ] +copy("copy_board.ld") { + deps = [ ":board.ld" ] + sources = [ "$target_out_dir/board.ld.board.ld.o" ] outputs = [ "$root_out_dir/board.ld" ] } diff --git a/platform/Makefile b/platform/Makefile index 57951cb2..5cf034df 100644 --- a/platform/Makefile +++ b/platform/Makefile @@ -44,22 +44,6 @@ ifneq ($(LOSCFG_BASE_CORE_HILOG), y) LOCAL_SRCS := $(filter-out los_hilog.c, $(LOCAL_SRCS)) endif -ifeq ($(LOSCFG_KERNEL_TICKLESS), y) -LOCAL_INCLUDE += -I $(LITEOSTOPDIR)/kernel/extended/include -endif - -ifeq ($(LOSCFG_KERNEL_TRACE), y) -LOCAL_INCLUDE += -I $(LITEOSTOPDIR)/kernel/extended/include -endif - -ifeq ($(LOSCFG_KERNEL_CPUP), y) -LOCAL_INCLUDE += -I $(LITEOSTOPDIR)/kernel/extended/include -endif - -ifeq ($(LOSCFG_KERNEL_VDSO), y) -LOCAL_INCLUDE += -I $(LITEOSTOPDIR)/kernel/extended/vdso/include -endif - ALL_ASSRCS := $(wildcard *.S) ASSRCS := $(filter-out board.ld.S,$(ALL_ASSRCS)) @@ -68,9 +52,8 @@ LOCAL_SRCS += $(ASSRCS) LOCAL_FLAGS := $(LOCAL_INCLUDE) $(LITEOS_GCOV_OPTS) BOARD_LD = $(OUT)/lib/board.ld -$(BOARD_LD): board.ld.S $(LITEOS_MENUCONFIG_H) - $(HIDE)$(CC) -I$(LITEOSTOPDIR)/kernel/base/include -I$(LITEOSTOPDIR)/../../$(LOSCFG_BOARD_CONFIG_PATH) -I. \ - -imacros $(LITEOS_MENUCONFIG_H) -P -E $< -o $@ +$(BOARD_LD): board.ld.S + $(HIDE)$(CC) $(LITEOS_CFLAGS) -P -E $< -o $@ .PHONY: rm_board_ld rm_board_ld: diff --git a/platform/bsp.mk b/platform/bsp.mk index c4ac4120..5d065491 100644 --- a/platform/bsp.mk +++ b/platform/bsp.mk @@ -27,31 +27,13 @@ # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -############################# SRCs ################################# -HWI_SRC := -MMU_SRC := -NET_SRC := -TIMER_SRC := -HRTIMER_SRC := -USB_SRC := - -############################# HI3516DV300 Options################################# - -########################## HI3518EV300 Options############################## - -########################## Qemu ARM Virt Options############################## - LITEOS_BASELIB += -lbsp -lbsp_config PLATFORM_BSP_BASE := $(LITEOSTOPDIR)/platform PLATFORM_INCLUDE := -I $(LITEOSTOPDIR)/../../$(LOSCFG_BOARD_CONFIG_PATH) \ -I $(LITEOSTOPDIR)/../../$(LOSCFG_BOARD_CONFIG_PATH)/include \ - -I $(PLATFORM_BSP_BASE)/../kernel/common/rootfs \ - -I $(PLATFORM_BSP_BASE) \ - -I $(PLATFORM_BSP_BASE)/../../../drivers/liteos/platform/pm \ - -I $(PLATFORM_BSP_BASE)/hw/include \ - -I $(PLATFORM_BSP_BASE)/include + -I $(PLATFORM_BSP_BASE) LIB_SUBDIRS += $(PLATFORM_BSP_BASE) $(LITEOSTOPDIR)/../../$(LOSCFG_BOARD_CONFIG_PATH) LITEOS_PLATFORM_INCLUDE += $(PLATFORM_INCLUDE) diff --git a/tools/build/mk/los_config.mk b/tools/build/mk/los_config.mk index 02245388..dbb529cf 100644 --- a/tools/build/mk/los_config.mk +++ b/tools/build/mk/los_config.mk @@ -30,16 +30,6 @@ -include $(LITEOS_CONFIG_FILE) HIDE := @ -CC := -AS := -AR := -LD := -GPP := -OBJCOPY := -OBJDUMP := -SIZE := -NM := -MKDIR = mkdir OBJ_MKDIR = if [ ! -d $(dir $@) ]; then mkdir -p $(dir $@); fi RM = -rm -rf ifeq ($(OS),) @@ -121,12 +111,6 @@ MODULE = $(LITEOSTOPDIR)/tools/build/mk/module.mk LITEOS_CMACRO += -D__LITEOS__ -DSECUREC_IN_KERNEL=0 AS_OBJS_LIBC_FLAGS = -D__ASSEMBLY__ -ifeq ($(LOSCFG_QUICK_START), y) -WARNING_AS_ERROR := -Wall -else -WARNING_AS_ERROR := -Wall -Werror -endif - ####################################### CPU Option Begin ######################################### include $(LITEOSTOPDIR)/arch/cpu.mk ####################################### CPU Option End ######################################### @@ -137,6 +121,7 @@ include $(LITEOSTOPDIR)/platform/bsp.mk ifeq ($(LOSCFG_PLATFORM_ROOTFS), y) LITEOS_BASELIB += -lrootfs LIB_SUBDIRS += $(LITEOSTOPDIR)/kernel/common/rootfs + LITEOS_PLATFORM_INCLUDE += -I $(LITEOSTOPDIR)/kernel/common/rootfs endif ifeq ($(LOSCFG_PLATFORM_PATCHFS), y) @@ -440,9 +425,16 @@ ifeq ($(LOSCFG_COMPILE_OPTIMIZE), y) endif ifeq ($(LOSCFG_COMPILE_OPTIMIZE_SIZE), y) ifeq ($(LOSCFG_COMPILER_CLANG_LLVM), y) - LITEOS_COPTS_OPTIMIZE = -Oz -flto + LITEOS_COPTS_OPTIMIZE = -Oz else - LITEOS_COPTS_OPTIMIZE = -Os -flto + LITEOS_COPTS_OPTIMIZE = -Os + endif +endif +ifeq ($(LOSCFG_COMPILE_LTO), y) + ifeq ($(LOSCFG_COMPILER_CLANG_LLVM), y) + LITEOS_COPTS_OPTIMIZE += -flto=thin + else + LITEOS_COPTS_OPTIMIZE += -flto endif endif LITEOS_COPTS_DEBUG += $(LITEOS_COPTS_OPTION) $(LITEOS_COPTS_OPTIMIZE) @@ -556,7 +548,7 @@ LITEOS_SECURITY_INCLUDE := $(LITEOS_SECURITY_CAP_INC) $(LITEOS_SECURITY_VID_I LOSCFG_TOOLS_DEBUG_INCLUDE := $(LITEOS_SHELL_INCLUDE) $(LITEOS_UART_INCLUDE) \ $(LITEOS_TELNET_INCLUDE) -LITEOS_COMMON_OPTS := -fno-pic -fno-builtin -nostdinc -nostdlib $(WARNING_AS_ERROR) -fms-extensions -fno-omit-frame-pointer -Wno-address-of-packed-member -Winvalid-pch +LITEOS_COMMON_OPTS := -fno-pic -fno-builtin -nostdinc -nostdlib -Wall -Werror -fms-extensions -fno-omit-frame-pointer -Wno-address-of-packed-member -Winvalid-pch LITEOS_CXXOPTS_BASE += $(LITEOS_COMMON_OPTS) -std=c++11 -nostdinc++ -fexceptions -fpermissive -fno-use-cxa-atexit -frtti