authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-09-23 13:19:14-07:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2024-09-23 13:19:14-07:00
loga08f8d44dace9d7e7833bce092b47faa5bc0796e
tree62c951fe29ec793b283ae64b32a9361b148aabc0
parent0676c04681ad7104faa7634c781df386e839d17b
parenta9d1c6acb2b3b1c85672461ecf0bb7d871767e44
signaturebadge-check Signed by PGP key B5690EEEBB952194

Merge pull request #21472 from alexrp/libunwind

`libunwind`: Update `gcc_personality_v0.c` to LLVM 19.1.0.

2 files changed, 33 insertions(+), 7 deletions(-)

lib/libunwind/src/gcc_personality_v0.c+29-7
......@@ -20,6 +20,15 @@
2020
2121#include <unwind.h>
2222
23#if defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__)
24#include <windows.h>
25#include <winnt.h>
26
27EXCEPTION_DISPOSITION _GCC_specific_handler(PEXCEPTION_RECORD, void *, PCONTEXT,
28 PDISPATCHER_CONTEXT,
29 _Unwind_Personality_Fn);
30#endif
31
2332// Pointer encodings documented at:
2433// http://refspecs.freestandards.org/LSB_1.3.0/gLSB/gLSB/ehframehdr.html
2534
......@@ -43,9 +52,9 @@
4352#define DW_EH_PE_indirect 0x80 // gcc extension
4453
4554// read a uleb128 encoded value and advance pointer
46static uintptr_t readULEB128(const uint8_t **data) {
47 uintptr_t result = 0;
48 uintptr_t shift = 0;
55static size_t readULEB128(const uint8_t **data) {
56 size_t result = 0;
57 size_t shift = 0;
4958 unsigned char byte;
5059 const uint8_t *p = *data;
5160 do {
......@@ -133,7 +142,7 @@ static uintptr_t readEncodedPointer(const uint8_t **data, uint8_t encoding) {
133142}
134143
135144#if defined(__arm__) && !defined(__USING_SJLJ_EXCEPTIONS__) && \
136 !defined(__ARM_DWARF_EH__)
145 !defined(__ARM_DWARF_EH__) && !defined(__SEH__)
137146#define USING_ARM_EHABI 1
138147_Unwind_Reason_Code __gnu_unwind_frame(struct _Unwind_Exception *,
139148 struct _Unwind_Context *);
......@@ -168,6 +177,10 @@ COMPILER_RT_ABI _Unwind_Reason_Code __gcc_personality_sj0(
168177COMPILER_RT_ABI _Unwind_Reason_Code __gcc_personality_v0(
169178 _Unwind_State state, struct _Unwind_Exception *exceptionObject,
170179 struct _Unwind_Context *context)
180#elif defined(__SEH__)
181static _Unwind_Reason_Code __gcc_personality_imp(
182 int version, _Unwind_Action actions, uint64_t exceptionClass,
183 struct _Unwind_Exception *exceptionObject, struct _Unwind_Context *context)
171184#else
172185COMPILER_RT_ABI _Unwind_Reason_Code __gcc_personality_v0(
173186 int version, _Unwind_Action actions, uint64_t exceptionClass,
......@@ -205,14 +218,14 @@ COMPILER_RT_ABI _Unwind_Reason_Code __gcc_personality_v0(
205218 }
206219 // Walk call-site table looking for range that includes current PC.
207220 uint8_t callSiteEncoding = *lsda++;
208 uint32_t callSiteTableLength = readULEB128(&lsda);
221 size_t callSiteTableLength = readULEB128(&lsda);
209222 const uint8_t *callSiteTableStart = lsda;
210223 const uint8_t *callSiteTableEnd = callSiteTableStart + callSiteTableLength;
211224 const uint8_t *p = callSiteTableStart;
212225 while (p < callSiteTableEnd) {
213226 uintptr_t start = readEncodedPointer(&p, callSiteEncoding);
214 uintptr_t length = readEncodedPointer(&p, callSiteEncoding);
215 uintptr_t landingPad = readEncodedPointer(&p, callSiteEncoding);
227 size_t length = readEncodedPointer(&p, callSiteEncoding);
228 size_t landingPad = readEncodedPointer(&p, callSiteEncoding);
216229 readULEB128(&p); // action value not used for C code
217230 if (landingPad == 0)
218231 continue; // no landing pad for this entry
......@@ -232,3 +245,12 @@ COMPILER_RT_ABI _Unwind_Reason_Code __gcc_personality_v0(
232245 // No landing pad found, continue unwinding.
233246 return continueUnwind(exceptionObject, context);
234247}
248
249#if defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__)
250COMPILER_RT_ABI EXCEPTION_DISPOSITION
251__gcc_personality_seh0(PEXCEPTION_RECORD ms_exc, void *this_frame,
252 PCONTEXT ms_orig_context, PDISPATCHER_CONTEXT ms_disp) {
253 return _GCC_specific_handler(ms_exc, this_frame, ms_orig_context, ms_disp,
254 __gcc_personality_imp);
255}
256#endif
src/libunwind.zig+4
......@@ -143,6 +143,10 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: std.Progress.Node) BuildErr
143143 try cflags.append("-Wno-visibility");
144144 try cflags.append("-Wno-incompatible-pointer-types");
145145
146 if (target.os.tag == .windows) {
147 try cflags.append("-Wno-dll-attribute-on-redeclaration");
148 }
149
146150 c_source_files[i] = .{
147151 .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{unwind_src}),
148152 .extra_flags = cflags.items,