authorgravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2019-09-04 16:23:25+02:00
committergravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2019-09-04 16:23:25+02:00
log77d04c03e3f20c4c60d98e73b876222006aa05fc
tree22418cab169a7e4b1600b958809736c0c1e540df
parent6a76298740344ba6d82c33b19914238a1233eaa0

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)

4 files changed, 9 insertions(+), 8 deletions(-)

std/debug.zig+2-1
......@@ -1053,7 +1053,8 @@ fn openSelfDebugInfoPosix(allocator: *mem.Allocator) !DwarfInfo {
10531053 S.self_exe_file = try fs.openSelfExe();
10541054 errdefer S.self_exe_file.close();
10551055
1056 const self_exe_mmap_len = mem.alignForward(@intCast(usize, try S.self_exe_file.getEndPos()), mem.page_size);
1056 const self_exe_len = math.cast(usize, try S.self_exe_file.getEndPos()) catch return error.DebugInfoTooLarge;
1057 const self_exe_mmap_len = mem.alignForward(self_exe_len, mem.page_size);
10571058 const self_exe_mmap = try os.mmap(
10581059 null,
10591060 self_exe_mmap_len,
std/fs/file.zig+3-3
......@@ -261,9 +261,9 @@ pub const File = struct {
261261 return Stat{
262262 .size = @bitCast(u64, st.size),
263263 .mode = st.mode,
264 .atime = @intCast(i64, atime.tv_sec) * std.time.ns_per_s + atime.tv_nsec,
265 .mtime = @intCast(i64, mtime.tv_sec) * std.time.ns_per_s + mtime.tv_nsec,
266 .ctime = @intCast(i64, ctime.tv_sec) * std.time.ns_per_s + ctime.tv_nsec,
264 .atime = i64(atime.tv_sec) * std.time.ns_per_s + atime.tv_nsec,
265 .mtime = i64(mtime.tv_sec) * std.time.ns_per_s + mtime.tv_nsec,
266 .ctime = i64(ctime.tv_sec) * std.time.ns_per_s + ctime.tv_nsec,
267267 };
268268 }
269269
std/os/linux/arm-eabi.zig+1-1
......@@ -89,7 +89,7 @@ pub extern fn clone(func: extern fn (arg: usize) u8, stack: usize, flags: u32, a
8989// LLVM calls this when the read-tp-hard feature is set to false. Currently, there is no way to pass
9090// that to llvm via zig, see https://github.com/ziglang/zig/issues/2883.
9191// LLVM expects libc to provide this function as __aeabi_read_tp, so it is exported if needed from special/c.zig.
92pub nakedcc fn getThreadPointer() usize {
92pub extern fn getThreadPointer() usize {
9393 return asm volatile("mrc p15, 0, %[ret], c13, c0, 3"
9494 : [ret] "=r" (-> usize)
9595 );
std/os/linux/tls.zig+3-3
......@@ -133,7 +133,7 @@ pub fn initTLS() void {
133133 var at_phent: usize = undefined;
134134 var at_phnum: usize = undefined;
135135 var at_phdr: usize = undefined;
136 var at_hwcap: usize = undefined;
136 var at_hwcap: ?usize = null;
137137
138138 var i: usize = 0;
139139 while (auxv[i].a_type != std.elf.AT_NULL) : (i += 1) {
......@@ -147,8 +147,8 @@ pub fn initTLS() void {
147147 }
148148
149149 // If the cpu is arm-based, check if it supports the TLS register
150 if (builtin.arch == builtin.Arch.arm) {
151 if (at_hwcap & std.os.linux.HWCAP_TLS == 0) {
150 if (at_hwcap) |hwcap| {
151 if (builtin.arch == builtin.Arch.arm and hwcap & std.os.linux.HWCAP_TLS == 0) {
152152 // If the CPU does not support TLS via a coprocessor register,
153153 // a kernel helper function can be used instead on certain linux kernels.
154154 // See linux/arch/arm/include/asm/tls.h and musl/src/thread/arm/__set_thread_area.c.