From 62729b425f3b3a9ccb53b7a57f3dcc0db76d039e Mon Sep 17 00:00:00 2001
From: zhuhengbo <zhuhengbo1@huawei.com>
Date: Thu, 19 Mar 2020 17:10:51 +0800
Subject: [PATCH] dpdk:
 add-secure-compile-option-and-compile-with-fPIC-for-static-lib

Signed-off-by: zhuhengbo <zhuhengbo1@huawei.com>
---
 lib/librte_eal/common/include/rte_log.h | 1 +
 mk/rte.lib.mk                           | 1 +
 mk/target/generic/rte.vars.mk           | 2 ++
 3 files changed, 4 insertions(+)

diff --git a/lib/librte_eal/common/include/rte_log.h b/lib/librte_eal/common/include/rte_log.h
index 1bb0e66..6426ea2 100644
--- a/lib/librte_eal/common/include/rte_log.h
+++ b/lib/librte_eal/common/include/rte_log.h
@@ -311,6 +311,7 @@ int rte_log(uint32_t level, uint32_t logtype, const char *format, ...)
  *   - Negative on error.
  */
 int rte_vlog(uint32_t level, uint32_t logtype, const char *format, va_list ap)
+	__attribute__((weak))
 	__attribute__((format(printf,3,0)));
 
 /**
diff --git a/mk/rte.lib.mk b/mk/rte.lib.mk
index 655a1b1..4516d1c 100644
--- a/mk/rte.lib.mk
+++ b/mk/rte.lib.mk
@@ -6,6 +6,7 @@ include $(RTE_SDK)/mk/internal/rte.install-pre.mk
 include $(RTE_SDK)/mk/internal/rte.clean-pre.mk
 include $(RTE_SDK)/mk/internal/rte.build-pre.mk
 
+CFLAGS += -fPIC
 EXTLIB_BUILD ?= n
 
 # VPATH contains at least SRCDIR
diff --git a/mk/target/generic/rte.vars.mk b/mk/target/generic/rte.vars.mk
index 3747221..bf3f4ff 100644
--- a/mk/target/generic/rte.vars.mk
+++ b/mk/target/generic/rte.vars.mk
@@ -75,6 +75,8 @@ ifeq ($(KERNELRELEASE),)
 include $(RTE_SDK)/mk/rte.cpuflags.mk
 
 # merge all CFLAGS
+CPU_CFLAGS += -fPIE -pie -fPIC -fstack-protector-strong -D_FORTIFY_SOURCE=2 -O2 -Wall
+CPU_CFLAGS += -Wl,-z,relro,-z,now,-z,noexecstack -Wtrampolines
 CFLAGS := $(CPU_CFLAGS) $(EXECENV_CFLAGS) $(TOOLCHAIN_CFLAGS) $(MACHINE_CFLAGS)
 CFLAGS += $(TARGET_CFLAGS)
 
-- 
2.19.1

