Skip to content

Commit 52ee615

Browse files
lyan3lijinxia
authored andcommitted
tools: acrnlog: update Makefile
In order to sync the compiler options with devicemode and enable options to harden software. Tracked-On: #1122 Signed-off-by: Yan, Like <like.yan@intel.com> Acked-by: Yin Fengwei <fengwei.yin@intel.com>
1 parent 74c4d71 commit 52ee615

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

tools/acrnlog/Makefile

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,37 @@
1+
T := $(CURDIR)
2+
OUT_DIR ?= $(shell mkdir -p $(T)/build;cd $(T)/build;pwd)
3+
CC ?= gcc
14

2-
OUT_DIR ?= .
3-
CFLAGS += -fpie
5+
CFLAGS := -g -O0 -std=gnu11
6+
CFLAGS += -D_GNU_SOURCE
7+
CFLAGS += -DNO_OPENSSL
8+
CFLAGS += -m64
9+
CFLAGS += -Wall -ffunction-sections
10+
CFLAGS += -Werror
11+
CFLAGS += -O2 -D_FORTIFY_SOURCE=2
12+
CFLAGS += -Wformat -Wformat-security -fno-strict-aliasing
13+
CFLAGS += -fpie -fpic
14+
15+
GCC_MAJOR=$(shell echo __GNUC__ | $(CC) -E -x c - | tail -n 1)
16+
GCC_MINOR=$(shell echo __GNUC_MINOR__ | $(CC) -E -x c - | tail -n 1)
17+
18+
#enable stack overflow check
19+
STACK_PROTECTOR := 1
20+
21+
ifdef STACK_PROTECTOR
22+
ifeq (true, $(shell [ $(GCC_MAJOR) -gt 4 ] && echo true))
23+
CFLAGS += -fstack-protector-strong
24+
else
25+
ifeq (true, $(shell [ $(GCC_MAJOR) -eq 4 ] && [ $(GCC_MINOR) -ge 9 ] && echo true))
26+
CFLAGS += -fstack-protector-strong
27+
else
28+
CFLAGS += -fstack-protector
29+
endif
30+
endif
31+
endif
32+
33+
LDFLAGS := -Wl,-z,noexecstack
34+
LDFLAGS += -Wl,-z,relro,-z,now
435
LDFLAGS += -pie
536

637
all:
@@ -11,6 +42,7 @@ clean:
1142
rm -f $(OUT_DIR)/acrnlog
1243
ifneq ($(OUT_DIR),.)
1344
rm -f $(OUT_DIR)/acrnlog.service
45+
rm -rf $(OUT_DIR)
1446
endif
1547

1648
install: $(OUT_DIR)/acrnlog

0 commit comments

Comments
 (0)