From 77dcef4bc0c92d0141f7a3be0addd4d5cb533b0b Mon Sep 17 00:00:00 2001 From: Guangyao Ma Date: Thu, 5 Aug 2021 22:19:03 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20clang=E7=9B=B8=E5=85=B3=E7=BC=96?= =?UTF-8?q?=E8=AF=91=E9=80=89=E9=A1=B9=E9=9A=94=E7=A6=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit liteos_a在apps/mksh和apps/toybox编译中,clang相关编译选项未进行隔离。之后支持 其他类似gcc编译时,可能存在编译问题。 其中 --target=$(LLVM_TARGET) $(LLVM_SYSROOT) 是clang编译特有的编译选项,需要被 隔离。 close #I444AV Signed-off-by: Guangyao Ma Change-Id: Ib11453aa0b3ee6bcdf3104d13d166c65f2202527 --- apps/mksh/Makefile | 13 ++++++++++--- apps/toybox/Makefile | 13 +++++++++++-- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/apps/mksh/Makefile b/apps/mksh/Makefile index 43f215f1..3431dd5c 100755 --- a/apps/mksh/Makefile +++ b/apps/mksh/Makefile @@ -39,11 +39,16 @@ BUILD_DIR := $(MKSH_DIR)/build BUILD_LOG := $(MKSH_DIR)/build.log TARGET_OS := OpenHarmony -LOCAL_CFLAGS := -flto -fdata-sections -ffunction-sections -Oz -fstack-protector-strong -D_FORTIFY_SOURCE=2 -LOCAL_CFLAGS += --target=$(LLVM_TARGET) $(LLVM_SYSROOT) +LOCAL_CFLAGS := -flto -fdata-sections -ffunction-sections -fstack-protector-strong -D_FORTIFY_SOURCE=2 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 --target=$(LLVM_TARGET) $(LLVM_SYSROOT) +LOCAL_LDFLAGS := -Wl,--gc-sections -flto -O2 + +ifeq ($(LOSCFG_COMPILER_CLANG_LLVM), y) +LOCAL_CFLAGS += -Oz --target=$(LLVM_TARGET) $(LLVM_SYSROOT) +else +LOCAL_CFLAGS += -O2 +endif all:$(MKSH) @@ -64,8 +69,10 @@ endif $(HIDE)$(CP) $(MKSH) $(APPS_OUT) $(HIDE)mkdir -p $(ETC_OUT) $(HIDE)$(CP) -rf $(BUILD_DIR)/.mkshrc $(ETC_OUT)/ + $(HIDE)$(RM) $(BUILD_DIR) $(BUILD_LOG) clean: $(HIDE)$(RM) $(MKSH) $(BUILD_DIR) $(BUILD_LOG) + .PHONY: all $(MKSH) clean diff --git a/apps/toybox/Makefile b/apps/toybox/Makefile index c4838eb7..2ca70f2f 100644 --- a/apps/toybox/Makefile +++ b/apps/toybox/Makefile @@ -38,6 +38,13 @@ BUILD_DIR := $(TOYBOX_DIR)/build BUILD_LOG := $(TOYBOX_DIR)/build.log OUTNAME := $(TOYBOX) +CFLAGS := -D_FORTIFY_SOURCE=2 -fstack-protector-strong +LDFLAGS := +ifeq ($(LOSCFG_COMPILER_CLANG_LLVM), y) +CFLAGS += --target=$(LLVM_TARGET) $(LLVM_SYSROOT) +LDFLAGS += --target=$(LLVM_TARGET) $(LLVM_SYSROOT) +endif + $(TOYBOX): ifneq ($(wildcard $(BUILD_DIR)),) $(HIDE)echo "not clean, rebuilding now"; @@ -46,12 +53,14 @@ else $(HIDE)$(CP) $(LITEOSTHIRDPARTY)/$(TOYBOX)/. $(BUILD_DIR) $(HIDE)$(CP) -p $(LITEOSTHIRDPARTY)/$(TOYBOX)/porting/liteos_a/. $(BUILD_DIR) endif - $(HIDE)CFLAGS="-D_FORTIFY_SOURCE=2 -fstack-protector-strong --target=$(LLVM_TARGET) $(LLVM_SYSROOT)" CC="$(CC)" OUTNAME=$(OUTNAME) \ - LDFLAGS="--target=$(LLVM_TARGET) $(LLVM_SYSROOT)" \ + + $(HIDE)CFLAGS="$(CFLAGS)" CC="$(CC)" OUTNAME="$(OUTNAME)" \ + LDFLAGS="$(LDFLAGS)" STRIP="$(STRIP)" \ make -C $(BUILD_DIR) toybox -j> $(BUILD_LOG) 2>&1 $(HIDE)$(CP) $(BUILD_DIR)/$(TOYBOX) . $(HIDE)mkdir -p $(APPS_OUT) $(HIDE)$(CP) $(TOYBOX) $(APPS_OUT) + $(HIDE)$(RM) $(BUILD_DIR) $(BUILD_LOG) clean: $(HIDE)$(RM) $(TOYBOX) $(BUILD_DIR) $(BUILD_LOG)