make debug safety stuff lazy

master
Andrew Kelley 2017-05-01 19:16:48 -04:00
parent 3cbd0065fa
commit cff5358f60
5 changed files with 24 additions and 9 deletions

View File

@ -381,10 +381,10 @@ static LLVMValueRef fn_llvm_value(CodeGen *g, FnTableEntry *fn_table_entry) {
LLVMSetLinkage(fn_table_entry->llvm_value, LLVMExternalLinkage);
break;
case GlobalLinkageIdWeak:
LLVMSetLinkage(fn_table_entry->llvm_value, LLVMWeakODRLinkage);
LLVMSetLinkage(fn_table_entry->llvm_value, LLVMWeakAnyLinkage);
break;
case GlobalLinkageIdLinkOnce:
LLVMSetLinkage(fn_table_entry->llvm_value, LLVMLinkOnceODRLinkage);
LLVMSetLinkage(fn_table_entry->llvm_value, LLVMLinkOnceAnyLinkage);
break;
}

View File

@ -92,7 +92,8 @@ pub fn writeStackTrace(out_stream: &io.OutStream, allocator: &mem.Allocator, tty
const ptr_hex = if (@sizeOf(usize) == 4) "0x{x8}" else "0x{x16}";
const compile_unit = findCompileUnit(st, return_address) ?? {
%return out_stream.print(DIM ++ ptr_hex ++ " in ??? (???)" ++ RESET ++ "\n\n\n", return_address);
%return out_stream.print("???:?:?: " ++ DIM ++ ptr_hex ++ " in ??? (???)" ++ RESET ++ "\n ???\n\n",
return_address);
%return out_stream.flush();
continue;
};

View File

@ -52,6 +52,7 @@ error ReadOnlyFileSystem;
error LinkQuotaExceeded;
error RenameAcrossMountPoints;
error DirNotEmpty;
error WouldBlock;
/// Fills `buf` with random bytes. If linking against libc, this calls the
/// appropriate OS-specific library call. Otherwise it uses the zig standard
@ -128,6 +129,11 @@ pub fn posixClose(fd: i32) {
}
}
error WouldBlock;
error FileClosed;
error DestinationAddressRequired;
error FileSystem;
/// Calls POSIX write, and keeps trying if it gets interrupted.
pub fn posixWrite(fd: i32, bytes: []const u8) -> %void {
while (true) {
@ -136,12 +142,15 @@ pub fn posixWrite(fd: i32, bytes: []const u8) -> %void {
if (write_err > 0) {
return switch (write_err) {
errno.EINTR => continue,
errno.EINVAL => unreachable,
errno.EINVAL, errno.EFAULT => unreachable,
errno.EAGAIN => error.WouldBlock,
errno.EBADF => error.FileClosed,
errno.EDESTADDRREQ => error.DestinationAddressRequired,
errno.EDQUOT => error.DiskQuota,
errno.EFBIG => error.FileTooBig,
errno.EIO => error.Io,
errno.EIO => error.FileSystem,
errno.ENOSPC => error.NoSpaceLeft,
errno.EPERM => error.BadPerm,
errno.EPERM => error.AccessDenied,
errno.EPIPE => error.PipeFail,
else => error.Unexpected,
}
@ -185,7 +194,7 @@ pub fn posixOpen(file_path: []const u8, flags: usize, perm: usize, allocator: ?&
errno.EFAULT => unreachable,
errno.EINVAL => unreachable,
errno.EACCES => error.BadPerm,
errno.EACCES => error.AccessDenied,
errno.EFBIG, errno.EOVERFLOW => error.FileTooBig,
errno.EISDIR => error.IsDir,
errno.ELOOP => error.SymLinkLoop,
@ -197,7 +206,7 @@ pub fn posixOpen(file_path: []const u8, flags: usize, perm: usize, allocator: ?&
errno.ENOMEM => error.SystemResources,
errno.ENOSPC => error.NoSpaceLeft,
errno.ENOTDIR => error.NotDir,
errno.EPERM => error.BadPerm,
errno.EPERM => error.AccessDenied,
else => error.Unexpected,
}
}

View File

@ -4,6 +4,7 @@
// Note that these functions do not return `dest`, like the libc API.
// The semantics of these functions is dictated by the corresponding
// LLVM intrinsics, not by the libc API.
const builtin = @import("builtin");
export fn memset(dest: ?&u8, c: u8, n: usize) {
@setDebugSafety(this, false);
@ -31,5 +32,9 @@ export fn memcpy(noalias dest: ?&u8, noalias src: ?&const u8, n: usize) {
}
export fn __stack_chk_fail() {
if (builtin.is_release) {
@setGlobalLinkage(__stack_chk_fail, builtin.GlobalLinkage.Internal);
unreachable;
}
@panic("stack smashing detected");
}

View File

@ -5,7 +5,7 @@
const builtin = @import("builtin");
export coldcc fn __zig_panic(message_ptr: &const u8, message_len: usize) -> noreturn {
@setGlobalLinkage(__zig_panic, builtin.GlobalLinkage.Weak);
@setGlobalLinkage(__zig_panic, builtin.GlobalLinkage.LinkOnce);
@setDebugSafety(this, false);
if (builtin.__zig_panic_implementation_provided) {