From 565b2e85cd1c0ce861ae846f56a0c015f282d6b5 Mon Sep 17 00:00:00 2001 From: Guangyao Ma Date: Tue, 8 Jun 2021 16:46:56 +0800 Subject: [PATCH] refactor(mksh): reduce the mksh size by Oz MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit clang不支持“-flto,-Oz”作为链接选项,但是可以作为编译选项,且作为编译选项时,有更好的size减少效果。这里为了使用这种 编译选项组合,且为了不影响链接过程(Build.sh链接时也会使用CFLAGS),在链接选项生效的-O选项中,重置其为O2。 最终size可以从300+k,缩减为不到180k。 Close #I3UVEV Change-Id: If29ac4a058bcd40c4c36deb484c9468c93bcd1ec Signed-off-by: Guangyao Ma --- apps/mksh/Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/mksh/Makefile b/apps/mksh/Makefile index 5773965e..d6fd31a9 100755 --- a/apps/mksh/Makefile +++ b/apps/mksh/Makefile @@ -38,10 +38,11 @@ BUILD_DIR := $(MKSH_DIR)/build BUILD_LOG := $(MKSH_DIR)/build.log TARGET_OS := OpenHarmony -LOCAL_CFLAGS := -flto -fdata-sections -ffunction-sections -O2 -fstack-protector-strong -D_FORTIFY_SOURCE=2 -mcpu=cortex-a7 -mfloat-abi=softfp -mfpu=neon-vfpv4 +LOCAL_CFLAGS := -flto -fdata-sections -ffunction-sections -Oz -fstack-protector-strong -D_FORTIFY_SOURCE=2 -mcpu=cortex-a7 -mfloat-abi=softfp -mfpu=neon-vfpv4 LOCAL_CFLAGS += --target=arm-liteos --sysroot=$(LITEOSTOPDIR)/../../prebuilts/lite/sysroot/ LOCAL_CFLAGS += -DMKSH_DISABLE_TTY_WARNING -DMKSH_SMALL=1 -DMKSH_ASSUME_UTF8=1 -DMKSH_SMALL_BUT_FAST=0 -DMKSH_S_NOVI=1 -DHAVE_CAN_FSTACKPROTECTORSTRONG=1 LOCAL_CFLAGS += -DMKSH_LESS_CMDLINE_EDITING -DMKSH_LESS_BUILDINS -DMKSH_NO_INITCOMS -DADAPT_FOR_LITEOS_A +LOCAL_LDFLAGS := -Wl,--gc-sections -flto -O2 all:$(MKSH) @@ -54,7 +55,7 @@ else $(HIDE)mkdir -p $(BUILD_DIR) $(HIDE)$(CP) $(LITEOSTHIRDPARTY)/$(MKSH)/. $(BUILD_DIR) $(HIDE)chmod +x $(BUILD_DIR)/Build.sh - $(HIDE)cd $(BUILD_DIR) && CC=$(CC) TARGET_OS=$(TARGET_OS) CFLAGS="$(LOCAL_CFLAGS)" LDFLAGS="$(LDFLAGS)" ./Build.sh -r > $(BUILD_LOG) 2>&1 + $(HIDE)cd $(BUILD_DIR) && CC=$(CC) TARGET_OS=$(TARGET_OS) CFLAGS="$(LOCAL_CFLAGS)" LDFLAGS="$(LOCAL_LDFLAGS)" ./Build.sh -r > $(BUILD_LOG) 2>&1 endif $(HIDE)$(CP) -rf $(BUILD_DIR)/$(MKSH) . $(HIDE)$(STRIP) $(MKSH)