Skip to content

Commit

Permalink
fix lua-bcc build issue with cmake try_compile
Browse files Browse the repository at this point in the history
Certain versions of recent gcc (e.g., gcc 6.3.0 on ubuntu17.04)
has pie enabled by default at linker (collect2) stage.
The compilation flag "-no-pie" is available to negate
this linker option.

Add -no-pie to compilation flag only if it is available.
Earlier gcc compiler may not have this option but it does
not have linker pie on-by-default either.

Tested with ubuntu 17.04 and my local gcc 4.8.5 (not accepting -no-pie).

Signed-off-by: Yonghong Song <[email protected]>
  • Loading branch information
yonghong-song authored and drzaeus77 committed Aug 24, 2017
1 parent d32a61b commit 75e2f37
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ include(cmake/GetGitRevisionDescription.cmake)
include(cmake/version.cmake)
include(GNUInstallDirs)
include(CheckCXXCompilerFlag)
include(cmake/FindCompilerFlag.cmake)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)

Expand Down
15 changes: 15 additions & 0 deletions cmake/FindCompilerFlag.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright (c) 2017 Facebook, Inc.
# Licensed under the Apache License, Version 2.0 (the "License")

if (CMAKE_C_COMPILER_ID MATCHES "Clang")
set(COMPILER_NOPIE_FLAG "-nopie")
else()
set(CMAKE_REQUIRED_FLAGS "-no-pie")
CHECK_CXX_SOURCE_COMPILES("int main() {return 0;}"
HAVE_NO_PIE_FLAG)
if (HAVE_NO_PIE_FLAG)
set(COMPILER_NOPIE_FLAG "-no-pie")
else()
set(COMPILER_NOPIE_FLAG "")
endif()
endif()
8 changes: 3 additions & 5 deletions src/lua/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@ if (LUAJIT_LIBRARIES AND LUAJIT)
set_target_properties(bcc-lua PROPERTIES LINKER_LANGUAGE C)
target_link_libraries(bcc-lua ${LUAJIT_LIBRARIES})
target_link_libraries(bcc-lua -Wl,--whole-archive bcc-static -Wl,--no-whole-archive)
if (CMAKE_C_COMPILER_ID MATCHES "Clang")
target_link_libraries(bcc-lua -nopie)
else()
target_link_libraries(bcc-lua --no-pie)
endif()
if (NOT COMPILER_NOPIE_FLAG EQUAL "")
target_link_libraries(bcc-lua ${COMPILER_NOPIE_FLAG})
endif()

install(TARGETS bcc-lua RUNTIME DESTINATION bin)
endif()

0 comments on commit 75e2f37

Please sign in to comment.