Skip to content

Commit c51e213

Browse files
lyan3lijinxia
authored andcommitted
tools: acrntrace: update Makefile
Update the Makefiel 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 5e0acac commit c51e213

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

tools/acrntrace/Makefile

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,47 @@
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:
738
$(CC) -o $(OUT_DIR)/acrntrace acrntrace.c sbuf.c -I. -lpthread -lrt $(CFLAGS) $(LDFLAGS)
839

940
clean:
1041
rm -f $(OUT_DIR)/acrntrace
42+
ifneq ($(OUT_DIR),.)
43+
rm -rf $(OUT_DIR)
44+
endif
1145

1246
install: $(OUT_DIR)/acrntrace
1347
install -d $(DESTDIR)/usr/bin

0 commit comments

Comments
 (0)