Skip to content

Commit 02dc75f

Browse files
authored
Update libunwind from LLVM 20.1.8 to 21.1.8 (#26036)
This updates libunwind from 20.1.8 to LLVM 21.1.8: https://github.com/llvm/llvm-project/releases/tag/llvmorg-21.1.8 Additional change: - Add `-Wno-c23-extensions` to libunwind's cflags: 0070206 llvm/llvm-project#125412 removed parameter names to suppress `-Wunused-parameter` in their own build system, but this causes these errors instead for us: ```console ../../../system/lib/libunwind/src/Unwind-wasm.c:105:62: error: omitting the parameter name in a function definition is a C23 extension [-Werror,-Wc23-extensions] 105 | _LIBUNWIND_EXPORT void _Unwind_SetIP(struct _Unwind_Context *, uintptr_t) {} | ``` This suppresses the warnings.
1 parent 1a55610 commit 02dc75f

11 files changed

Lines changed: 387 additions & 118 deletions

ChangeLog.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ See docs/process.md for more on how version tagging works.
2020

2121
4.0.24 (in development)
2222
-----------------------
23-
- compiler-rt was updated to LLVM 21.1.8. (#26405)
23+
- compiler-rt and libunwind were updated to LLVM 21.1.8. (#26036 and #26045)
2424
- A new `-sEXECUTABLE` setting was added which adds a #! line to the resulting
2525
JavaScript and makes it executable. This setting defaults to true when the
2626
output filename has no extension, or ends in `.out` (e.g. `a.out`) (#26085)

system/lib/libunwind/readme.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
LLVM's libunwind
22
----------------
33

4-
These files are from the llvm-project based on release 20.1.8.
4+
These files are from the llvm-project based on release 21.1.8.
55

66
We maintain a local fork of llvm-project that contains any Emscripten
77
specific patches:
88

99
https://github.com/emscripten-core/llvm-project
1010

11-
The current patch is based on the emscripten-libs-20 branch.
11+
The current patch is based on the emscripten-libs-21 branch.
1212

1313
Update Instructions
1414
-------------------
@@ -20,4 +20,4 @@ Modifications
2020

2121
For a list of changes from upstream see the libunwind files that are part of:
2222

23-
https://github.com/llvm/llvm-project/compare/llvmorg-20.1.8...emscripten-core:emscripten-libs-20
23+
https://github.com/llvm/llvm-project/compare/llvmorg-21.1.8...emscripten-core:emscripten-libs-21

system/lib/libunwind/src/Registers.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
#include <stdint.h>
1616
#include <string.h>
1717

18-
#include "cet_unwind.h"
1918
#include "config.h"
2019
#include "libunwind.h"
20+
#include "shadow_stack_unwind.h"
2121

2222
namespace libunwind {
2323

@@ -48,7 +48,7 @@ class _LIBUNWIND_HIDDEN Registers_x86;
4848
extern "C" void __libunwind_Registers_x86_jumpto(Registers_x86 *);
4949

5050
#if defined(_LIBUNWIND_USE_CET)
51-
extern "C" void *__libunwind_cet_get_jump_target() {
51+
extern "C" void *__libunwind_shstk_get_jump_target() {
5252
return reinterpret_cast<void *>(&__libunwind_Registers_x86_jumpto);
5353
}
5454
#endif
@@ -268,7 +268,7 @@ class _LIBUNWIND_HIDDEN Registers_x86_64;
268268
extern "C" void __libunwind_Registers_x86_64_jumpto(Registers_x86_64 *);
269269

270270
#if defined(_LIBUNWIND_USE_CET)
271-
extern "C" void *__libunwind_cet_get_jump_target() {
271+
extern "C" void *__libunwind_shstk_get_jump_target() {
272272
return reinterpret_cast<void *>(&__libunwind_Registers_x86_64_jumpto);
273273
}
274274
#endif
@@ -1817,7 +1817,7 @@ class _LIBUNWIND_HIDDEN Registers_arm64;
18171817
extern "C" void __libunwind_Registers_arm64_jumpto(Registers_arm64 *);
18181818

18191819
#if defined(_LIBUNWIND_USE_GCS)
1820-
extern "C" void *__libunwind_cet_get_jump_target() {
1820+
extern "C" void *__libunwind_shstk_get_jump_target() {
18211821
return reinterpret_cast<void *>(&__libunwind_Registers_arm64_jumpto);
18221822
}
18231823
#endif
@@ -4126,7 +4126,7 @@ inline reg_t Registers_riscv::getRegister(int regNum) const {
41264126
return _registers[regNum];
41274127
if (regNum == UNW_RISCV_VLENB) {
41284128
reg_t vlenb;
4129-
__asm__("csrr %0, 0xC22" : "=r"(vlenb));
4129+
__asm__ volatile("csrr %0, 0xC22" : "=r"(vlenb));
41304130
return vlenb;
41314131
}
41324132
_LIBUNWIND_ABORT("unsupported riscv register");

system/lib/libunwind/src/Unwind-seh.cpp

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,32 @@ static DISPATCHER_CONTEXT *__unw_seh_get_disp_ctx(unw_cursor_t *cursor);
5151
static void __unw_seh_set_disp_ctx(unw_cursor_t *cursor,
5252
DISPATCHER_CONTEXT *disp);
5353

54+
#pragma clang diagnostic push
55+
#pragma clang diagnostic ignored "-Wgnu-anonymous-struct"
56+
// Local redefinition of this type; mingw-w64 headers lack the
57+
// DISPATCHER_CONTEXT_NONVOLREG_ARM64 type as of May 2025, so locally redefine
58+
// it and use that definition, to avoid needing to test/guess whether the real
59+
// type is available of not.
60+
union LOCAL_DISPATCHER_CONTEXT_NONVOLREG_ARM64 {
61+
BYTE Buffer[11 * sizeof(DWORD64) + 8 * sizeof(double)];
62+
63+
struct {
64+
DWORD64 GpNvRegs[11];
65+
double FpNvRegs[8];
66+
};
67+
};
68+
69+
// Custom data type definition; this type is not defined in WinSDK.
70+
union LOCAL_DISPATCHER_CONTEXT_NONVOLREG_ARM {
71+
BYTE Buffer[8 * sizeof(DWORD) + 8 * sizeof(double)];
72+
73+
struct {
74+
DWORD GpNvRegs[8];
75+
double FpNvRegs[8];
76+
};
77+
};
78+
#pragma clang diagnostic pop
79+
5480
/// Common implementation of SEH-style handler functions used by Itanium-
5581
/// style frames. Depending on how and why it was called, it may do one of:
5682
/// a) Delegate to the given Itanium-style personality function; or
@@ -148,7 +174,8 @@ _GCC_specific_handler(PEXCEPTION_RECORD ms_exc, PVOID frame, PCONTEXT ms_ctx,
148174
}
149175
// FIXME: Indicate target frame in foreign case!
150176
// phase 2: the clean up phase
151-
RtlUnwindEx(frame, (PVOID)disp->ControlPc, ms_exc, exc, ms_ctx, disp->HistoryTable);
177+
RtlUnwindEx(frame, (PVOID)disp->ControlPc, ms_exc, exc, disp->ContextRecord,
178+
disp->HistoryTable);
152179
_LIBUNWIND_ABORT("RtlUnwindEx() failed");
153180
case _URC_INSTALL_CONTEXT: {
154181
// If we were called by __libunwind_seh_personality(), indicate that
@@ -212,6 +239,21 @@ __libunwind_seh_personality(int version, _Unwind_Action state,
212239
ms_exc.ExceptionInformation[2] = state;
213240
DISPATCHER_CONTEXT *disp_ctx =
214241
__unw_seh_get_disp_ctx((unw_cursor_t *)context);
242+
#if defined(__aarch64__)
243+
LOCAL_DISPATCHER_CONTEXT_NONVOLREG_ARM64 nonvol;
244+
memcpy(&nonvol.GpNvRegs, &disp_ctx->ContextRecord->X19,
245+
sizeof(nonvol.GpNvRegs));
246+
for (int i = 0; i < 8; i++)
247+
nonvol.FpNvRegs[i] = disp_ctx->ContextRecord->V[i + 8].D[0];
248+
disp_ctx->NonVolatileRegisters = nonvol.Buffer;
249+
#elif defined(__arm__)
250+
LOCAL_DISPATCHER_CONTEXT_NONVOLREG_ARM nonvol;
251+
memcpy(&nonvol.GpNvRegs, &disp_ctx->ContextRecord->R4,
252+
sizeof(nonvol.GpNvRegs));
253+
memcpy(&nonvol.FpNvRegs, &disp_ctx->ContextRecord->D[8],
254+
sizeof(nonvol.FpNvRegs));
255+
disp_ctx->NonVolatileRegisters = nonvol.Buffer;
256+
#endif
215257
_LIBUNWIND_TRACE_UNWINDING("__libunwind_seh_personality() calling "
216258
"LanguageHandler %p(%p, %p, %p, %p)",
217259
(void *)disp_ctx->LanguageHandler, (void *)&ms_exc,

system/lib/libunwind/src/Unwind-wasm.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,7 @@ _LIBUNWIND_EXPORT uintptr_t _Unwind_GetIP(struct _Unwind_Context *context) {
102102
}
103103

104104
/// Not used in Wasm.
105-
_LIBUNWIND_EXPORT void _Unwind_SetIP(struct _Unwind_Context *context,
106-
uintptr_t value) {}
105+
_LIBUNWIND_EXPORT void _Unwind_SetIP(struct _Unwind_Context *, uintptr_t) {}
107106

108107
/// Called by personality handler to get LSDA for current frame.
109108
_LIBUNWIND_EXPORT uintptr_t
@@ -115,8 +114,7 @@ _Unwind_GetLanguageSpecificData(struct _Unwind_Context *context) {
115114
}
116115

117116
/// Not used in Wasm.
118-
_LIBUNWIND_EXPORT uintptr_t
119-
_Unwind_GetRegionStart(struct _Unwind_Context *context) {
117+
_LIBUNWIND_EXPORT uintptr_t _Unwind_GetRegionStart(struct _Unwind_Context *) {
120118
return 0;
121119
}
122120

0 commit comments

Comments
 (0)