Skip to content

Commit edabf42

Browse files
ihnortonvchuravy
authored andcommitted
Backport symbol versioning patch from LLVM 4.0
Should help with crashes when loading multiple libLLVM versions in the same process, as happens with mesa/llvmpipe when mesa is dynamically linked against libLLVM. See #19606 patch: https://reviews.llvm.org/D31524 commit: https://reviews.llvm.org/rL300496
1 parent aea9155 commit edabf42

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed

deps/llvm.mk

Lines changed: 1 addition & 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
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 <sylvestre@debian.org>
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 <rebecca_palmer@zoho.com>
22+
Author: Lisandro Damían Nicanor Pérez Meyer <lisandro@debian.org>
23+
Author: Sylvestre Ledru <sylvestre@debian.org>
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

Comments
 (0)