cmake: make "-no-pie" optional
authorGary Lin <glin@suse.com>
Fri, 12 Mar 2021 03:32:19 +0000 (11:32 +0800)
committeryonghong-song <ys114321@gmail.com>
Fri, 19 Mar 2021 23:20:45 +0000 (16:20 -0700)
The recent linux distros already support PIE so it shouldn't be a
problem to remove "-no-pie". To avoid issue#782, we make "-no-pie"
optional and enable it by default. For the distro with PIE luajit,
just add the following build option:

   -DENABLE_NO_PIE=OFF

Then, bcc-lua will be built with PIE support.

Signed-off-by: Gary Lin <glin@suse.com>
CMakeLists.txt
cmake/FindCompilerFlag.cmake

index 21246d42d3ac2f41491335a2b556b83f9326e82e..720969147241a5bb1f0c147afb41eb47bf438120 100644 (file)
@@ -38,6 +38,8 @@ endif()
 #  $ cmake -DKERNEL_INCLUDE_DIRS=/tmp/headers/include/ ...
 include_directories(${KERNEL_INCLUDE_DIRS})
 
+option(ENABLE_NO_PIE "Build bcc-lua without PIE" ON)
+
 include(cmake/GetGitRevisionDescription.cmake)
 include(cmake/version.cmake)
 include(CMakeDependentOption)
index 04256a1973362e3bd178882083a8b7cc870ccb74..9b150ab5c65dd0ce1cea0ea9c0634b8f43e6f3dd 100644 (file)
@@ -1,6 +1,8 @@
 # Copyright (c) 2017 Facebook, Inc.
 # Licensed under the Apache License, Version 2.0 (the "License")
 
+if (ENABLE_NO_PIE)
+
 if (CMAKE_C_COMPILER_ID MATCHES "Clang")
        set(COMPILER_NOPIE_FLAG "-nopie")
 else()
@@ -16,6 +18,8 @@ else()
        set(CMAKE_REQUIRED_FLAGS "${_backup_c_flags}")
 endif()
 
+endif(ENABLE_NO_PIE)
+
 # check whether reallocarray availability
 # this is used to satisfy reallocarray usage under src/cc/libbpf/
 CHECK_CXX_SOURCE_COMPILES(