| ... | ... | @@ -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 | 487 | inline fn logMessage(comptime fmt: []const u8, args: anytype) noreturn { |
| 496 | 488 | std.debug.panicExtra(null, @returnAddress(), fmt, args); |
| 497 | 489 | } |
| ... | ... | @@ -513,72 +505,70 @@ fn exportHandler( |
| 513 | 505 | } |
| 514 | 506 | |
| 515 | 507 | fn exportMinimal( |
| 516 | | err_name: anytype, |
| 508 | comptime err_name: []const u8, |
| 517 | 509 | comptime sym_name: []const u8, |
| 518 | 510 | comptime abort: bool, |
| 519 | 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 | 517 | const linkage = if (builtin.is_test) .internal else .weak; |
| 522 | 518 | { |
| 523 | 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 | 522 | if (abort) { |
| 527 | 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 | 528 | comptime { |
| 542 | 529 | overflowHandler("add_overflow", "+"); |
| 543 | | overflowHandler("sub_overflow", "-"); |
| 544 | 530 | overflowHandler("mul_overflow", "*"); |
| 545 | | exportHandler(&negationHandler, "negate_overflow", true); |
| 546 | | exportHandler(&divRemHandler, "divrem_overflow", true); |
| 531 | overflowHandler("sub_overflow", "-"); |
| 547 | 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 | 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 | 538 | exportHandler(&missingReturn, "missing_return", false); |
| 554 | | exportHandler(&nonNullReturn, "nonnull_return_v1", true); |
| 539 | exportHandler(&negationHandler, "negate_overflow", true); |
| 555 | 540 | exportHandler(&nonNullArg, "nonnull_arg", true); |
| 556 | | exportHandler(&loadInvalidValue, "load_invalid_value", true); |
| 557 | | exportHandler(&invalidBuiltin, "invalid_builtin", true); |
| 541 | exportHandler(&nonNullReturn, "nonnull_return_v1", 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 | 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 | 548 | exportMinimal("add-overflow", "add_overflow", true); |
| 570 | 549 | exportMinimal("sub-overflow", "sub_overflow", true); |
| 571 | 550 | exportMinimal("mul-overflow", "mul_overflow", true); |
| 572 | | exportMinimal("negation-handler", "negate_overflow", true); |
| 573 | | exportMinimal("divrem-handler", "divrem_overflow", true); |
| 574 | 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 | 560 | exportMinimal("out-of-bounds", "out_of_bounds", true); |
| 577 | 561 | exportMinimal("pointer-overflow", "pointer_overflow", true); |
| 562 | exportMinimal("shift-oob", "shift_out_of_bounds", true); |
| 578 | 563 | exportMinimal("type-mismatch", "type_mismatch", true); |
| 564 | exportMinimal("vla-bound-not-positive", "vla_bound_not_positive", true); |
| 579 | 565 | |
| 580 | 566 | // these checks are nearly impossible to duplicate in zig, as they rely on nuances |
| 581 | 567 | // in the Itanium C++ ABI. |
| 582 | 568 | // exportHelper("dynamic_type_cache_miss", "dynamic-type-cache-miss", true); |
| 583 | 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 | } |