[llvm] r300496 - Add a linker script to version LLVM symbols
Sylvestre Ledru via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 17 13:51:50 PDT 2017
Author: sylvestre
Date: Mon Apr 17 15:51:50 2017
New Revision: 300496
URL: http://llvm.org/viewvc/llvm-project?rev=300496&view=rev
Log:
Add a linker script to version LLVM symbols
Summary:
This patch adds a very simple linker script to version the lib's symbols
and thus trying to avoid crashes if an application loads two different
LLVM versions (as long as they do not share data between them).
Note that we deliberately *don't* make LLVM_5.0 depend on LLVM_4.0:
they're incompatible and the whole point of this patch is
to tell the linker that.
Avoid unexpected crashes when two LLVM versions are used in the same process.
Author: Rebecca N. Palmer <rebecca_palmer at zoho.com>
Author: Lisandro Damían Nicanor Pérez Meyer <lisandro at debian.org>
Author: Sylvestre Ledru <sylvestre at debian.org>
Bug-Debian: https://bugs.debian.org/848368
Reviewers: beanz, rnk
Reviewed By: rnk
Subscribers: mgorny, llvm-commits
Differential Revision: https://reviews.llvm.org/D31524
Added:
llvm/trunk/tools/llvm-shlib/simple_version_script.map.in
Modified:
llvm/trunk/cmake/modules/AddLLVM.cmake
llvm/trunk/tools/llvm-shlib/CMakeLists.txt
Modified: llvm/trunk/cmake/modules/AddLLVM.cmake
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/cmake/modules/AddLLVM.cmake?rev=300496&r1=300495&r2=300496&view=diff
==============================================================================
--- llvm/trunk/cmake/modules/AddLLVM.cmake (original)
+++ llvm/trunk/cmake/modules/AddLLVM.cmake Mon Apr 17 15:51:50 2017
@@ -81,8 +81,9 @@ function(add_llvm_symbol_exports target_
# Gold and BFD ld require a version script rather than a plain list.
set(native_export_file "${target_name}.exports")
# FIXME: Don't write the "local:" line on OpenBSD.
+ # in the export file, also add a linker script to version LLVM symbols (form: LLVM_N.M)
add_custom_command(OUTPUT ${native_export_file}
- COMMAND echo "{" > ${native_export_file}
+ COMMAND echo "LLVM_${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR} {" > ${native_export_file}
COMMAND grep -q "[[:alnum:]]" ${export_file} && echo " global:" >> ${native_export_file} || :
COMMAND sed -e "s/$/;/" -e "s/^/ /" < ${export_file} >> ${native_export_file}
COMMAND echo " local: *;" >> ${native_export_file}
Modified: llvm/trunk/tools/llvm-shlib/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-shlib/CMakeLists.txt?rev=300496&r1=300495&r2=300496&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-shlib/CMakeLists.txt (original)
+++ llvm/trunk/tools/llvm-shlib/CMakeLists.txt Mon Apr 17 15:51:50 2017
@@ -38,8 +38,12 @@ add_llvm_library(LLVM SHARED DISABLE_LLV
list(REMOVE_DUPLICATES LIB_NAMES)
if(("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") OR (MINGW) OR ("${CMAKE_SYSTEM_NAME}" STREQUAL "FreeBSD") OR ("${CMAKE_SYSTEM_NAME}" STREQUAL "DragonFly")) # FIXME: It should be "GNU ld for elf"
+ configure_file(
+ ${CMAKE_CURRENT_SOURCE_DIR}/simple_version_script.map.in
+ ${LLVM_LIBRARY_DIR}/tools/llvm-shlib/simple_version_script.map)
+
# GNU ld doesn't resolve symbols in the version script.
- set(LIB_NAMES -Wl,--whole-archive ${LIB_NAMES} -Wl,--no-whole-archive)
+ set(LIB_NAMES -Wl,--version-script,${LLVM_LIBRARY_DIR}/tools/llvm-shlib/simple_version_script.map -Wl,--whole-archive ${LIB_NAMES} -Wl,--no-whole-archive)
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
set(LIB_NAMES -Wl,-all_load ${LIB_NAMES})
endif()
Added: llvm/trunk/tools/llvm-shlib/simple_version_script.map.in
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-shlib/simple_version_script.map.in?rev=300496&view=auto
==============================================================================
--- llvm/trunk/tools/llvm-shlib/simple_version_script.map.in (added)
+++ llvm/trunk/tools/llvm-shlib/simple_version_script.map.in Mon Apr 17 15:51:50 2017
@@ -0,0 +1 @@
+LLVM_ at LLVM_VERSION_MAJOR@. at LLVM_VERSION_MINOR@ { global: *; };
More information about the llvm-commits
mailing list