Skip to content

Commit c1e18e7

Browse files
committed
Restore MODE=dbg support
We recently broke MODE=dbg support when we added C++ exception support. This change adds the missing UBSAN interfaces, needed to get it working again. Some of the ASAN checking in the SJLJ guts needed to be disabled since I doubt anyone's combined the two features until now.
1 parent f27808c commit c1e18e7

File tree

5 files changed

+34
-38
lines changed

5 files changed

+34
-38
lines changed

libc/intrin/ubsan.c

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,13 @@ struct UbsanOverflowData {
112112
struct UbsanTypeDescriptor *type;
113113
};
114114

115+
struct UbsanDynamicTypeCacheMissData {
116+
struct UbsanSourceLocation location;
117+
struct UbsanTypeDescriptor *type;
118+
void *TypeInfo;
119+
unsigned char TypeCheckKind;
120+
};
121+
115122
struct UbsanFloatCastOverflowData {
116123
#if __GNUC__ + 0 >= 6
117124
struct UbsanSourceLocation location;
@@ -145,6 +152,8 @@ upcast of\0\
145152
cast to virtual base of\0\
146153
\0";
147154

155+
uintptr_t __ubsan_vptr_type_cache[128];
156+
148157
static int __ubsan_bits(struct UbsanTypeDescriptor *t) {
149158
return 1 << (t->info >> 1);
150159
}
@@ -439,15 +448,22 @@ void __ubsan_handle_divrem_overflow_abort(
439448
__ubsan_handle_divrem_overflow(loc);
440449
}
441450

451+
static bool HandleDynamicTypeCacheMiss(
452+
struct UbsanDynamicTypeCacheMissData *data, uintptr_t ptr, uintptr_t hash) {
453+
return false; // TODO: implement me
454+
}
455+
442456
void __ubsan_handle_dynamic_type_cache_miss(
443-
const struct UbsanSourceLocation *loc) {
444-
__ubsan_abort(loc, "dynamic type cache miss")();
445-
__ubsan_unreachable();
457+
struct UbsanDynamicTypeCacheMissData *data, uintptr_t ptr, uintptr_t hash) {
458+
HandleDynamicTypeCacheMiss(data, ptr, hash);
446459
}
447460

448461
void __ubsan_handle_dynamic_type_cache_miss_abort(
449-
const struct UbsanSourceLocation *loc) {
450-
__ubsan_handle_dynamic_type_cache_miss(loc);
462+
struct UbsanDynamicTypeCacheMissData *data, uintptr_t ptr, uintptr_t hash) {
463+
if (HandleDynamicTypeCacheMiss(data, ptr, hash)) {
464+
__ubsan_abort(&data->location, "dynamic type cache miss")();
465+
__ubsan_unreachable();
466+
}
451467
}
452468

453469
void __ubsan_handle_function_type_mismatch(

third_party/libcxxabi/cxa_personality.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ enum
202202
/// @link http://dwarfstd.org/Dwarf4.pdf @unlink
203203
/// @param data reference variable holding memory pointer to decode from
204204
/// @returns decoded value
205-
static
205+
static dontasan
206206
uintptr_t
207207
readULEB128(const uint8_t** data)
208208
{
@@ -225,7 +225,7 @@ readULEB128(const uint8_t** data)
225225
/// @link http://dwarfstd.org/Dwarf4.pdf @unlink
226226
/// @param data reference variable holding memory pointer to decode from
227227
/// @returns decoded value
228-
static
228+
static dontasan
229229
intptr_t
230230
readSLEB128(const uint8_t** data)
231231
{
@@ -542,7 +542,7 @@ struct scan_results
542542

543543
} // unnamed namespace
544544

545-
static
545+
static dontasan
546546
void
547547
set_registers(_Unwind_Exception* unwind_exception, _Unwind_Context* context,
548548
const scan_results& results)
@@ -581,6 +581,7 @@ set_registers(_Unwind_Exception* unwind_exception, _Unwind_Context* context,
581581
_UA_CLEANUP_PHASE && !_UA_HANDLER_FRAME
582582
*/
583583

584+
dontasan
584585
static void scan_eh_tab(scan_results &results, _Unwind_Action actions,
585586
bool native_exception,
586587
_Unwind_Exception *unwind_exception,
@@ -911,6 +912,7 @@ static _Unwind_Reason_Code __gxx_personality_imp
911912
#else
912913
_LIBCXXABI_FUNC_VIS _Unwind_Reason_Code
913914
#ifdef __USING_SJLJ_EXCEPTIONS__
915+
dontasan
914916
__gxx_personality_sj0
915917
#elif defined(__MVS__)
916918
__zos_cxx_personality_v2

third_party/libunwind/README.cosmo

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,8 @@ ORIGIN
1212
Date: Tue, 28 Nov 2023 09:52:28 +0100
1313

1414
LOCAL CHANGES
15-
- Fixed `_Unwind_FunctionContext` struct to be ABI-compatible with code
16-
generated by GCC.
15+
16+
- Fixed `_Unwind_FunctionContext` struct to be ABI-compatible with
17+
code generated by GCC.
18+
19+
- Added `dontasan` annotations to functions that raised ASAN errors.

third_party/libunwind/Unwind-sjlj.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,15 @@ __Unwind_SjLj_SetTopOfFunctionStack(struct _Unwind_FunctionContext *fc) {
105105

106106

107107
/// Called at start of each function that catches exceptions
108-
_LIBUNWIND_EXPORT void
108+
_LIBUNWIND_EXPORT void dontasan
109109
_Unwind_SjLj_Register(struct _Unwind_FunctionContext *fc) {
110110
fc->prev = __Unwind_SjLj_GetTopOfFunctionStack();
111111
__Unwind_SjLj_SetTopOfFunctionStack(fc);
112112
}
113113

114114

115115
/// Called at end of each function that catches exceptions
116-
_LIBUNWIND_EXPORT void
116+
_LIBUNWIND_EXPORT void dontasan
117117
_Unwind_SjLj_Unregister(struct _Unwind_FunctionContext *fc) {
118118
__Unwind_SjLj_SetTopOfFunctionStack(fc->prev);
119119
}
@@ -426,6 +426,7 @@ _LIBUNWIND_EXPORT uintptr_t _Unwind_GetGR(struct _Unwind_Context *context,
426426

427427

428428
/// Called by personality handler during phase 2 to alter register values.
429+
dontasan
429430
_LIBUNWIND_EXPORT void _Unwind_SetGR(struct _Unwind_Context *context, int index,
430431
uintptr_t new_value) {
431432
_LIBUNWIND_TRACE_API("_Unwind_SetGR(context=%p, reg=%d, value=0x%" PRIuPTR

third_party/nsync/README.md

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

0 commit comments

Comments
 (0)