Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use linker tools on OSX & Linux to limit exports (#4651) #5659

Merged
merged 12 commits into from
Jan 21, 2021
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,12 @@ else
LIBHALIDE_SONAME_FLAGS=
endif

ifeq ($(UNAME), Linux)
LIBHALIDE_EXPORTS=-Wl,--version-script=$(ROOT_DIR)/src/exported_symbols.linux
else
LIBHALIDE_EXPORTS=-Wl,-exported_symbols_list $(ROOT_DIR)/src/exported_symbols.osx
alexreinking marked this conversation as resolved.
Show resolved Hide resolved
endif

$(BIN_DIR)/libHalide.$(SHARED_EXT): $(OBJECTS) $(INITIAL_MODULES)
@mkdir -p $(@D)
$(CXX) -shared $(OBJECTS) $(INITIAL_MODULES) $(LLVM_LIBS_FOR_SHARED_LIBHALIDE) $(LLVM_SYSTEM_LIBS) $(COMMON_LD_FLAGS) $(INSTALL_NAME_TOOL_LD_FLAGS) $(LIBHALIDE_SONAME_FLAGS) -o $(BIN_DIR)/libHalide.$(SHARED_EXT)
Expand Down
12 changes: 12 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,18 @@ add_library(Halide
$<TARGET_OBJECTS:Halide_initmod>)
add_library(Halide::Halide ALIAS Halide)

# TODO: there is probably a more elegant way to do these conditionals in CMake
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
alexreinking marked this conversation as resolved.
Show resolved Hide resolved
# using Clang
target_link_options(Halide PRIVATE -Wl,-exported_symbols_list ${CMAKE_CURRENT_LIST_DIR}/exported_symbols.osx)
alexreinking marked this conversation as resolved.
Show resolved Hide resolved
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
# using GCC
target_link_options(Halide PRIVATE -Wl,--version-script=${CMAKE_CURRENT_LIST_DIR}/exported_symbols.linux)
alexreinking marked this conversation as resolved.
Show resolved Hide resolved
else ()
# TODO: implement something similar for MSVC
# https://github.com/halide/Halide/issues/4651
endif ()

target_link_libraries(Halide PRIVATE Halide::LLVM)
target_link_libraries(Halide PUBLIC Halide::LanguageOptions)
target_compile_definitions(Halide
Expand Down
19 changes: 19 additions & 0 deletions src/exported_symbols.linux
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
global:
# Everything at global namespace beginning with halide_
halide_* ;

# Some C++ classes that are overloaded at global namespace
# TODO: should not be necessary
# _ZN28halide_handle_cplusplus_type* ;

# Everything in Halide:: namespace (including nested namespace)
# (Don't use _Z*6Halide as that can match things like std::sort()
# with Halide types in the specialization)
_Z?6Halide* ;
_Z??6Halide* ;
_Z???6Halide* ;

local: *;
};

11 changes: 11 additions & 0 deletions src/exported_symbols.osx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Everything at global namespace beginning with halide_
halide_*

# Some C++ classes that are overloaded at global namespace
# TODO: should not be necessary
# __ZN28halide_handle_cplusplus_type*

# Everything in Halide:: namespace (including nested namespace)
__Z?6Halide*
__Z??6Halide*
__Z???6Halide*