From a655c865fce412d7e661d866bde0df30607fb6a4 Mon Sep 17 00:00:00 2001
From: Changsheng Wu <wuchangsheng2@huawei.com>
Date: Thu, 16 Dec 2021 20:35:09 +0800
Subject: [PATCH] huawei-0001-dpdk-add-secure-compile-option-and-fPIC

---
 app/meson.build                | 2 ++
 buildtools/chkincs/meson.build | 2 ++
 drivers/meson.build            | 2 ++
 examples/meson.build           | 2 ++
 lib/meson.build                | 2 ++
 5 files changed, 10 insertions(+)

diff --git a/app/meson.build b/app/meson.build
index 93d8c15032..68be53c92d 100644
--- a/app/meson.build
+++ b/app/meson.build
@@ -21,6 +21,8 @@ apps = [
 ]
 
 default_cflags = machine_args + ['-DALLOW_EXPERIMENTAL_API']
+default_cflags += ['-fPIE', '-pie', '-fPIC', '-fstack-protector-strong', '-D_FORTIFY_SOURCE=2', '-O2', '-Wall', '-Werror']
+default_cflags += ['-Wl,-z,relro,-z,now,-z,noexecstack', '-Wtrampolines']
 default_ldflags = []
 if get_option('default_library') == 'static' and not is_windows
     default_ldflags += ['-Wl,--export-dynamic']
diff --git a/buildtools/chkincs/meson.build b/buildtools/chkincs/meson.build
index 5ffca89761..e3d13a691c 100644
--- a/buildtools/chkincs/meson.build
+++ b/buildtools/chkincs/meson.build
@@ -13,6 +13,8 @@ gen_c_files = generator(gen_c_file_for_header,
 
 cflags = machine_args
 cflags += '-DALLOW_EXPERIMENTAL_API'
+cflags += ['-fPIE', '-pie', '-fPIC', '-fstack-protector-strong', '-D_FORTIFY_SOURCE=2', '-O2', '-Wall', '-Werror']
+cflags += ['-Wl,-z,relro,-z,now,-z,noexecstack', '-Wtrampolines']
 
 sources = files('main.c')
 sources += gen_c_files.process(dpdk_chkinc_headers)
diff --git a/drivers/meson.build b/drivers/meson.build
index d5f4e1c1f2..9e71057afb 100644
--- a/drivers/meson.build
+++ b/drivers/meson.build
@@ -45,6 +45,8 @@ enable_drivers += always_enable
 default_cflags = machine_args
 default_cflags += ['-DALLOW_EXPERIMENTAL_API']
 default_cflags += ['-DALLOW_INTERNAL_API']
+default_cflags += ['-fPIE', '-pie', '-fPIC', '-fstack-protector-strong', '-D_FORTIFY_SOURCE=2', '-O2', '-Wall', '-Werror']
+default_cflags += ['-Wl,-z,relro,-z,now,-z,noexecstack', '-Wtrampolines']
 
 if cc.has_argument('-Wno-format-truncation')
     default_cflags += '-Wno-format-truncation'
diff --git a/examples/meson.build b/examples/meson.build
index bac9b76007..db8603542f 100644
--- a/examples/meson.build
+++ b/examples/meson.build
@@ -90,6 +90,8 @@ default_ldflags = dpdk_extra_ldflags
 if get_option('default_library') == 'static' and not is_windows
     default_ldflags += ['-Wl,--export-dynamic']
 endif
+default_cflags += ['-fPIE', '-pie', '-fPIC', '-fstack-protector-strong', '-D_FORTIFY_SOURCE=2', '-O2', '-Wall', '-Werror']
+default_cflags += ['-Wl,-z,relro,-z,now,-z,noexecstack', '-Wtrampolines']
 
 foreach example: examples
     name = example.split('/')[-1]
diff --git a/lib/meson.build b/lib/meson.build
index 018976df17..668050dcc7 100644
--- a/lib/meson.build
+++ b/lib/meson.build
@@ -94,6 +94,8 @@ endforeach
 default_cflags = machine_args
 default_cflags += ['-DALLOW_EXPERIMENTAL_API']
 default_cflags += ['-DALLOW_INTERNAL_API']
+default_cflags += ['-fPIE', '-pie', '-fPIC', '-fstack-protector-strong', '-D_FORTIFY_SOURCE=2', '-O2', '-Wall', '-Werror']
+default_cflags += ['-Wl,-z,relro,-z,now,-z,noexecstack', '-Wtrampolines']
 
 if cc.has_argument('-Wno-format-truncation')
     default_cflags += '-Wno-format-truncation'
-- 
2.27.0

