1From ec2d36466c9050ee282ea1c3bb1b5f1f61c96ecb Mon Sep 17 00:00:00 2001
2From: Yi Zhao <yi.zhao@windriver.com>
3Date: Mon, 17 Jul 2023 14:33:32 +0800
4Subject: [PATCH] Do not specify PIE flag explicitly
5
6For nodistro distro, packages are built without PIE because
7security_flags.inc is not included by default. But in vsomeip, the PIE
8flag is explicitly specified in CMAKE_CXX_FLAGS, which will cause
9building with PIE even in nodistro, causing an error when linking the
10googletest static library:
11
12TOPDIR/tmp-glibc/work/cortexa53-oe-linux/vsomeip/3.1.20.3-r0/recipe-sysroot-native/usr/bin/aarch64-oe-linux/../../libexec/aarch64-oe-linux/gcc/aarch64-oe-linux/12.2.0/ld:
13TOPDIR/tmp-glibc/work/cortexa53-oe-linux/vsomeip/3.1.20.3-r0/recipe-sysroot/usr/lib/libgtest.a(gtest-all.cc.o)(.text+0x4a90):
14unresolvable R_AARCH64_ADR_PREL_PG_HI21 relocation against symbol `_ZSt4cerr@@GLIBCXX_3.4'
15
16Remove PIE flag from CMAKE_CXX_FLAGS and only enable PIE flag by
17including security_flags.inc.
18
19Upstream-Status: Inappropriate [embedded specific]
20
21Signed-off-by: Yi Zhao <yi.zhao@windriver.com>
22---
23 CMakeLists.txt | 4 ++--
24 1 file changed, 2 insertions(+), 2 deletions(-)
25
26diff --git a/CMakeLists.txt b/CMakeLists.txt
27index f1bcba27..2653a4df 100644
28--- a/CMakeLists.txt
29+++ b/CMakeLists.txt
30@@ -60,12 +60,12 @@ if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
31 if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
32     # This is only relevant for GCC and causes warnings on Clang
33     set(EXPORTSYMBOLS "-Wl,-export-dynamic -Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/exportmap.gcc")
34-    set(OS_CXX_FLAGS "${OS_CXX_FLAGS} -pie -Wno-tsan -Wl,-z,relro,-z,now")
35+    set(OS_CXX_FLAGS "${OS_CXX_FLAGS} -Wno-tsan -Wl,-z,relro,-z,now")
36 endif()
37
38     set(NO_DEPRECATED "")
39     set(OPTIMIZE "")
40-    set(OS_CXX_FLAGS "${OS_CXX_FLAGS} -D_GLIBCXX_USE_NANOSLEEP -pthread -O -Wall -Wextra -Wformat -Wformat-security -Wconversion -fexceptions -fstrict-aliasing -fstack-protector-strong -fasynchronous-unwind-tables -fno-omit-frame-pointer -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Wpedantic -Werror -fPIE")
41+    set(OS_CXX_FLAGS "${OS_CXX_FLAGS} -D_GLIBCXX_USE_NANOSLEEP -pthread -O -Wall -Wextra -Wformat -Wformat-security -Wconversion -fexceptions -fstrict-aliasing -fstack-protector-strong -fasynchronous-unwind-tables -fno-omit-frame-pointer -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Wpedantic")
42
43     # force all use of std::mutex and std::recursive_mutex to use runtime init
44     # instead of static initialization so mutexes can be hooked to enable PI as needed
45--
462.25.1
47
48