|
| 1 | +From cd789d8cfe12aa374e66eafc748f4fc06e149ca7 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Sylvestre Ledru < [email protected]> |
| 3 | +Date: Mon, 17 Apr 2017 20:51:50 +0000 |
| 4 | +Subject: [PATCH] Add a linker script to version LLVM symbols |
| 5 | +MIME-Version: 1.0 |
| 6 | +Content-Type: text/plain; charset=UTF-8 |
| 7 | +Content-Transfer-Encoding: 8bit |
| 8 | + |
| 9 | +Summary: |
| 10 | +This patch adds a very simple linker script to version the lib's symbols |
| 11 | +and thus trying to avoid crashes if an application loads two different |
| 12 | +LLVM versions (as long as they do not share data between them). |
| 13 | + |
| 14 | +Note that we deliberately *don't* make LLVM_5.0 depend on LLVM_4.0: |
| 15 | +they're incompatible and the whole point of this patch is |
| 16 | +to tell the linker that. |
| 17 | + |
| 18 | + |
| 19 | +Avoid unexpected crashes when two LLVM versions are used in the same process. |
| 20 | + |
| 21 | +Author: Rebecca N. Palmer < [email protected]> |
| 22 | +Author: Lisandro Damían Nicanor Pérez Meyer < [email protected]> |
| 23 | +Author: Sylvestre Ledru < [email protected]> |
| 24 | +Bug-Debian: https://bugs.debian.org/848368 |
| 25 | + |
| 26 | + |
| 27 | +Reviewers: beanz, rnk |
| 28 | + |
| 29 | +Reviewed By: rnk |
| 30 | + |
| 31 | +Subscribers: mgorny, llvm-commits |
| 32 | + |
| 33 | +Differential Revision: https://reviews.llvm.org/D31524 |
| 34 | + |
| 35 | +git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@300496 91177308-0d34-0410-b5e6-96231b3b80d8 |
| 36 | +--- |
| 37 | + cmake/modules/AddLLVM.cmake | 3 ++- |
| 38 | + tools/llvm-shlib/CMakeLists.txt | 6 +++++- |
| 39 | + tools/llvm-shlib/simple_version_script.map.in | 1 + |
| 40 | + 3 files changed, 8 insertions(+), 2 deletions(-) |
| 41 | + create mode 100644 tools/llvm-shlib/simple_version_script.map.in |
| 42 | + |
| 43 | +diff --git a/cmake/modules/AddLLVM.cmake b/cmake/modules/AddLLVM.cmake |
| 44 | +index 7f7608cff33..e011bb40275 100644 |
| 45 | +--- a/cmake/modules/AddLLVM.cmake |
| 46 | ++++ b/cmake/modules/AddLLVM.cmake |
| 47 | +@@ -81,8 +81,9 @@ function(add_llvm_symbol_exports target_name export_file) |
| 48 | + # Gold and BFD ld require a version script rather than a plain list. |
| 49 | + set(native_export_file "${target_name}.exports") |
| 50 | + # FIXME: Don't write the "local:" line on OpenBSD. |
| 51 | ++ # in the export file, also add a linker script to version LLVM symbols (form: LLVM_N.M) |
| 52 | + add_custom_command(OUTPUT ${native_export_file} |
| 53 | +- COMMAND echo "{" > ${native_export_file} |
| 54 | ++ COMMAND echo "LLVM_${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR} {" > ${native_export_file} |
| 55 | + COMMAND grep -q "[[:alnum:]]" ${export_file} && echo " global:" >> ${native_export_file} || : |
| 56 | + COMMAND sed -e "s/$/;/" -e "s/^/ /" < ${export_file} >> ${native_export_file} |
| 57 | + COMMAND echo " local: *;" >> ${native_export_file} |
| 58 | +diff --git a/tools/llvm-shlib/CMakeLists.txt b/tools/llvm-shlib/CMakeLists.txt |
| 59 | +index c68a2b0e60e..27815868629 100644 |
| 60 | +--- a/tools/llvm-shlib/CMakeLists.txt |
| 61 | ++++ b/tools/llvm-shlib/CMakeLists.txt |
| 62 | +@@ -38,8 +38,12 @@ add_llvm_library(LLVM SHARED DISABLE_LLVM_LINK_LLVM_DYLIB SONAME ${SOURCES}) |
| 63 | + |
| 64 | + list(REMOVE_DUPLICATES LIB_NAMES) |
| 65 | + 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" |
| 66 | ++ configure_file( |
| 67 | ++ ${CMAKE_CURRENT_SOURCE_DIR}/simple_version_script.map.in |
| 68 | ++ ${LLVM_LIBRARY_DIR}/tools/llvm-shlib/simple_version_script.map) |
| 69 | ++ |
| 70 | + # GNU ld doesn't resolve symbols in the version script. |
| 71 | +- set(LIB_NAMES -Wl,--whole-archive ${LIB_NAMES} -Wl,--no-whole-archive) |
| 72 | ++ 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) |
| 73 | + elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin") |
| 74 | + set(LIB_NAMES -Wl,-all_load ${LIB_NAMES}) |
| 75 | + endif() |
| 76 | +diff --git a/tools/llvm-shlib/simple_version_script.map.in b/tools/llvm-shlib/simple_version_script.map.in |
| 77 | +new file mode 100644 |
| 78 | +index 00000000000..e9515fe7862 |
| 79 | +--- /dev/null |
| 80 | ++++ b/tools/llvm-shlib/simple_version_script.map.in |
| 81 | +@@ -0,0 +1 @@ |
| 82 | ++LLVM_@LLVM_VERSION_MAJOR@.@LLVM_VERSION_MINOR@ { global: *; }; |
0 commit comments