commit 77d04c03e3f20c4c60d98e73b876222006aa05fc (tree)
parent 6a76298740344ba6d82c33b19914238a1233eaa0
Author: Robin Voetter <robin@voetter.nl>
Date: Wed, 4 Sep 2019 16:23:25 +0200
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)
Diffstat:
4 files changed, 9 insertions(+), 8 deletions(-)
diff --git 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
@@ -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
@@ -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
@@ -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.