refactor(mksh): reduce the mksh size by Oz

clang不支持“-flto,-Oz”作为链接选项,但是可以作为编译选项,且作为编译选项时,有更好的size减少效果。这里为了使用这种
编译选项组合,且为了不影响链接过程(Build.sh链接时也会使用CFLAGS),在链接选项生效的-O选项中,重置其为O2。
最终size可以从300+k,缩减为不到180k。

Close #I3UVEV

Change-Id: If29ac4a058bcd40c4c36deb484c9468c93bcd1ec
Signed-off-by: Guangyao Ma <guangyao.ma@outlook.com>
This commit is contained in:
Guangyao Ma 2021-06-08 16:46:56 +08:00
parent 9b364500ad
commit 565b2e85cd
1 changed files with 3 additions and 2 deletions

View File

@ -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)