Skip to content

Commit

Permalink
Merge pull request #449 from haampie/fix/hide-symbols
Browse files Browse the repository at this point in the history
Hide more symbols in ELF shared libs
  • Loading branch information
rkaminsk authored Aug 12, 2023
2 parents ef795b1 + d8984d0 commit ec6b69b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
11 changes: 11 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE "Release")
endif()

include(CheckCXXSourceCompiles)
include(GNUInstallDirs)
include(CMakeDependentOption)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
Expand Down Expand Up @@ -245,6 +246,16 @@ if (POLICY CMP0063 AND (CLINGO_BUILD_SHARED OR Python_Development_FOUND OR LUA_F
set(CMAKE_C_VISIBILITY_PRESET hidden)
endif()

# Test support for -Wl,--version-script as a linker flag
if (CLINGO_BUILD_SHARED AND UNIX AND NOT APPLE)
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/version.map" "{global: f; local: *;};")
set(CMAKE_REQUIRED_FLAGS_SAVE ${CMAKE_REQUIRED_FLAGS})
set(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS} "-Wl,--version-script='${CMAKE_CURRENT_BINARY_DIR}/version.map'")
check_cxx_source_compiles("void f(){} int main(){}" CLINGO_USE_VERSION_SCRIPT)
set(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS_SAVE})
file(REMOVE "${CMAKE_CURRENT_BINARY_DIR}/version.map")
endif()

enable_testing()

if (CLINGO_USE_LIB)
Expand Down
4 changes: 4 additions & 0 deletions libclingo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ target_include_directories(libclingo
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
target_compile_definitions(libclingo ${clingo_private_scope_} CLINGO_BUILD_LIBRARY)

if (CLINGO_USE_VERSION_SCRIPT)
set_target_properties(libclingo PROPERTIES LINK_FLAGS "-Wl,--version-script='${CMAKE_CURRENT_SOURCE_DIR}/clingo.map'")
endif()

if (NOT CLINGO_BUILD_SHARED)
target_compile_definitions(libclingo PUBLIC CLINGO_NO_VISIBILITY)
endif()
Expand Down
4 changes: 4 additions & 0 deletions libclingo/clingo.map
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
global: clingo_*; gringo_*; g_clingo_*;
local: *;
};

0 comments on commit ec6b69b

Please sign in to comment.