authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-05-01 19:16:48-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-05-01 19:16:48-04:00
logcff5358f60bac70728c9b738c8311e055e96d04a
tree1e89a67d08c3c0b3afa318b758d9b4512771ceb6
parent3cbd0065fa4b0f659dfb1733b25bd09e37442d09

make debug safety stuff lazy


5 files changed, 24 insertions(+), 9 deletions(-)

src/codegen.cpp+2-2
......@@ -381,10 +381,10 @@ static LLVMValueRef fn_llvm_value(CodeGen *g, FnTableEntry *fn_table_entry) {
381381 LLVMSetLinkage(fn_table_entry->llvm_value, LLVMExternalLinkage);
382382 break;
383383 case GlobalLinkageIdWeak:
384 LLVMSetLinkage(fn_table_entry->llvm_value, LLVMWeakODRLinkage);
384 LLVMSetLinkage(fn_table_entry->llvm_value, LLVMWeakAnyLinkage);
385385 break;
386386 case GlobalLinkageIdLinkOnce:
387 LLVMSetLinkage(fn_table_entry->llvm_value, LLVMLinkOnceODRLinkage);
387 LLVMSetLinkage(fn_table_entry->llvm_value, LLVMLinkOnceAnyLinkage);
388388 break;
389389 }
390390
std/debug.zig+2-1
......@@ -92,7 +92,8 @@ pub fn writeStackTrace(out_stream: &io.OutStream, allocator: &mem.Allocator, tty
9292 const ptr_hex = if (@sizeOf(usize) == 4) "0x{x8}" else "0x{x16}";
9393
9494 const compile_unit = findCompileUnit(st, return_address) ?? {
95 %return out_stream.print(DIM ++ ptr_hex ++ " in ??? (???)" ++ RESET ++ "\n\n\n", return_address);
95 %return out_stream.print("???:?:?: " ++ DIM ++ ptr_hex ++ " in ??? (???)" ++ RESET ++ "\n ???\n\n",
96 return_address);
9697 %return out_stream.flush();
9798 continue;
9899 };
std/os/index.zig+14-5
......@@ -52,6 +52,7 @@ error ReadOnlyFileSystem;
5252error LinkQuotaExceeded;
5353error RenameAcrossMountPoints;
5454error DirNotEmpty;
55error WouldBlock;
5556
5657/// Fills `buf` with random bytes. If linking against libc, this calls the
5758/// appropriate OS-specific library call. Otherwise it uses the zig standard
......@@ -128,6 +129,11 @@ pub fn posixClose(fd: i32) {
128129 }
129130}
130131
132error WouldBlock;
133error FileClosed;
134error DestinationAddressRequired;
135error FileSystem;
136
131137/// Calls POSIX write, and keeps trying if it gets interrupted.
132138pub fn posixWrite(fd: i32, bytes: []const u8) -> %void {
133139 while (true) {
......@@ -136,12 +142,15 @@ pub fn posixWrite(fd: i32, bytes: []const u8) -> %void {
136142 if (write_err > 0) {
137143 return switch (write_err) {
138144 errno.EINTR => continue,
139 errno.EINVAL => unreachable,
145 errno.EINVAL, errno.EFAULT => unreachable,
146 errno.EAGAIN => error.WouldBlock,
147 errno.EBADF => error.FileClosed,
148 errno.EDESTADDRREQ => error.DestinationAddressRequired,
140149 errno.EDQUOT => error.DiskQuota,
141150 errno.EFBIG => error.FileTooBig,
142 errno.EIO => error.Io,
151 errno.EIO => error.FileSystem,
143152 errno.ENOSPC => error.NoSpaceLeft,
144 errno.EPERM => error.BadPerm,
153 errno.EPERM => error.AccessDenied,
145154 errno.EPIPE => error.PipeFail,
146155 else => error.Unexpected,
147156 }
......@@ -185,7 +194,7 @@ pub fn posixOpen(file_path: []const u8, flags: usize, perm: usize, allocator: ?&
185194
186195 errno.EFAULT => unreachable,
187196 errno.EINVAL => unreachable,
188 errno.EACCES => error.BadPerm,
197 errno.EACCES => error.AccessDenied,
189198 errno.EFBIG, errno.EOVERFLOW => error.FileTooBig,
190199 errno.EISDIR => error.IsDir,
191200 errno.ELOOP => error.SymLinkLoop,
......@@ -197,7 +206,7 @@ pub fn posixOpen(file_path: []const u8, flags: usize, perm: usize, allocator: ?&
197206 errno.ENOMEM => error.SystemResources,
198207 errno.ENOSPC => error.NoSpaceLeft,
199208 errno.ENOTDIR => error.NotDir,
200 errno.EPERM => error.BadPerm,
209 errno.EPERM => error.AccessDenied,
201210 else => error.Unexpected,
202211 }
203212 }
std/special/builtin.zig+5
......@@ -4,6 +4,7 @@
44// Note that these functions do not return `dest`, like the libc API.
55// The semantics of these functions is dictated by the corresponding
66// LLVM intrinsics, not by the libc API.
7const builtin = @import("builtin");
78
89export fn memset(dest: ?&u8, c: u8, n: usize) {
910 @setDebugSafety(this, false);
......@@ -31,5 +32,9 @@ export fn memcpy(noalias dest: ?&u8, noalias src: ?&const u8, n: usize) {
3132}
3233
3334export fn __stack_chk_fail() {
35 if (builtin.is_release) {
36 @setGlobalLinkage(__stack_chk_fail, builtin.GlobalLinkage.Internal);
37 unreachable;
38 }
3439 @panic("stack smashing detected");
3540}
std/special/zigrt.zig+1-1
......@@ -5,7 +5,7 @@
55const builtin = @import("builtin");
66
77export coldcc fn __zig_panic(message_ptr: &const u8, message_len: usize) -> noreturn {
8 @setGlobalLinkage(__zig_panic, builtin.GlobalLinkage.Weak);
8 @setGlobalLinkage(__zig_panic, builtin.GlobalLinkage.LinkOnce);
99 @setDebugSafety(this, false);
1010
1111 if (builtin.__zig_panic_implementation_provided) {