Skip to content

Commit

Permalink
libclang.so: Make SONAME independent from LLVM version
Browse files Browse the repository at this point in the history
Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D105527
  • Loading branch information
tstellar committed Jul 26, 2021
1 parent 97e95fe commit c7b3a91
Show file tree
Hide file tree
Showing 8 changed files with 463 additions and 394 deletions.
1 change: 1 addition & 0 deletions clang/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ configure_lit_site_cfg(
"CLANG_BINARY_DIR"
"CLANG_SOURCE_DIR"
"CLANG_TOOLS_DIR"
"CMAKE_LIBRARY_OUTPUT_DIRECTORY"
)

configure_lit_site_cfg(
Expand Down
2 changes: 2 additions & 0 deletions clang/test/LibClang/lit.local.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
config.substitutions.append(('%libclang', os.path.join(config.clang_lib_dir, 'libclang.so')))
config.pipefail = False
6 changes: 6 additions & 0 deletions clang/test/LibClang/symbols.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Check that there are no unversioned clang symbols in libclang.so
RUN: llvm-nm -Dj --defined-only %libclang | grep -v -e '@@LLVM_[0-9]\+$' | not grep '^clang'

# Check that here are no local clang_ symbols (ignoring symbols with .cold or
# .localalias suffxies.)
RUN: llvm-nm %libclang | not grep '[a-z] clang_[^.]\+$'
1 change: 1 addition & 0 deletions clang/test/lit.site.cfg.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ config.clang_lit_site_cfg = __file__
config.clang_obj_root = path(r"@CLANG_BINARY_DIR@")
config.clang_src_dir = path(r"@CLANG_SOURCE_DIR@")
config.clang_tools_dir = path(r"@CLANG_TOOLS_DIR@")
config.clang_lib_dir = path(r"@CMAKE_LIBRARY_OUTPUT_DIRECTORY@")
config.host_triple = "@LLVM_HOST_TRIPLE@"
config.target_triple = "@TARGET_TRIPLE@"
config.host_cc = "@CMAKE_C_COMPILER@"
Expand Down
28 changes: 28 additions & 0 deletions clang/tools/libclang/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ option(LIBCLANG_BUILD_STATIC
"Build libclang as a static library (in addition to a shared one)" OFF)

set(LLVM_EXPORTED_SYMBOL_FILE ${CMAKE_CURRENT_SOURCE_DIR}/libclang.exports)
set(LIBCLANG_VERSION_SCRIPT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/libclang.map)

if(MSVC)
# Avoid LNK4197 by not specifying libclang.exports here.
Expand All @@ -73,6 +74,20 @@ if(MSVC)
set(LLVM_EXPORTED_SYMBOL_FILE)
endif()

if (UNIX AND NOT APPLE)
set(LLVM_EXPORTED_SYMBOL_FILE)
set(USE_VERSION_SCRIPT TRUE)
endif()

if (LLVM_EXPORTED_SYMBOL_FILE)
add_custom_command(OUTPUT ${LLVM_EXPORTED_SYMBOL_FILE}
COMMAND "${Python3_EXECUTABLE}"
ARGS ${CMAKE_CURRENT_SOURCE_DIR}/linker-script-to-export-list.py
${LIBCLANG_VERSION_SCRIPT_FILE}
${LLVM_EXPORTED_SYMBOL_FILE}
DEPENDS ${LIBCLANG_VERSION_SCRIPT_FILE})
endif()

if(LLVM_ENABLE_PIC OR (WIN32 AND NOT LIBCLANG_BUILD_STATIC))
set(ENABLE_SHARED SHARED)
endif()
Expand Down Expand Up @@ -145,6 +160,19 @@ if(ENABLE_SHARED)
)
endif()
endif()
if (USE_VERSION_SCRIPT)
target_link_options(libclang PRIVATE "-Wl,--version-script,${CMAKE_CURRENT_SOURCE_DIR}/libclang.map")
# Ensure that libclang.so gets rebuilt when the linker script changes.
set_property(SOURCE ARCMigrate.cpp APPEND PROPERTY
OBJECT_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/libclang.map)

# The SOVERSION should be updated only if a change is made to the libclang
# ABI, and when it is updated, it should be updated to the current
# LLVM_VERSION_MAJOR.
set_target_properties(libclang PROPERTIES
VERSION ${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}${LLVM_VERSION_SUFFIX}
SOVERSION 13)
endif()
endif()

if(INTERNAL_INSTALL_PREFIX)
Expand Down
Loading

0 comments on commit c7b3a91

Please sign in to comment.