Skip to content

Commit 7b0fbc8

Browse files
authored
Merge pull request #113513 from am11/feature/vendor/llvm-libunwind
Update llvm-libunwind to 20.1.0
2 parents 4ca1691 + a205551 commit 7b0fbc8

39 files changed

+612
-293
lines changed

src/coreclr/nativeaot/Runtime/unix/UnwindHelpers.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ struct Registers_REGDISPLAY : REGDISPLAY
175175
inline bool validFloatRegister(int) { return false; }
176176
inline bool validVectorRegister(int) { return false; }
177177

178-
inline static int lastDwarfRegNum() { return 16; }
178+
static constexpr int lastDwarfRegNum() { return 16; }
179179

180180
inline bool validRegister(int regNum) const
181181
{
@@ -297,7 +297,7 @@ struct Registers_REGDISPLAY : REGDISPLAY
297297
inline bool validFloatRegister(int) { return false; }
298298
inline bool validVectorRegister(int) { return false; }
299299

300-
inline static int lastDwarfRegNum() { return 16; }
300+
static constexpr int lastDwarfRegNum() { return 16; }
301301

302302
inline bool validRegister(int regNum) const
303303
{
@@ -336,7 +336,7 @@ struct Registers_REGDISPLAY : REGDISPLAY
336336
struct Registers_REGDISPLAY : REGDISPLAY
337337
{
338338
inline static int getArch() { return libunwind::REGISTERS_ARM; }
339-
inline static int lastDwarfRegNum() { return _LIBUNWIND_HIGHEST_DWARF_REGISTER_ARM; }
339+
static constexpr int lastDwarfRegNum() { return _LIBUNWIND_HIGHEST_DWARF_REGISTER_ARM; }
340340

341341
bool validRegister(int num) const;
342342
bool validFloatRegister(int num) const;
@@ -533,7 +533,7 @@ void Registers_REGDISPLAY::setFloatRegister(int num, double value)
533533
struct Registers_REGDISPLAY : REGDISPLAY
534534
{
535535
inline static int getArch() { return libunwind::REGISTERS_ARM64; }
536-
inline static int lastDwarfRegNum() { return _LIBUNWIND_HIGHEST_DWARF_REGISTER_ARM64; }
536+
static constexpr int lastDwarfRegNum() { return _LIBUNWIND_HIGHEST_DWARF_REGISTER_ARM64; }
537537

538538
bool validRegister(int num) const;
539539
bool validFloatRegister(int num) { return false; };
@@ -816,7 +816,7 @@ void Registers_REGDISPLAY::setVectorRegister(int num, libunwind::v128 value)
816816
struct Registers_REGDISPLAY : REGDISPLAY
817817
{
818818
inline static int getArch() { return libunwind::REGISTERS_LOONGARCH; }
819-
inline static int lastDwarfRegNum() { return _LIBUNWIND_HIGHEST_DWARF_REGISTER_LOONGARCH; }
819+
static constexpr int lastDwarfRegNum() { return _LIBUNWIND_HIGHEST_DWARF_REGISTER_LOONGARCH; }
820820

821821
bool validRegister(int num) const;
822822
bool validFloatRegister(int num) { return false; };
@@ -1096,7 +1096,7 @@ void Registers_REGDISPLAY::setVectorRegister(int num, libunwind::v128 value)
10961096
struct Registers_REGDISPLAY : REGDISPLAY
10971097
{
10981098
inline static int getArch() { return libunwind::REGISTERS_RISCV; }
1099-
inline static int lastDwarfRegNum() { return _LIBUNWIND_HIGHEST_DWARF_REGISTER_RISCV; }
1099+
static constexpr int lastDwarfRegNum() { return _LIBUNWIND_HIGHEST_DWARF_REGISTER_RISCV; }
11001100

11011101
bool validRegister(int num) const;
11021102
bool validFloatRegister(int num) { return false; };
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
v18.1.5
2-
https://github.com/llvm/llvm-project/releases/tag/llvmorg-18.1.5
3-
4-
Apply https://github.com/dotnet/runtime/commit/a53805790a49f5bf52776dc81c1c83ec7f21ebce
1+
v20.1.0
2+
https://github.com/llvm/llvm-project/releases/tag/llvmorg-20.1.0
53

4+
Apply https://github.com/dotnet/runtime/commit/d03d1ba7835fdf9e2a6bb537d49fb5ff6584697b

src/native/external/llvm-libunwind/CMakeLists.txt

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#===============================================================================
44

55
cmake_minimum_required(VERSION 3.20.0)
6+
set(LLVM_SUBPROJECT_TITLE "libunwind")
67

78
set(LLVM_COMMON_CMAKE_UTILS "${CMAKE_CURRENT_SOURCE_DIR}/../cmake")
89

@@ -23,19 +24,20 @@ set(LIBUNWIND_LIBCXX_PATH "${CMAKE_CURRENT_LIST_DIR}/../libcxx" CACHE PATH
2324
include(GNUInstallDirs)
2425
include(CheckSymbolExists)
2526

27+
if (MSVC)
28+
message(FATAL_ERROR "Libunwind doesn't build for MSVC targets, and that is almost certainly not what you want to do "
29+
"anyway since libunwind is tied to the Itanium C++ ABI, and MSVC targets must use the MS C++ ABI.")
30+
endif()
31+
2632
#===============================================================================
2733
# Setup CMake Options
2834
#===============================================================================
2935
include(CMakeDependentOption)
3036
include(HandleCompilerRT)
3137

3238
# Define options.
33-
option(LIBUNWIND_BUILD_32_BITS "Build 32 bit multilib libunwind. This option is not supported anymore when building the runtimes. Please specify a full triple instead." ${LLVM_BUILD_32_BITS})
34-
if (LIBUNWIND_BUILD_32_BITS)
35-
message(FATAL_ERROR "LIBUNWIND_BUILD_32_BITS is not supported anymore when building the runtimes, please specify a full triple instead.")
36-
endif()
37-
3839
option(LIBUNWIND_ENABLE_CET "Build libunwind with CET enabled." OFF)
40+
option(LIBUNWIND_ENABLE_GCS "Build libunwind with GCS enabled." OFF)
3941
option(LIBUNWIND_ENABLE_ASSERTIONS "Enable assertions independent of build mode." ON)
4042
option(LIBUNWIND_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
4143
option(LIBUNWIND_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
@@ -64,8 +66,18 @@ cmake_dependent_option(LIBUNWIND_INSTALL_SHARED_LIBRARY
6466
"Install the shared libunwind library." ON
6567
"LIBUNWIND_ENABLE_SHARED;LIBUNWIND_INSTALL_LIBRARY" OFF)
6668

69+
set(LIBUNWIND_LIBRARY_VERSION "1.0" CACHE STRING
70+
"Version of libunwind. This will be reflected in the name of the shared library produced.
71+
For example, -DLIBUNWIND_LIBRARY_VERSION=x.y will result in the library being named
72+
libunwind.x.y.dylib, along with the usual symlinks pointing to that. On Apple platforms,
73+
this also controls the linker's 'current_version' property.")
74+
6775
if(MINGW)
68-
set(LIBUNWIND_DEFAULT_TEST_CONFIG "llvm-libunwind-mingw.cfg.in")
76+
if (LIBUNWIND_ENABLE_SHARED)
77+
set(LIBUNWIND_DEFAULT_TEST_CONFIG "llvm-libunwind-shared-mingw.cfg.in")
78+
else()
79+
set(LIBUNWIND_DEFAULT_TEST_CONFIG "llvm-libunwind-static-mingw.cfg.in")
80+
endif()
6981
elseif (LIBUNWIND_ENABLE_SHARED)
7082
set(LIBUNWIND_DEFAULT_TEST_CONFIG "llvm-libunwind-shared.cfg.in")
7183
else()
@@ -129,13 +141,14 @@ set(LIBUNWIND_SHARED_OUTPUT_NAME "unwind" CACHE STRING "Output name for the shar
129141
set(LIBUNWIND_STATIC_OUTPUT_NAME "unwind" CACHE STRING "Output name for the static libunwind runtime library.")
130142

131143
if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
132-
set(LIBUNWIND_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE})
133-
set(LIBUNWIND_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE STRING
134-
"Path where built libunwind libraries should be installed.")
135-
if(LIBCXX_LIBDIR_SUBDIR)
136-
string(APPEND LIBUNWIND_LIBRARY_DIR /${LIBUNWIND_LIBDIR_SUBDIR})
137-
string(APPEND LIBUNWIND_INSTALL_LIBRARY_DIR /${LIBUNWIND_LIBDIR_SUBDIR})
144+
set(LIBUNWIND_TARGET_SUBDIR ${LLVM_DEFAULT_TARGET_TRIPLE})
145+
if(LIBUNWIND_LIBDIR_SUBDIR)
146+
string(APPEND LIBUNWIND_TARGET_SUBDIR /${LIBUNWIND_LIBDIR_SUBDIR})
138147
endif()
148+
set(LIBUNWIND_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LIBUNWIND_TARGET_SUBDIR})
149+
set(LIBUNWIND_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LIBUNWIND_TARGET_SUBDIR} CACHE STRING
150+
"Path where built libunwind libraries should be installed.")
151+
unset(LIBUNWIND_TARGET_SUBDIR)
139152
else()
140153
if(LLVM_LIBRARY_OUTPUT_INTDIR)
141154
set(LIBUNWIND_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
@@ -154,8 +167,7 @@ set(LIBUNWIND_C_FLAGS "")
154167
set(LIBUNWIND_CXX_FLAGS "")
155168
set(LIBUNWIND_COMPILE_FLAGS "")
156169
set(LIBUNWIND_LINK_FLAGS "")
157-
set(LIBUNWIND_ADDITIONAL_COMPILE_FLAGS "" CACHE STRING
158-
"Additional Compile only flags which can be provided in cache")
170+
set(LIBUNWIND_ADDITIONAL_COMPILE_FLAGS "" CACHE STRING "See documentation for LIBCXX_ADDITIONAL_COMPILE_FLAGS")
159171
set(LIBUNWIND_ADDITIONAL_LIBRARIES "" CACHE STRING
160172
"Additional libraries libunwind is linked to which can be provided in cache")
161173

@@ -186,6 +198,13 @@ if (LIBUNWIND_ENABLE_CET)
186198
endif()
187199
endif()
188200

201+
if (LIBUNWIND_ENABLE_GCS)
202+
add_compile_flags_if_supported(-mbranch-protection=standard)
203+
if (NOT CXX_SUPPORTS_MBRANCH_PROTECTION_EQ_STANDARD_FLAG)
204+
message(SEND_ERROR "Compiler doesn't support GCS -mbranch-protection option!")
205+
endif()
206+
endif()
207+
189208
if (WIN32)
190209
# The headers lack matching dllexport attributes (_LIBUNWIND_EXPORT);
191210
# silence the warning instead of cluttering the headers (which aren't

src/native/external/llvm-libunwind/docs/BuildingLibunwind.rst

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ On Mac OS, the easiest way to get this library is to link with -lSystem.
1616
However if you want to build tip-of-trunk from here (getting the bleeding
1717
edge), read on.
1818

19-
The basic steps needed to build libc++ are:
19+
The basic steps needed to build libunwind are:
2020

2121
#. Checkout LLVM, libunwind, and related projects:
2222

@@ -50,23 +50,6 @@ The basic steps needed to build libc++ are:
5050
* ``make install-unwind`` --- Will install the libraries and the headers
5151

5252

53-
It is sometimes beneficial to build outside of the LLVM tree. An out-of-tree
54-
build would look like this:
55-
56-
.. code-block:: bash
57-
58-
$ cd where-you-want-libunwind-to-live
59-
$ # Check out llvm, and libunwind
60-
$ ``svn co https://llvm.org/svn/llvm-project/llvm/trunk llvm``
61-
$ ``svn co https://llvm.org/svn/llvm-project/libunwind/trunk libunwind``
62-
$ cd where-you-want-to-build
63-
$ mkdir build && cd build
64-
$ export CC=clang CXX=clang++
65-
$ cmake -DLLVM_PATH=path/to/llvm \
66-
path/to/libunwind
67-
$ make
68-
69-
7053
.. _CMake Options:
7154

7255
CMake Options

src/native/external/llvm-libunwind/docs/index.rst

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,13 @@ and `Getting started with LLVM <https://llvm.org/docs/GettingStarted.html>`__.
7878

7979
If you think you've found a bug in libunwind, please report it using
8080
the `LLVM bug tracker`_. If you're not sure, you
81-
can ask for support on the `Runtimes forum`_ or on IRC.
81+
can ask for support on the `Runtimes forum`_ or on Discord.
8282
Please use the tag "libunwind" for new threads.
8383

8484
**Patches**
8585

86-
If you want to contribute a patch to libunwind, the best place for that is
87-
`Phabricator <https://llvm.org/docs/Phabricator.html>`_. Please include [libunwind] in the subject and
88-
add `cfe-commits` as a subscriber. Also make sure you are subscribed to the `cfe-commits mailing list`_.
86+
If you want to contribute a patch to libunwind, please start by reading the LLVM
87+
`documentation about contributing <https://www.llvm.org/docs/Contributing.html>`__.
8988

9089
**Discussion and Questions**
9190

src/native/external/llvm-libunwind/include/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ set(files
33
libunwind.h
44
libunwind.modulemap
55
mach-o/compact_unwind_encoding.h
6-
mach-o/compact_unwind_encoding.modulemap
76
unwind_arm_ehabi.h
87
unwind_itanium.h
98
unwind.h

src/native/external/llvm-libunwind/include/__libunwind_config.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@
5353
# else
5454
# define _LIBUNWIND_CURSOR_SIZE 66
5555
# endif
56+
# elif defined(__ILP32__)
57+
# define _LIBUNWIND_CONTEXT_SIZE 21
58+
# define _LIBUNWIND_CURSOR_SIZE 28
5659
# else
5760
# define _LIBUNWIND_CONTEXT_SIZE 38
5861
# define _LIBUNWIND_CURSOR_SIZE 50
@@ -185,6 +188,10 @@
185188
#endif
186189
#define _LIBUNWIND_HIGHEST_DWARF_REGISTER \
187190
_LIBUNWIND_HIGHEST_DWARF_REGISTER_LOONGARCH
191+
#elif defined(__wasm__)
192+
// Unused
193+
#define _LIBUNWIND_CONTEXT_SIZE 0
194+
#define _LIBUNWIND_CURSOR_SIZE 0
188195
# else
189196
# error "Unsupported architecture."
190197
# endif

src/native/external/llvm-libunwind/include/mach-o/compact_unwind_encoding.modulemap

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/native/external/llvm-libunwind/src/CMakeLists.txt

Lines changed: 50 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ set(LIBUNWIND_C_SOURCES
2020
)
2121
set_source_files_properties(${LIBUNWIND_C_SOURCES}
2222
PROPERTIES
23-
COMPILE_FLAGS "-std=c99")
23+
# We need to set `-fexceptions` here so that key
24+
# unwinding functions, like
25+
# _UNWIND_RaiseException, are not marked as
26+
# `nounwind`, which breaks LTO builds of
27+
# libunwind. See #56825 and #120657 for context.
28+
COMPILE_FLAGS "-std=c99 -fexceptions")
2429

2530
set(LIBUNWIND_ASM_SOURCES
2631
UnwindRegistersRestore.S
@@ -105,15 +110,6 @@ if (LIBUNWIND_ENABLE_SHARED AND
105110
"on C++ ABI library is not supported.")
106111
endif()
107112

108-
if (APPLE)
109-
add_compile_flags("-U__STRICT_ANSI__")
110-
add_link_flags("-compatibility_version 1" "-install_name /usr/lib/libunwind.1.dylib")
111-
112-
if (CMAKE_OSX_DEPLOYMENT_TARGET STREQUAL "10.6")
113-
add_link_flags("-current_version ${LIBUNWIND_VERSION}" "/usr/lib/libSystem.B.dylib")
114-
endif ()
115-
endif ()
116-
117113
if (HAIKU)
118114
add_library_flags_if(LIBUNWIND_HAS_ROOT_LIB root)
119115

@@ -122,6 +118,22 @@ if (HAIKU)
122118

123119
add_compile_flags("-D_DEFAULT_SOURCE")
124120
add_compile_flags("-DPT_GNU_EH_FRAME=PT_EH_FRAME")
121+
122+
find_path(LIBUNWIND_HAIKU_PRIVATE_HEADERS
123+
"commpage_defs.h"
124+
PATHS ${CMAKE_SYSTEM_INCLUDE_PATH}
125+
PATH_SUFFIXES "/private/system"
126+
NO_DEFAULT_PATH
127+
REQUIRED)
128+
129+
include_directories(SYSTEM "${LIBUNWIND_HAIKU_PRIVATE_HEADERS}")
130+
if (LIBUNWIND_TARGET_TRIPLE)
131+
if (${LIBUNWIND_TARGET_TRIPLE} MATCHES "^x86_64")
132+
include_directories(SYSTEM "${LIBUNWIND_HAIKU_PRIVATE_HEADERS}/arch/x86_64")
133+
endif()
134+
else()
135+
include_directories(SYSTEM "${LIBUNWIND_HAIKU_PRIVATE_HEADERS}/arch/${CMAKE_SYSTEM_PROCESSOR}")
136+
endif()
125137
endif ()
126138

127139
string(REPLACE ";" " " LIBUNWIND_COMPILE_FLAGS "${LIBUNWIND_COMPILE_FLAGS}")
@@ -162,22 +174,23 @@ if (CMAKE_POSITION_INDEPENDENT_CODE OR NOT DEFINED CMAKE_POSITION_INDEPENDENT_CO
162174
set_target_properties(unwind_shared_objects PROPERTIES POSITION_INDEPENDENT_CODE ON) # must set manually because it's an object library
163175
endif()
164176

165-
if (LIBUNWIND_ENABLE_SHARED)
166-
add_library(unwind_shared SHARED)
167-
target_link_libraries(unwind_shared PUBLIC unwind_shared_objects)
168-
set_target_properties(unwind_shared
169-
PROPERTIES
170-
LINK_FLAGS "${LIBUNWIND_LINK_FLAGS}"
171-
LINKER_LANGUAGE C
172-
OUTPUT_NAME "${LIBUNWIND_SHARED_OUTPUT_NAME}"
173-
VERSION "1.0"
174-
SOVERSION "1"
175-
)
177+
add_library(unwind_shared SHARED)
178+
target_link_libraries(unwind_shared PUBLIC unwind_shared_objects)
179+
set_target_properties(unwind_shared
180+
PROPERTIES
181+
EXCLUDE_FROM_ALL "$<IF:$<BOOL:${LIBUNWIND_ENABLE_SHARED}>,FALSE,TRUE>"
182+
LINK_FLAGS "${LIBUNWIND_LINK_FLAGS}"
183+
LINKER_LANGUAGE C
184+
OUTPUT_NAME "${LIBUNWIND_SHARED_OUTPUT_NAME}"
185+
VERSION "${LIBUNWIND_LIBRARY_VERSION}"
186+
SOVERSION "1"
187+
)
176188

189+
if (LIBUNWIND_ENABLE_SHARED)
177190
list(APPEND LIBUNWIND_BUILD_TARGETS "unwind_shared")
178-
if (LIBUNWIND_INSTALL_SHARED_LIBRARY)
179-
list(APPEND LIBUNWIND_INSTALL_TARGETS "unwind_shared")
180-
endif()
191+
endif()
192+
if (LIBUNWIND_INSTALL_SHARED_LIBRARY)
193+
list(APPEND LIBUNWIND_INSTALL_TARGETS "unwind_shared")
181194
endif()
182195

183196
# Build the static library.
@@ -208,20 +221,21 @@ if(LIBUNWIND_HIDE_SYMBOLS)
208221
target_compile_definitions(unwind_static_objects PRIVATE _LIBUNWIND_HIDE_SYMBOLS)
209222
endif()
210223

211-
if (LIBUNWIND_ENABLE_STATIC)
212-
add_library(unwind_static STATIC)
213-
target_link_libraries(unwind_static PUBLIC unwind_static_objects)
214-
set_target_properties(unwind_static
215-
PROPERTIES
216-
LINK_FLAGS "${LIBUNWIND_LINK_FLAGS}"
217-
LINKER_LANGUAGE C
218-
OUTPUT_NAME "${LIBUNWIND_STATIC_OUTPUT_NAME}"
219-
)
224+
add_library(unwind_static STATIC)
225+
target_link_libraries(unwind_static PUBLIC unwind_static_objects)
226+
set_target_properties(unwind_static
227+
PROPERTIES
228+
EXCLUDE_FROM_ALL "$<IF:$<BOOL:${LIBUNWIND_ENABLE_STATIC}>,FALSE,TRUE>"
229+
LINK_FLAGS "${LIBUNWIND_LINK_FLAGS}"
230+
LINKER_LANGUAGE C
231+
OUTPUT_NAME "${LIBUNWIND_STATIC_OUTPUT_NAME}"
232+
)
220233

234+
if (LIBUNWIND_ENABLE_STATIC)
221235
list(APPEND LIBUNWIND_BUILD_TARGETS "unwind_static")
222-
if (LIBUNWIND_INSTALL_STATIC_LIBRARY)
223-
list(APPEND LIBUNWIND_INSTALL_TARGETS "unwind_static")
224-
endif()
236+
endif()
237+
if (LIBUNWIND_INSTALL_STATIC_LIBRARY)
238+
list(APPEND LIBUNWIND_INSTALL_TARGETS "unwind_static")
225239
endif()
226240

227241
# Add a meta-target for both libraries.

0 commit comments

Comments
 (0)