diff --git a/ffi/CMakeLists.txt b/ffi/CMakeLists.txt index 5b7807339..a11e65051 100755 --- a/ffi/CMakeLists.txt +++ b/ffi/CMakeLists.txt @@ -13,6 +13,11 @@ include(GNUInstallDirs) set(CMAKE_CXX_STANDARD 17) +# Preset function visibility to hidden, API functions +# are annotated explicitly to use 'default' visibility. +set(CMAKE_CXX_VISIBILITY_PRESET "hidden") +set(CMAKE_C_VISIBILITY_PRESET "hidden") + find_package(LLVM REQUIRED CONFIG) message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}") @@ -316,7 +321,6 @@ endif() message(STATUS "LLVM target link libraries: ${llvm_libs}") target_link_libraries(llvmlite ${llvm_libs}) - # -flto and --exclude-libs allow removal of unused parts of LLVM # TODO: these options are just set, they should really be tested for # suitability. @@ -328,6 +332,12 @@ if(UNIX AND NOT APPLE) if (LLVMLITE_FLTO) STRING(APPEND FORCED_LINK_FLAGS " -flto") endif() + if(NOT LLVMLITE_SHARED) + # If LLVM is statically linked, we specify -Bsymbolic to prevent + # that LLVM symbols can be interposed upon by previously + # loaded shared objects that export LLVM symbols. + STRING(APPEND FORCED_LINK_FLAGS " -Wl,-Bsymbolic") + endif() set_property(TARGET llvmlite APPEND_STRING PROPERTY LINK_FLAGS "${FORCED_LINK_FLAGS}") elseif(APPLE) diff --git a/ffi/core.h b/ffi/core.h index 2d54d4453..22296066c 100644 --- a/ffi/core.h +++ b/ffi/core.h @@ -17,7 +17,8 @@ #if defined(HAVE_DECLSPEC_DLL) #define API_EXPORT(RTYPE) __declspec(dllexport) RTYPE #else -#define API_EXPORT(RTYPE) RTYPE +// Non-windows: use visibility attributes. +#define API_EXPORT(RTYPE) __attribute__((visibility("default"))) RTYPE #endif extern "C" {