| ... | @@ -484,14 +484,6 @@ fn floatCastOverflow( | ... | @@ -484,14 +484,6 @@ fn floatCastOverflow( |
| 484 | } | 484 | } |
| 485 | } | 485 | } |
| 486 | | 486 | |
| 487 | fn SimpleHandler(comptime error_name: []const u8) type { | | |
| 488 | return struct { | | |
| 489 | fn handler() callconv(.c) noreturn { | | |
| 490 | logMessage("{s}", .{error_name}); | | |
| 491 | } | | |
| 492 | }; | | |
| 493 | } | | |
| 494 | | | |
| 495 | inline fn logMessage(comptime fmt: []const u8, args: anytype) noreturn { | 487 | inline fn logMessage(comptime fmt: []const u8, args: anytype) noreturn { |
| 496 | std.debug.panicExtra(null, @returnAddress(), fmt, args); | 488 | std.debug.panicExtra(null, @returnAddress(), fmt, args); |
| 497 | } | 489 | } |
| ... | @@ -513,72 +505,70 @@ fn exportHandler( | ... | @@ -513,72 +505,70 @@ fn exportHandler( |
| 513 | } | 505 | } |
| 514 | | 506 | |
| 515 | fn exportMinimal( | 507 | fn exportMinimal( |
| 516 | err_name: anytype, | 508 | comptime err_name: []const u8, |
| 517 | comptime sym_name: []const u8, | 509 | comptime sym_name: []const u8, |
| 518 | comptime abort: bool, | 510 | comptime abort: bool, |
| 519 | ) void { | 511 | ) void { |
| 520 | const handler = &SimpleHandler(err_name).handler; | 512 | const S = struct { |
| | 513 | fn handler() callconv(.c) noreturn { |
| | 514 | logMessage("{s}", .{err_name}); |
| | 515 | } |
| | 516 | }; |
| 521 | const linkage = if (builtin.is_test) .internal else .weak; | 517 | const linkage = if (builtin.is_test) .internal else .weak; |
| 522 | { | 518 | { |
| 523 | const N = "__ubsan_handle_" ++ sym_name ++ "_minimal"; | 519 | const N = "__ubsan_handle_" ++ sym_name ++ "_minimal"; |
| 524 | @export(handler, .{ .name = N, .linkage = linkage }); | 520 | @export(&S.handler, .{ .name = N, .linkage = linkage }); |
| 525 | } | 521 | } |
| 526 | if (abort) { | 522 | if (abort) { |
| 527 | const N = "__ubsan_handle_" ++ sym_name ++ "_minimal_abort"; | 523 | const N = "__ubsan_handle_" ++ sym_name ++ "_minimal_abort"; |
| 528 | @export(handler, .{ .name = N, .linkage = linkage }); | 524 | @export(&S.handler, .{ .name = N, .linkage = linkage }); |
| 529 | } | 525 | } |
| 530 | } | 526 | } |
| 531 | | 527 | |
| 532 | fn exportHelper( | | |
| 533 | comptime err_name: []const u8, | | |
| 534 | comptime sym_name: []const u8, | | |
| 535 | comptime abort: bool, | | |
| 536 | ) void { | | |
| 537 | exportHandler(&SimpleHandler(err_name).handler, sym_name, abort); | | |
| 538 | exportMinimal(err_name, sym_name, abort); | | |
| 539 | } | | |
| 540 | | | |
| 541 | comptime { | 528 | comptime { |
| 542 | overflowHandler("add_overflow", "+"); | 529 | overflowHandler("add_overflow", "+"); |
| 543 | overflowHandler("sub_overflow", "-"); | | |
| 544 | overflowHandler("mul_overflow", "*"); | 530 | overflowHandler("mul_overflow", "*"); |
| 545 | exportHandler(&negationHandler, "negate_overflow", true); | 531 | overflowHandler("sub_overflow", "-"); |
| 546 | exportHandler(&divRemHandler, "divrem_overflow", true); | | |
| 547 | exportHandler(&alignmentAssumptionHandler, "alignment_assumption", true); | 532 | exportHandler(&alignmentAssumptionHandler, "alignment_assumption", true); |
| 548 | exportHandler(&shiftOob, "shift_out_of_bounds", true); | | |
| 549 | exportHandler(&outOfBounds, "out_of_bounds", true); | | |
| 550 | exportHandler(&pointerOverflow, "pointer_overflow", true); | | |
| 551 | exportHandler(&typeMismatch, "type_mismatch_v1", true); | | |
| 552 | exportHandler(&builtinUnreachable, "builtin_unreachable", false); | 533 | exportHandler(&builtinUnreachable, "builtin_unreachable", false); |
| | 534 | exportHandler(&divRemHandler, "divrem_overflow", true); |
| | 535 | exportHandler(&floatCastOverflow, "float_cast_overflow", true); |
| | 536 | exportHandler(&invalidBuiltin, "invalid_builtin", true); |
| | 537 | exportHandler(&loadInvalidValue, "load_invalid_value", true); |
| 553 | exportHandler(&missingReturn, "missing_return", false); | 538 | exportHandler(&missingReturn, "missing_return", false); |
| 554 | exportHandler(&nonNullReturn, "nonnull_return_v1", true); | 539 | exportHandler(&negationHandler, "negate_overflow", true); |
| 555 | exportHandler(&nonNullArg, "nonnull_arg", true); | 540 | exportHandler(&nonNullArg, "nonnull_arg", true); |
| 556 | exportHandler(&loadInvalidValue, "load_invalid_value", true); | 541 | exportHandler(&nonNullReturn, "nonnull_return_v1", true); |
| 557 | exportHandler(&invalidBuiltin, "invalid_builtin", true); | 542 | exportHandler(&outOfBounds, "out_of_bounds", true); |
| | 543 | exportHandler(&pointerOverflow, "pointer_overflow", true); |
| | 544 | exportHandler(&shiftOob, "shift_out_of_bounds", true); |
| | 545 | exportHandler(&typeMismatch, "type_mismatch_v1", true); |
| 558 | exportHandler(&vlaBoundNotPositive, "vla_bound_not_positive", true); | 546 | exportHandler(&vlaBoundNotPositive, "vla_bound_not_positive", true); |
| 559 | exportHandler(&floatCastOverflow, "float_cast_overflow", true); | | |
| 560 | | | |
| 561 | exportHelper("function-type-mismatch", "function_type_mismatch", true); | | |
| 562 | exportHelper("implicit-conversion", "implicit_conversion", true); | | |
| 563 | exportHelper("nullability-arg", "nullability_arg", true); | | |
| 564 | exportHelper("nullability-return", "nullability_return", true); | | |
| 565 | exportHelper("cfi-check-fail", "cfi_check_fail", true); | | |
| 566 | exportHelper("function-type-mismatch-v1", "function_type_mismatch_v1", true); | | |
| 567 | | 547 | |
| 568 | exportMinimal("builtin-unreachable", "builtin_unreachable", false); | | |
| 569 | exportMinimal("add-overflow", "add_overflow", true); | 548 | exportMinimal("add-overflow", "add_overflow", true); |
| 570 | exportMinimal("sub-overflow", "sub_overflow", true); | 549 | exportMinimal("sub-overflow", "sub_overflow", true); |
| 571 | exportMinimal("mul-overflow", "mul_overflow", true); | 550 | exportMinimal("mul-overflow", "mul_overflow", true); |
| 572 | exportMinimal("negation-handler", "negate_overflow", true); | | |
| 573 | exportMinimal("divrem-handler", "divrem_overflow", true); | | |
| 574 | exportMinimal("alignment-assumption-handler", "alignment_assumption", true); | 551 | exportMinimal("alignment-assumption-handler", "alignment_assumption", true); |
| 575 | exportMinimal("shift-oob", "shift_out_of_bounds", true); | 552 | exportMinimal("builtin-unreachable", "builtin_unreachable", false); |
| | 553 | exportMinimal("divrem-handler", "divrem_overflow", true); |
| | 554 | exportMinimal("float-cast-overflow", "float_cast_overflow", true); |
| | 555 | exportMinimal("invalid-builtin", "invalid_builtin", true); |
| | 556 | exportMinimal("load-invalid-value", "load_invalid_value", true); |
| | 557 | exportMinimal("missing-return", "missing_return", true); |
| | 558 | exportMinimal("negation-handler", "negate_overflow", true); |
| | 559 | exportMinimal("nonnull-arg", "nonnull_arg", true); |
| 576 | exportMinimal("out-of-bounds", "out_of_bounds", true); | 560 | exportMinimal("out-of-bounds", "out_of_bounds", true); |
| 577 | exportMinimal("pointer-overflow", "pointer_overflow", true); | 561 | exportMinimal("pointer-overflow", "pointer_overflow", true); |
| | 562 | exportMinimal("shift-oob", "shift_out_of_bounds", true); |
| 578 | exportMinimal("type-mismatch", "type_mismatch", true); | 563 | exportMinimal("type-mismatch", "type_mismatch", true); |
| | 564 | exportMinimal("vla-bound-not-positive", "vla_bound_not_positive", true); |
| 579 | | 565 | |
| 580 | // these checks are nearly impossible to duplicate in zig, as they rely on nuances | 566 | // these checks are nearly impossible to duplicate in zig, as they rely on nuances |
| 581 | // in the Itanium C++ ABI. | 567 | // in the Itanium C++ ABI. |
| 582 | // exportHelper("dynamic_type_cache_miss", "dynamic-type-cache-miss", true); | 568 | // exportHelper("dynamic_type_cache_miss", "dynamic-type-cache-miss", true); |
| 583 | // exportHelper("vptr_type_cache", "vptr-type-cache", true); | 569 | // exportHelper("vptr_type_cache", "vptr-type-cache", true); |
| | 570 | |
| | 571 | // we disable -fsanitize=function for reasons explained in src/Compilation.zig |
| | 572 | // exportHelper("function-type-mismatch", "function_type_mismatch", true); |
| | 573 | // exportHelper("function-type-mismatch-v1", "function_type_mismatch_v1", true); |
| 584 | } | 574 | } |