Skip to content

Commit 0f28d48

Browse files
h-vetinaritru
authored andcommitted
SONAME introduce option CLANG_FORCE_MATCHING_LIBCLANG_SOVERSION
This reverts commit bc39d7b. rename CLANG_SONAME to LIBCLANG_SOVERSION [clang][cmake] introduce option CLANG_FORCE_MATCHING_LIBCLANG_SOVERSION Differential Revision: https://reviews.llvm.org/D132486
1 parent 70770a1 commit 0f28d48

File tree

6 files changed

+481
-396
lines changed

6 files changed

+481
-396
lines changed

clang/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,12 @@ if(CLANG_ENABLE_ARCMT)
463463
set(CLANG_ENABLE_OBJC_REWRITER ON)
464464
endif()
465465

466+
# This option is a stop-gap, we should commit to removing this as
467+
# soon as possible. See discussion:
468+
# https://discourse.llvm.org/t/rationale-for-removing-versioned-libclang-middle-ground-to-keep-it-behind-option/
469+
option(CLANG_FORCE_MATCHING_LIBCLANG_SOVERSION
470+
"Force the SOVERSION of libclang to be equal to CLANG_MAJOR" ON)
471+
466472
# Clang version information
467473
set(CLANG_EXECUTABLE_VERSION
468474
"${CLANG_VERSION_MAJOR}" CACHE STRING

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,8 @@ clang-extdef-mapping
235235
libclang
236236
--------
237237

238+
- ...
239+
238240
Static Analyzer
239241
---------------
240242

clang/tools/libclang/CMakeLists.txt

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
# The SOVERSION should be updated only if a change is made to the libclang
2+
# ABI, and when it is updated, it should be updated to the current
3+
# LLVM_VERSION_MAJOR.
4+
# Please also see clang/tools/libclang/libclang.map
5+
6+
if(NOT CLANG_FORCE_MATCHING_LIBCLANG_SOVERSION)
7+
# default is to use the SOVERSION according to ABI...
8+
set(LIBCLANG_SOVERSION 13)
9+
else()
10+
# ... unless explicily overridden
11+
set(LIBCLANG_SOVERSION ${CLANG_VERSION_MAJOR})
12+
endif()
13+
14+
# TODO: harmonize usage of LIBCLANG_SOVERSION / LIBCLANG_LIBARY_VERSION
15+
# below; this was added under time-pressure to avoid reverting the
16+
# better default from LLVM 14 for LLVM 15.0.0-rc3, hence no time
17+
# to clean up previous inconsistencies.
18+
119
set(SOURCES
220
ARCMigrate.cpp
321
BuildSystem.cpp
@@ -64,7 +82,8 @@ endif ()
6482
option(LIBCLANG_BUILD_STATIC
6583
"Build libclang as a static library (in addition to a shared one)" OFF)
6684

67-
set(LLVM_EXPORTED_SYMBOL_FILE ${CMAKE_CURRENT_SOURCE_DIR}/libclang.exports)
85+
set(LLVM_EXPORTED_SYMBOL_FILE ${CMAKE_CURRENT_BINARY_DIR}/libclang-generic.exports)
86+
set(LIBCLANG_VERSION_SCRIPT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/libclang.map)
6887

6988
if(MSVC)
7089
# Avoid LNK4197 by not specifying libclang.exports here.
@@ -73,6 +92,20 @@ if(MSVC)
7392
set(LLVM_EXPORTED_SYMBOL_FILE)
7493
endif()
7594

95+
if (UNIX AND NOT APPLE)
96+
set(LLVM_EXPORTED_SYMBOL_FILE)
97+
set(USE_VERSION_SCRIPT ${LLVM_HAVE_LINK_VERSION_SCRIPT})
98+
endif()
99+
100+
if (LLVM_EXPORTED_SYMBOL_FILE)
101+
add_custom_command(OUTPUT ${LLVM_EXPORTED_SYMBOL_FILE}
102+
COMMAND "${Python3_EXECUTABLE}"
103+
ARGS ${CMAKE_CURRENT_SOURCE_DIR}/linker-script-to-export-list.py
104+
${LIBCLANG_VERSION_SCRIPT_FILE}
105+
${LLVM_EXPORTED_SYMBOL_FILE}
106+
DEPENDS ${LIBCLANG_VERSION_SCRIPT_FILE})
107+
endif()
108+
76109
if(LLVM_ENABLE_PIC OR (WIN32 AND NOT LIBCLANG_BUILD_STATIC))
77110
set(ENABLE_SHARED SHARED)
78111
endif()
@@ -145,6 +178,21 @@ if(ENABLE_SHARED)
145178
)
146179
endif()
147180
endif()
181+
if (USE_VERSION_SCRIPT)
182+
target_link_options(libclang PRIVATE "-Wl,--version-script,${CMAKE_CURRENT_SOURCE_DIR}/libclang.map")
183+
# The Solaris 11.4 linker supports a subset of GNU ld version scripts,
184+
# but requires a special option to enable it.
185+
if (${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
186+
target_link_options(libclang PRIVATE "-Wl,-z,gnu-version-script-compat")
187+
endif()
188+
# Ensure that libclang.so gets rebuilt when the linker script changes.
189+
set_property(SOURCE ARCMigrate.cpp APPEND PROPERTY
190+
OBJECT_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/libclang.map)
191+
192+
set_target_properties(libclang PROPERTIES
193+
VERSION ${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}${LLVM_VERSION_SUFFIX}
194+
SOVERSION ${LIBCLANG_SOVERSION})
195+
endif()
148196
endif()
149197

150198
if(INTERNAL_INSTALL_PREFIX)

0 commit comments

Comments
 (0)