Skip to content

Commit 86ca591

Browse files
authored
Merge pull request #25597 from JuliaLang/vc/symprefix
Add symbol versioning to libLLVM.so
2 parents c4b21ca + 9803708 commit 86ca591

File tree

3 files changed

+107
-0
lines changed

3 files changed

+107
-0
lines changed

deps/llvm.mk

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,7 @@ $(eval $(call LLVM_PATCH,llvm-D33179))
461461
$(eval $(call LLVM_PATCH,llvm-PR29010-i386-xmm)) # Remove for 4.0
462462
$(eval $(call LLVM_PATCH,llvm-3.9.0-D37576-NVPTX-sm_70)) # NVPTX, Remove for 6.0
463463
$(eval $(call LLVM_PATCH,llvm-D37939-Mem2Reg-Also-handle-memcpy))
464+
$(eval $(call LLVM_PATCH,llvm-D31524-sovers_4.0)) # Remove for 4.0
464465
ifeq ($(BUILD_LLVM_CLANG),1)
465466
$(eval $(call LLVM_PATCH,compiler_rt-3.9-glibc_2.25.90)) # Remove for 5.0
466467
endif
@@ -507,6 +508,11 @@ $(eval $(call LLVM_PATCH,llvm-3.9-osx-10.12))
507508
endif
508509
endif
509510

511+
# Independent to the llvm version add a JL prefix to the version map
512+
# Depends on `llvm-D31524-sovers_4.0` for LLVM_VER==3.9
513+
$(eval $(call LLVM_PATCH,llvm-symver-jlprefix)) # DO NOT REMOVE
514+
515+
510516
$(LLVM_BUILDDIR_withtype)/build-configured: $(LLVM_PATCH_PREV)
511517

512518
$(LLVM_BUILDDIR_withtype)/build-configured: $(LLVM_SRC_DIR)/source-extracted | $(llvm_python_workaround) $(LIBCXX_DEPENDENCY)
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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: *; };
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
From f23277bb91a4925ba8763337137a3123a7600557 Mon Sep 17 00:00:00 2001
2+
From: Valentin Churavy <[email protected]>
3+
Date: Tue, 16 Jan 2018 17:29:05 -0500
4+
Subject: [PATCH] add JL prefix to all LLVM version suffixes
5+
6+
---
7+
tools/llvm-shlib/simple_version_script.map.in | 2 +-
8+
1 file changed, 1 insertion(+), 1 deletion(-)
9+
10+
diff --git a/tools/llvm-shlib/simple_version_script.map.in b/tools/llvm-shlib/simple_version_script.map.in
11+
index e9515fe7862..af082581627 100644
12+
--- a/tools/llvm-shlib/simple_version_script.map.in
13+
+++ b/tools/llvm-shlib/simple_version_script.map.in
14+
@@ -1 +1 @@
15+
-LLVM_@LLVM_VERSION_MAJOR@.@LLVM_VERSION_MINOR@ { global: *; };
16+
+JL_LLVM_@LLVM_VERSION_MAJOR@.@LLVM_VERSION_MINOR@ { global: *; };
17+
--
18+
2.15.1
19+

0 commit comments

Comments
 (0)