Skip to content

Commit fbb8a0c

Browse files
authored
[CMake] Add a linker test for -Bsymbolic-functions to AddLLVM (#79539)
Add a linker test for -Bsymbolic-functions to AddLLVM and remove the illumos hardcoded bits for its handling. OpenBSD also has a local patch for linking with the old BFD linker on mips64 and sparc64.
1 parent 6d515ce commit fbb8a0c

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

clang/tools/clang-shlib/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ endif()
5757

5858
# Optimize function calls for default visibility definitions to avoid PLT and
5959
# reduce dynamic relocations.
60-
if (NOT APPLE AND NOT MINGW AND NOT CYGWIN AND NOT LLVM_LINKER_IS_SOLARISLD_ILLUMOS)
60+
if (NOT APPLE AND LLVM_LINKER_SUPPORTS_B_SYMBOLIC_FUNCTIONS)
6161
target_link_options(clang-cpp PRIVATE LINKER:-Bsymbolic-functions)
6262
endif()
6363
if (MINGW OR CYGWIN)

llvm/cmake/modules/AddLLVM.cmake

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -257,12 +257,6 @@ if (NOT DEFINED LLVM_LINKER_DETECTED AND NOT WIN32)
257257
set(LLVM_LINKER_DETECTED YES CACHE INTERNAL "")
258258
set(LLVM_LINKER_IS_GNULD YES CACHE INTERNAL "")
259259
message(STATUS "Linker detection: GNU ld")
260-
elseif("${stderr}" MATCHES "(illumos)" OR
261-
"${stdout}" MATCHES "(illumos)")
262-
set(LLVM_LINKER_DETECTED YES CACHE INTERNAL "")
263-
set(LLVM_LINKER_IS_SOLARISLD YES CACHE INTERNAL "")
264-
set(LLVM_LINKER_IS_SOLARISLD_ILLUMOS YES CACHE INTERNAL "")
265-
message(STATUS "Linker detection: Solaris ld (illumos)")
266260
elseif("${stderr}" MATCHES "Solaris Link Editors" OR
267261
"${stdout}" MATCHES "Solaris Link Editors")
268262
set(LLVM_LINKER_DETECTED YES CACHE INTERNAL "")
@@ -296,6 +290,7 @@ if (NOT DEFINED LLVM_LINKER_DETECTED AND NOT WIN32)
296290
endif()
297291

298292
function(add_link_opts target_name)
293+
include(CheckLinkerFlag)
299294
get_llvm_distribution(${target_name} in_distribution in_distribution_var)
300295
if(NOT in_distribution)
301296
# Don't LTO optimize targets that aren't part of any distribution.
@@ -327,7 +322,6 @@ function(add_link_opts target_name)
327322
elseif(${CMAKE_SYSTEM_NAME} MATCHES "SunOS" AND LLVM_LINKER_IS_SOLARISLD)
328323
# Support for ld -z discard-unused=sections was only added in
329324
# Solaris 11.4. GNU ld ignores it, but warns every time.
330-
include(CheckLinkerFlag)
331325
check_linker_flag(CXX "-Wl,-z,discard-unused=sections" LINKER_SUPPORTS_Z_DISCARD_UNUSED)
332326
if (LINKER_SUPPORTS_Z_DISCARD_UNUSED)
333327
set_property(TARGET ${target_name} APPEND_STRING PROPERTY
@@ -355,6 +349,12 @@ function(add_link_opts target_name)
355349
set_property(TARGET ${target_name} APPEND_STRING PROPERTY
356350
LINK_FLAGS " -Wl,-brtl")
357351
endif()
352+
353+
# Check for existence of symbolic functions flag. Not supported
354+
# by the older BFD linker (such as on some OpenBSD archs), the
355+
# MinGW driver for LLD, and the Solaris native linker.
356+
check_linker_flag(CXX "-Wl,-Bsymbolic-functions"
357+
LLVM_LINKER_SUPPORTS_B_SYMBOLIC_FUNCTIONS)
358358
endfunction(add_link_opts)
359359

360360
# Set each output directory according to ${CMAKE_CONFIGURATION_TYPES}.

llvm/tools/llvm-shlib/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ if(LLVM_BUILD_LLVM_DYLIB)
7070
# Solaris ld does not accept global: *; so there is no way to version *all* global symbols
7171
set(LIB_NAMES -Wl,--version-script,${LLVM_LIBRARY_DIR}/tools/llvm-shlib/simple_version_script.map ${LIB_NAMES})
7272
endif()
73-
if (NOT MINGW AND NOT LLVM_LINKER_IS_SOLARISLD_ILLUMOS)
73+
if (LLVM_LINKER_SUPPORTS_B_SYMBOLIC_FUNCTIONS)
7474
# Optimize function calls for default visibility definitions to avoid PLT and
7575
# reduce dynamic relocations.
7676
# Note: for -fno-pic default, the address of a function may be different from

0 commit comments

Comments
 (0)