diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2019-12-16 16:17:52 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-12-16 16:17:52 -0500 |
| commit | 13cdc137e6389af83f225ab851bf8ef768ebcc69 (patch) | |
| tree | 34675041bfef45efd3c294f7df9fb244674c6dbf /lib/std | |
| parent | de0d8885b4623dab14c379fc844ae0b18d9f8405 (diff) | |
| parent | 839b3a61ad51b385ac28a0123b6cc63d90ef83f8 (diff) | |
| download | zig-13cdc137e6389af83f225ab851bf8ef768ebcc69.tar.gz zig-13cdc137e6389af83f225ab851bf8ef768ebcc69.zip | |
Merge pull request #3570 from ziglang/c-sanitize-undef
use -fsanitize=undefined for C code in safe build modes
Diffstat (limited to 'lib/std')
| -rw-r--r-- | lib/std/build.zig | 5 | ||||
| -rw-r--r-- | lib/std/debug.zig | 9 |
2 files changed, 12 insertions, 2 deletions
diff --git a/lib/std/build.zig b/lib/std/build.zig index e54a23d8ab..f7e4756e90 100644 --- a/lib/std/build.zig +++ b/lib/std/build.zig @@ -1034,6 +1034,7 @@ pub const LibExeObjStep = struct { disable_gen_h: bool, bundle_compiler_rt: bool, disable_stack_probing: bool, + disable_sanitize_c: bool, c_std: Builder.CStd, override_lib_dir: ?[]const u8, main_pkg_path: ?[]const u8, @@ -1183,6 +1184,7 @@ pub const LibExeObjStep = struct { .disable_gen_h = false, .bundle_compiler_rt = false, .disable_stack_probing = false, + .disable_sanitize_c = false, .output_dir = null, .need_system_paths = false, .single_threaded = false, @@ -1822,6 +1824,9 @@ pub const LibExeObjStep = struct { if (self.disable_stack_probing) { try zig_args.append("-fno-stack-check"); } + if (self.disable_sanitize_c) { + try zig_args.append("-fno-sanitize-c"); + } switch (self.target) { .Native => {}, diff --git a/lib/std/debug.zig b/lib/std/debug.zig index 69b9e894bb..9b24e1acd3 100644 --- a/lib/std/debug.zig +++ b/lib/std/debug.zig @@ -2404,6 +2404,7 @@ pub fn attachSegfaultHandler() void { }; os.sigaction(os.SIGSEGV, &act, null); + os.sigaction(os.SIGILL, &act, null); } fn resetSegfaultHandler() void { @@ -2420,6 +2421,7 @@ fn resetSegfaultHandler() void { .flags = 0, }; os.sigaction(os.SIGSEGV, &act, null); + os.sigaction(os.SIGILL, &act, null); } extern fn handleSegfaultLinux(sig: i32, info: *const os.siginfo_t, ctx_ptr: *const c_void) noreturn { @@ -2429,8 +2431,11 @@ extern fn handleSegfaultLinux(sig: i32, info: *const os.siginfo_t, ctx_ptr: *con resetSegfaultHandler(); const addr = @ptrToInt(info.fields.sigfault.addr); - std.debug.warn("Segmentation fault at address 0x{x}\n", .{addr}); - + switch (sig) { + os.SIGSEGV => std.debug.warn("Segmentation fault at address 0x{x}\n", .{addr}), + os.SIGILL => std.debug.warn("Illegal instruction at address 0x{x}\n", .{addr}), + else => unreachable, + } switch (builtin.arch) { .i386 => { const ctx = @ptrCast(*const os.ucontext_t, @alignCast(@alignOf(os.ucontext_t), ctx_ptr)); |
