From 108a51b11032ba3ed7864a653f87283853e6e318 Mon Sep 17 00:00:00 2001 From: Robin Voetter Date: Thu, 29 Aug 2019 10:34:05 +0200 Subject: fix issues with debug.zig - Use sys_*stat*64 instead of sys_*stat* where appropriate - Fix overflow when calculating atime, ctime and mtime on File.stat() - Fix compilation error casting getEndPos to usize. --- std/debug.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'std/debug.zig') diff --git a/std/debug.zig b/std/debug.zig index d1c17343ef..a6ef60b663 100644 --- a/std/debug.zig +++ b/std/debug.zig @@ -1053,7 +1053,7 @@ fn openSelfDebugInfoPosix(allocator: *mem.Allocator) !DwarfInfo { S.self_exe_file = try fs.openSelfExe(); errdefer S.self_exe_file.close(); - const self_exe_mmap_len = mem.alignForward(try S.self_exe_file.getEndPos(), mem.page_size); + const self_exe_mmap_len = mem.alignForward(@intCast(usize, try S.self_exe_file.getEndPos()), mem.page_size); const self_exe_mmap = try os.mmap( null, self_exe_mmap_len, -- cgit v1.2.3 From e4c262b804dded7e47aea0bb61f4578b94a7fa86 Mon Sep 17 00:00:00 2001 From: Robin Voetter Date: Thu, 29 Aug 2019 10:52:50 +0200 Subject: Don't print line info if source is not available --- std/debug.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'std/debug.zig') diff --git a/std/debug.zig b/std/debug.zig index a6ef60b663..8918426e47 100644 --- a/std/debug.zig +++ b/std/debug.zig @@ -793,7 +793,7 @@ fn printLineInfo( try out_stream.write(GREEN ++ "^" ++ RESET ++ "\n"); } } else |err| switch (err) { - error.EndOfFile => {}, + error.EndOfFile, error.FileNotFound => {}, else => return err, } } else { -- cgit v1.2.3 From 77d04c03e3f20c4c60d98e73b876222006aa05fc Mon Sep 17 00:00:00 2001 From: Robin Voetter Date: Wed, 4 Sep 2019 16:23:25 +0200 Subject: Implement remaining requested changes - Replace @intCast with a checked version (std/debug.zig) - Replace @intCast with i64() when casting from a smaller type (std/fs/file.zig) - Replace `nakedcc` with appropriate calling convention for linking with c (std/os/linux/arm-eabi.zig) - Only check if hwcap contains TLS when the hwcap field actually exists (std/os/linux/tls.zig) --- std/debug.zig | 3 ++- std/fs/file.zig | 6 +++--- std/os/linux/arm-eabi.zig | 2 +- std/os/linux/tls.zig | 6 +++--- 4 files changed, 9 insertions(+), 8 deletions(-) (limited to 'std/debug.zig') diff --git a/std/debug.zig b/std/debug.zig index 8918426e47..68e6220a72 100644 --- a/std/debug.zig +++ b/std/debug.zig @@ -1053,7 +1053,8 @@ fn openSelfDebugInfoPosix(allocator: *mem.Allocator) !DwarfInfo { S.self_exe_file = try fs.openSelfExe(); errdefer S.self_exe_file.close(); - const self_exe_mmap_len = mem.alignForward(@intCast(usize, try S.self_exe_file.getEndPos()), mem.page_size); + const self_exe_len = math.cast(usize, try S.self_exe_file.getEndPos()) catch return error.DebugInfoTooLarge; + const self_exe_mmap_len = mem.alignForward(self_exe_len, mem.page_size); const self_exe_mmap = try os.mmap( null, self_exe_mmap_len, diff --git a/std/fs/file.zig b/std/fs/file.zig index 83cbe23780..5ecad01026 100644 --- a/std/fs/file.zig +++ b/std/fs/file.zig @@ -261,9 +261,9 @@ pub const File = struct { return Stat{ .size = @bitCast(u64, st.size), .mode = st.mode, - .atime = @intCast(i64, atime.tv_sec) * std.time.ns_per_s + atime.tv_nsec, - .mtime = @intCast(i64, mtime.tv_sec) * std.time.ns_per_s + mtime.tv_nsec, - .ctime = @intCast(i64, ctime.tv_sec) * std.time.ns_per_s + ctime.tv_nsec, + .atime = i64(atime.tv_sec) * std.time.ns_per_s + atime.tv_nsec, + .mtime = i64(mtime.tv_sec) * std.time.ns_per_s + mtime.tv_nsec, + .ctime = i64(ctime.tv_sec) * std.time.ns_per_s + ctime.tv_nsec, }; } diff --git a/std/os/linux/arm-eabi.zig b/std/os/linux/arm-eabi.zig index a0a00dce8b..c8a5bbe378 100644 --- a/std/os/linux/arm-eabi.zig +++ b/std/os/linux/arm-eabi.zig @@ -89,7 +89,7 @@ pub extern fn clone(func: extern fn (arg: usize) u8, stack: usize, flags: u32, a // LLVM calls this when the read-tp-hard feature is set to false. Currently, there is no way to pass // that to llvm via zig, see https://github.com/ziglang/zig/issues/2883. // LLVM expects libc to provide this function as __aeabi_read_tp, so it is exported if needed from special/c.zig. -pub nakedcc fn getThreadPointer() usize { +pub extern fn getThreadPointer() usize { return asm volatile("mrc p15, 0, %[ret], c13, c0, 3" : [ret] "=r" (-> usize) ); diff --git a/std/os/linux/tls.zig b/std/os/linux/tls.zig index 8920e28a5b..2ed5f1d75b 100644 --- a/std/os/linux/tls.zig +++ b/std/os/linux/tls.zig @@ -133,7 +133,7 @@ pub fn initTLS() void { var at_phent: usize = undefined; var at_phnum: usize = undefined; var at_phdr: usize = undefined; - var at_hwcap: usize = undefined; + var at_hwcap: ?usize = null; var i: usize = 0; while (auxv[i].a_type != std.elf.AT_NULL) : (i += 1) { @@ -147,8 +147,8 @@ pub fn initTLS() void { } // If the cpu is arm-based, check if it supports the TLS register - if (builtin.arch == builtin.Arch.arm) { - if (at_hwcap & std.os.linux.HWCAP_TLS == 0) { + if (at_hwcap) |hwcap| { + if (builtin.arch == builtin.Arch.arm and hwcap & std.os.linux.HWCAP_TLS == 0) { // If the CPU does not support TLS via a coprocessor register, // a kernel helper function can be used instead on certain linux kernels. // See linux/arch/arm/include/asm/tls.h and musl/src/thread/arm/__set_thread_area.c. -- cgit v1.2.3