Skip to content

Commit

Permalink
Reapply "[CMake] Fold export_executable_symbols_* into function args. (
Browse files Browse the repository at this point in the history
…#101741)" (#102138)

Fix the builds with LLVM_TOOL_LLVM_DRIVER_BUILD enabled.

LLVM_ENABLE_EXPORTED_SYMBOLS_IN_EXECUTABLES is not completely
compatible with export_executable_symbols as the later will be ignored
if the previous is set to NO.

Fix the issue by passing if symbols need to be exported to
llvm_add_exectuable so the link flag can be determined directly
without calling export_executable_symbols_* later.
  • Loading branch information
cachemeifyoucan authored and TIFitis committed Aug 8, 2024
1 parent 01925ee commit bb24f0d
Show file tree
Hide file tree
Showing 58 changed files with 70 additions and 125 deletions.
6 changes: 2 additions & 4 deletions clang-tools-extra/clang-tidy/tool/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ clang_target_link_libraries(clangTidyMain
# Support plugins.
if(CLANG_PLUGIN_SUPPORT)
set(support_plugins SUPPORT_PLUGINS)
set(export_symbols EXPORT_SYMBOLS_FOR_PLUGINS)
endif()

add_clang_tool(clang-tidy
Expand All @@ -41,6 +42,7 @@ add_clang_tool(clang-tidy
DEPENDS
clang-resource-headers
${support_plugins}
${export_symbols}
)
clang_target_link_libraries(clang-tidy
PRIVATE
Expand All @@ -57,10 +59,6 @@ target_link_libraries(clang-tidy
${ALL_CLANG_TIDY_CHECKS}
)

if(CLANG_PLUGIN_SUPPORT)
export_executable_symbols_for_plugins(clang-tidy)
endif()

install(PROGRAMS clang-tidy-diff.py
DESTINATION "${CMAKE_INSTALL_DATADIR}/clang"
COMPONENT clang-tidy)
Expand Down
2 changes: 1 addition & 1 deletion clang/cmake/modules/AddClang.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ macro(add_clang_tool name)
AND (NOT LLVM_DISTRIBUTION_COMPONENTS OR ${name} IN_LIST LLVM_DISTRIBUTION_COMPONENTS)
)
set(get_obj_args ${ARGN})
list(FILTER get_obj_args EXCLUDE REGEX "^SUPPORT_PLUGINS$")
list(FILTER get_obj_args EXCLUDE REGEX "^(SUPPORT_PLUGINS|EXPORT_SYMBOLS_FOR_PLUGINS)$")
generate_llvm_objects(${name} ${get_obj_args})
add_custom_target(${name} DEPENDS llvm-driver clang-resource-headers)
else()
Expand Down
3 changes: 1 addition & 2 deletions clang/tools/clang-linker-wrapper/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ add_clang_tool(clang-linker-wrapper

DEPENDS
${tablegen_deps}
EXPORT_SYMBOLS_FOR_PLUGINS
)

set(CLANG_LINKER_WRAPPER_LIB_DEPS
Expand All @@ -41,5 +42,3 @@ target_link_libraries(clang-linker-wrapper
PRIVATE
${CLANG_LINKER_WRAPPER_LIB_DEPS}
)

export_executable_symbols_for_plugins(clang-linker-wrapper)
4 changes: 2 additions & 2 deletions clang/tools/clang-repl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ set( LLVM_LINK_COMPONENTS

add_clang_tool(clang-repl
ClangRepl.cpp

EXPORT_SYMBOLS_FOR_PLUGINS
)

if(MSVC)
Expand Down Expand Up @@ -61,8 +63,6 @@ clang_target_link_libraries(clang-repl PRIVATE
clangInterpreter
)

export_executable_symbols_for_plugins(clang-repl)

# The clang-repl binary can get huge with static linking in debug mode.
# Some 32-bit targets use PLT slots with limited branch range by default and we
# start to exceed this limit, e.g. when linking for arm-linux-gnueabihf with
Expand Down
7 changes: 2 additions & 5 deletions clang/tools/driver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ set( LLVM_LINK_COMPONENTS
# Support plugins.
if(CLANG_PLUGIN_SUPPORT)
set(support_plugins SUPPORT_PLUGINS)
set(export_symbols EXPORT_SYMBOLS_FOR_PLUGINS)
endif()

add_clang_tool(clang
Expand All @@ -35,6 +36,7 @@ add_clang_tool(clang
ARMTargetParserTableGen
AArch64TargetParserTableGen
${support_plugins}
${export_symbols}
GENERATE_DRIVER
)

Expand All @@ -54,11 +56,6 @@ else()
set_target_properties(clang PROPERTIES VERSION ${CLANG_EXECUTABLE_VERSION})
endif()

# Support plugins.
if(CLANG_PLUGIN_SUPPORT)
export_executable_symbols_for_plugins(clang)
endif()

add_dependencies(clang clang-resource-headers)

if(NOT CLANG_LINKS_TO_CREATE)
Expand Down
4 changes: 2 additions & 2 deletions clang/unittests/Interpreter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ add_clang_unittest(ClangReplInterpreterTests
InterpreterTest.cpp
InterpreterExtensionsTest.cpp
CodeCompletionTest.cpp

EXPORT_SYMBOLS
)
target_link_libraries(ClangReplInterpreterTests PUBLIC
clangAST
Expand All @@ -28,8 +30,6 @@ if(NOT WIN32)
add_subdirectory(ExceptionTests)
endif()

export_executable_symbols(ClangReplInterpreterTests)

if(MSVC)
set_target_properties(ClangReplInterpreterTests PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS 1)

Expand Down
4 changes: 2 additions & 2 deletions clang/unittests/Interpreter/ExceptionTests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ set(LLVM_LINK_COMPONENTS

add_clang_unittest(ClangReplInterpreterExceptionTests
InterpreterExceptionTest.cpp

EXPORT_SYMBOLS
)

llvm_update_compile_flags(ClangReplInterpreterExceptionTests)
Expand All @@ -22,5 +24,3 @@ target_link_libraries(ClangReplInterpreterExceptionTests PUBLIC
clangFrontend
)
add_dependencies(ClangReplInterpreterExceptionTests clang-resource-headers)

export_executable_symbols(ClangReplInterpreterExceptionTests)
16 changes: 9 additions & 7 deletions flang/tools/flang-driver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,18 @@ set( LLVM_LINK_COMPONENTS
TargetParser
)

option(FLANG_PLUGIN_SUPPORT "Build Flang with plugin support." ON)

# Enable support for plugins, which need access to symbols from flang-new
if(FLANG_PLUGIN_SUPPORT)
set(export_symbols EXPORT_SYMBOLS_FOR_PLUGINS)
endif()

add_flang_tool(flang-new
driver.cpp
fc1_main.cpp

${export_symbols}
)

target_link_libraries(flang-new
Expand All @@ -28,11 +37,4 @@ clang_target_link_libraries(flang-new
clangBasic
)

option(FLANG_PLUGIN_SUPPORT "Build Flang with plugin support." ON)

# Enable support for plugins, which need access to symbols from flang-new
if(FLANG_PLUGIN_SUPPORT)
export_executable_symbols_for_plugins(flang-new)
endif()

install(TARGETS flang-new DESTINATION "${CMAKE_INSTALL_BINDIR}")
2 changes: 1 addition & 1 deletion lld/cmake/modules/AddLLD.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ macro(add_lld_tool name)
AND (NOT LLVM_DISTRIBUTION_COMPONENTS OR ${name} IN_LIST LLVM_DISTRIBUTION_COMPONENTS)
)
set(get_obj_args ${ARGN})
list(FILTER get_obj_args EXCLUDE REGEX "^SUPPORT_PLUGINS$")
list(FILTER get_obj_args EXCLUDE REGEX "^(SUPPORT_PLUGINS|EXPORT_SYMBOLS_FOR_PLUGINS)$")
generate_llvm_objects(${name} ${get_obj_args})
add_custom_target(${name} DEPENDS llvm-driver)
else()
Expand Down
2 changes: 1 addition & 1 deletion lld/tools/lld/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ add_lld_tool(lld

SUPPORT_PLUGINS
GENERATE_DRIVER
EXPORT_SYMBOLS_FOR_PLUGINS
)
export_executable_symbols_for_plugins(lld)

function(lld_target_link_libraries target type)
if (TARGET obj.${target})
Expand Down
4 changes: 2 additions & 2 deletions llvm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1197,7 +1197,7 @@ if( ${CMAKE_SYSTEM_NAME} MATCHES SunOS )
endif( ${CMAKE_SYSTEM_NAME} MATCHES SunOS )

# Make sure we don't get -rdynamic in every binary. For those that need it,
# use export_executable_symbols(target).
# use EXPORT_SYMBOLS argument.
set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")

include(AddLLVM)
Expand Down Expand Up @@ -1238,7 +1238,7 @@ if( LLVM_INCLUDE_UTILS )
if( LLVM_INCLUDE_TESTS )
set(LLVM_SUBPROJECT_TITLE "Third-Party/Google Test")
add_subdirectory(${LLVM_THIRD_PARTY_DIR}/unittest ${CMAKE_CURRENT_BINARY_DIR}/third-party/unittest)
set(LLVM_SUBPROJECT_TITLE)
set(LLVM_SUBPROJECT_TITLE)
endif()
else()
if ( LLVM_INCLUDE_TESTS )
Expand Down
13 changes: 10 additions & 3 deletions llvm/cmake/modules/AddLLVM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,7 @@ endmacro()

macro(add_llvm_executable name)
cmake_parse_arguments(ARG
"DISABLE_LLVM_LINK_LLVM_DYLIB;IGNORE_EXTERNALIZE_DEBUGINFO;NO_INSTALL_RPATH;SUPPORT_PLUGINS"
"DISABLE_LLVM_LINK_LLVM_DYLIB;IGNORE_EXTERNALIZE_DEBUGINFO;NO_INSTALL_RPATH;SUPPORT_PLUGINS;EXPORT_SYMBOLS;EXPORT_SYMBOLS_FOR_PLUGINS"
"ENTITLEMENTS;BUNDLE_PATH"
""
${ARGN})
Expand Down Expand Up @@ -1070,7 +1070,8 @@ macro(add_llvm_executable name)
endif(LLVM_EXPORTED_SYMBOL_FILE)

if (DEFINED LLVM_ENABLE_EXPORTED_SYMBOLS_IN_EXECUTABLES AND
NOT LLVM_ENABLE_EXPORTED_SYMBOLS_IN_EXECUTABLES)
NOT LLVM_ENABLE_EXPORTED_SYMBOLS_IN_EXECUTABLES AND
NOT ARG_EXPORT_SYMBOLS AND NOT ARG_EXPORT_SYMBOLS_FOR_PLUGINS)
if(LLVM_LINKER_SUPPORTS_NO_EXPORTED_SYMBOLS)
set_property(TARGET ${name} APPEND_STRING PROPERTY
LINK_FLAGS " -Wl,-no_exported_symbols")
Expand All @@ -1080,6 +1081,12 @@ macro(add_llvm_executable name)
endif()
endif()

if (ARG_EXPORT_SYMBOLS)
export_executable_symbols(${name})
elseif(ARG_EXPORT_SYMBOLS_FOR_PLUGINS)
export_executable_symbols_for_plugins(${name})
endif()

if (LLVM_LINK_LLVM_DYLIB AND NOT ARG_DISABLE_LLVM_LINK_LLVM_DYLIB)
set(USE_SHARED USE_SHARED)
endif()
Expand Down Expand Up @@ -1464,7 +1471,7 @@ macro(add_llvm_example name)
if( NOT LLVM_BUILD_EXAMPLES )
set(EXCLUDE_FROM_ALL ON)
endif()
add_llvm_executable(${name} ${ARGN})
add_llvm_executable(${name} EXPORT_SYMBOLS ${ARGN})
if( LLVM_BUILD_EXAMPLES )
install(TARGETS ${name} RUNTIME DESTINATION "${LLVM_EXAMPLES_INSTALL_DIR}")
endif()
Expand Down
4 changes: 2 additions & 2 deletions llvm/examples/ExceptionDemo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ endif()

add_llvm_example(ExceptionDemo
ExceptionDemo.cpp
)

export_executable_symbols(ExceptionDemo)
EXPORT_SYMBOLS
)
4 changes: 2 additions & 2 deletions llvm/examples/HowToUseLLJIT/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ set(LLVM_LINK_COMPONENTS

add_llvm_example(HowToUseLLJIT
HowToUseLLJIT.cpp
)

export_executable_symbols(HowToUseLLJIT)
EXPORT_SYMBOLS
)
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,3 @@ set(LLVM_LINK_COMPONENTS
add_kaleidoscope_chapter(BuildingAJIT-Ch1
toy.cpp
)

export_executable_symbols(BuildingAJIT-Ch1)
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,3 @@ set(LLVM_LINK_COMPONENTS
add_kaleidoscope_chapter(BuildingAJIT-Ch2
toy.cpp
)

export_executable_symbols(BuildingAJIT-Ch2)
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,3 @@ set(LLVM_LINK_COMPONENTS
add_kaleidoscope_chapter(BuildingAJIT-Ch3
toy.cpp
)

export_executable_symbols(BuildingAJIT-Ch3)
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,3 @@ set(LLVM_LINK_COMPONENTS
add_kaleidoscope_chapter(BuildingAJIT-Ch4
toy.cpp
)

export_executable_symbols(BuildingAJIT-Ch4)
2 changes: 1 addition & 1 deletion llvm/examples/Kaleidoscope/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set_target_properties(Kaleidoscope PROPERTIES FOLDER "LLVM/Examples")

macro(add_kaleidoscope_chapter name)
add_dependencies(Kaleidoscope ${name})
add_llvm_example(${name} ${ARGN})
add_llvm_example(${name} EXPORT_SYMBOLS ${ARGN})
endmacro(add_kaleidoscope_chapter name)

add_subdirectory(BuildingAJIT)
Expand Down
2 changes: 0 additions & 2 deletions llvm/examples/Kaleidoscope/Chapter4/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,3 @@ set(LLVM_LINK_COMPONENTS
add_kaleidoscope_chapter(Kaleidoscope-Ch4
toy.cpp
)

export_executable_symbols(Kaleidoscope-Ch4)
2 changes: 0 additions & 2 deletions llvm/examples/Kaleidoscope/Chapter5/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,3 @@ set(LLVM_LINK_COMPONENTS
add_kaleidoscope_chapter(Kaleidoscope-Ch5
toy.cpp
)

export_executable_symbols(Kaleidoscope-Ch5)
2 changes: 0 additions & 2 deletions llvm/examples/Kaleidoscope/Chapter6/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,3 @@ set(LLVM_LINK_COMPONENTS
add_kaleidoscope_chapter(Kaleidoscope-Ch6
toy.cpp
)

export_executable_symbols(Kaleidoscope-Ch6)
2 changes: 0 additions & 2 deletions llvm/examples/Kaleidoscope/Chapter7/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,3 @@ set(LLVM_LINK_COMPONENTS
add_kaleidoscope_chapter(Kaleidoscope-Ch7
toy.cpp
)

export_executable_symbols(Kaleidoscope-Ch7)
2 changes: 0 additions & 2 deletions llvm/examples/Kaleidoscope/Chapter8/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,3 @@ set(LLVM_LINK_COMPONENTS
add_kaleidoscope_chapter(Kaleidoscope-Ch8
toy.cpp
)

export_executable_symbols(Kaleidoscope-Ch8)
2 changes: 0 additions & 2 deletions llvm/examples/Kaleidoscope/Chapter9/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,3 @@ set(LLVM_LINK_COMPONENTS
add_kaleidoscope_chapter(Kaleidoscope-Ch9
toy.cpp
)

export_executable_symbols(Kaleidoscope-Ch9)
2 changes: 0 additions & 2 deletions llvm/examples/OrcV2Examples/LLJITDumpObjects/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,3 @@ set(LLVM_LINK_COMPONENTS
add_llvm_example(LLJITDumpObjects
LLJITDumpObjects.cpp
)

export_executable_symbols(LLJITDumpObjects)
2 changes: 0 additions & 2 deletions llvm/examples/OrcV2Examples/LLJITRemovableCode/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,3 @@ set(LLVM_LINK_COMPONENTS
add_llvm_example(LLJITRemovableCode
LLJITRemovableCode.cpp
)

export_executable_symbols(LLJITRemovableCode)
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,3 @@ set(LLVM_LINK_COMPONENTS
add_llvm_example(LLJITWithCustomObjectLinkingLayer
LLJITWithCustomObjectLinkingLayer.cpp
)

export_executable_symbols(LLJITWithCustomObjectLinkingLayer)
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,3 @@ set(LLVM_LINK_COMPONENTS
add_llvm_example(LLJITWithExecutorProcessControl
LLJITWithExecutorProcessControl.cpp
)

export_executable_symbols(LLJITWithExecutorProcessControl)
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,3 @@ set(LLVM_LINK_COMPONENTS
add_llvm_example(LLJITWithGDBRegistrationListener
LLJITWithGDBRegistrationListener.cpp
)

# We want JIT'd code to be able to link against process symbols like printf
# for this example, so make sure they're exported.
export_executable_symbols(LLJITWithGDBRegistrationListener)
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,3 @@ set(LLVM_LINK_COMPONENTS
add_llvm_example(LLJITWithInitializers
LLJITWithInitializers.cpp
)

export_executable_symbols(LLJITWithInitializers)
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,3 @@ set(LLVM_LINK_COMPONENTS
add_llvm_example(LLJITWithLazyReexports
LLJITWithLazyReexports.cpp
)

export_executable_symbols(LLJITWithLazyReexports)
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,3 @@ set(LLVM_LINK_COMPONENTS
add_llvm_example(LLJITWithObjectCache
LLJITWithObjectCache.cpp
)

export_executable_symbols(LLJITWithObjectCache)
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,3 @@ set(LLVM_LINK_COMPONENTS
add_llvm_example(LLJITWithObjectLinkingLayerPlugin
LLJITWithObjectLinkingLayerPlugin.cpp
)

export_executable_symbols(LLJITWithObjectLinkingLayerPlugin)
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,3 @@ set(LLVM_LINK_COMPONENTS
add_llvm_example(LLJITWithOptimizingIRTransform
LLJITWithOptimizingIRTransform.cpp
)

export_executable_symbols(LLJITWithOptimizingIRTransform)
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,4 @@ if (LLVM_INCLUDE_UTILS)
DEPENDS
llvm-jitlink-executor
)

export_executable_symbols(LLJITWithRemoteDebugging)
endif()
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,3 @@ set(LLVM_LINK_COMPONENTS
add_llvm_example(LLJITWithThinLTOSummaries
LLJITWithThinLTOSummaries.cpp
)

export_executable_symbols(LLJITWithThinLTOSummaries)
Loading

0 comments on commit bb24f0d

Please sign in to comment.