Commit 77d04c03e3

Robin Voetter <robin@voetter.nl>
2019-09-04 16:23:25
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)
1 parent 6a76298
Changed files (4)
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,
         };
     }
 
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)
     );
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.
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,