Skip to content

Commit

Permalink
Restore PIE support being dropped on Linux (osquery#6611)
Browse files Browse the repository at this point in the history
CMake ignores the sysroot when testing the support of PIE,
so the link test fails when it tries to check for PIE support
and decides that it's not supported.
Therefore we tell CMake that PIE is supported when using the
osquery-toolchain and leave the automatic test for other toolchains.

Temporarily disable PIE on executables built with the
osquery-toolchain libFuzzer, since it has not been compiled with PIE/PIC
support.
  • Loading branch information
Smjert authored and nabilschear committed Aug 31, 2020
1 parent 58ef034 commit 4287ba0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
9 changes: 7 additions & 2 deletions cmake/flags.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
include(CheckPIESupported)
check_pie_supported()
if(NOT DEFINED OSQUERY_TOOLCHAIN_SYSROOT)
include(CheckPIESupported)
check_pie_supported()
if(NOT CMAKE_C_LINK_PIE_SUPPORT OR NOT CMAKE_CXX_LINK_PIE_SUPPORT)
message(FATAL_ERROR "The linker for the current compiler do not support -fPIE or -pie")
endif()
endif()
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

# The function creates the osquery_<c|cxx>_settings targets with compiler and linker flags
Expand Down
4 changes: 4 additions & 0 deletions cmake/toolchain.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ if(OSQUERY_TOOLCHAIN_SYSROOT)
overwrite_cache_variable("CMAKE_SYSROOT" "PATH" "${OSQUERY_TOOLCHAIN_SYSROOT}")
overwrite_cache_variable("CMAKE_LINK_SEARCH_START_STATIC" "BOOL" "ON")
overwrite_cache_variable("CMAKE_LINK_SEARCH_END_STATIC" "BOOL" "ON")
overwrite_cache_variable("CMAKE_CXX_LINK_NO_PIE_SUPPORTED" "INTERNAL" "TRUE")
overwrite_cache_variable("CMAKE_CXX_LINK_PIE_SUPPORTED" "INTERNAL" "TRUE")
overwrite_cache_variable("CMAKE_C_LINK_NO_PIE_SUPPORTED" "INTERNAL" "TRUE")
overwrite_cache_variable("CMAKE_C_LINK_PIE_SUPPORTED" "INTERNAL" "TRUE")
else()
option(OSQUERY_STATIC_BUILD "Whether to prefer linking static libraries or not")

Expand Down
6 changes: 5 additions & 1 deletion osquery/main/harnesses/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ endfunction()

function(generateOsqueryFuzzHarness harness_name source_files)
add_osquery_executable(${harness_name} ${source_files})
set_target_properties(${harness_name} PROPERTIES POSITION_INDEPENDENT_CODE true)
# TODO: osquery-toolchain libFuzzer is not compiled with -fPIC support,
# temporarily disable PIE until the toolchain is fixed.
if(DEFINED OSQUERY_TOOLCHAIN_SYSROOT)
set_target_properties(${harness_name} PROPERTIES POSITION_INDEPENDENT_CODE OFF)
endif()
target_link_libraries(${harness_name} PRIVATE osquery_harnesses)
target_link_options(${harness_name} PRIVATE -fsanitize=fuzzer)
endfunction()
Expand Down

0 comments on commit 4287ba0

Please sign in to comment.