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 {...@@ -1053,7 +1053,8 @@ fn openSelfDebugInfoPosix(allocator: *mem.Allocator) !DwarfInfo {
1053 S.self_exe_file = try fs.openSelfExe();1053 S.self_exe_file = try fs.openSelfExe();
1054 errdefer S.self_exe_file.close();1054 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);
1057 const self_exe_mmap = try os.mmap(1058 const self_exe_mmap = try os.mmap(
1058 null,1059 null,
1059 self_exe_mmap_len,1060 self_exe_mmap_len,
std/fs/file.zig+3-3
...@@ -261,9 +261,9 @@ pub const File = struct {...@@ -261,9 +261,9 @@ pub const File = struct {
261 return Stat{261 return Stat{
262 .size = @bitCast(u64, st.size),262 .size = @bitCast(u64, st.size),
263 .mode = st.mode,263 .mode = st.mode,
264 .atime = @intCast(i64, atime.tv_sec) * std.time.ns_per_s + atime.tv_nsec,264 .atime = 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,265 .mtime = 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,266 .ctime = i64(ctime.tv_sec) * std.time.ns_per_s + ctime.tv_nsec,
267 };267 };
268 }268 }
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...@@ -89,7 +89,7 @@ pub extern fn clone(func: extern fn (arg: usize) u8, stack: usize, flags: u32, a
89// LLVM calls this when the read-tp-hard feature is set to false. Currently, there is no way to pass89// LLVM calls this when the read-tp-hard feature is set to false. Currently, there is no way to pass
90// that to llvm via zig, see https://github.com/ziglang/zig/issues/2883.90// that to llvm via zig, see https://github.com/ziglang/zig/issues/2883.
91// LLVM expects libc to provide this function as __aeabi_read_tp, so it is exported if needed from special/c.zig.91// 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 {
93 return asm volatile("mrc p15, 0, %[ret], c13, c0, 3"93 return asm volatile("mrc p15, 0, %[ret], c13, c0, 3"
94 : [ret] "=r" (-> usize)94 : [ret] "=r" (-> usize)
95 );95 );
std/os/linux/tls.zig+3-3
...@@ -133,7 +133,7 @@ pub fn initTLS() void {...@@ -133,7 +133,7 @@ pub fn initTLS() void {
133 var at_phent: usize = undefined;133 var at_phent: usize = undefined;
134 var at_phnum: usize = undefined;134 var at_phnum: usize = undefined;
135 var at_phdr: usize = undefined;135 var at_phdr: usize = undefined;
136 var at_hwcap: usize = undefined;136 var at_hwcap: ?usize = null;
137137
138 var i: usize = 0;138 var i: usize = 0;
139 while (auxv[i].a_type != std.elf.AT_NULL) : (i += 1) {139 while (auxv[i].a_type != std.elf.AT_NULL) : (i += 1) {
...@@ -147,8 +147,8 @@ pub fn initTLS() void {...@@ -147,8 +147,8 @@ pub fn initTLS() void {
147 }147 }
148148
149 // If the cpu is arm-based, check if it supports the TLS register149 // If the cpu is arm-based, check if it supports the TLS register
150 if (builtin.arch == builtin.Arch.arm) {150 if (at_hwcap) |hwcap| {
151 if (at_hwcap & std.os.linux.HWCAP_TLS == 0) {151 if (builtin.arch == builtin.Arch.arm and hwcap & std.os.linux.HWCAP_TLS == 0) {
152 // If the CPU does not support TLS via a coprocessor register,152 // If the CPU does not support TLS via a coprocessor register,
153 // a kernel helper function can be used instead on certain linux kernels.153 // a kernel helper function can be used instead on certain linux kernels.
154 // See linux/arch/arm/include/asm/tls.h and musl/src/thread/arm/__set_thread_area.c.154 // See linux/arch/arm/include/asm/tls.h and musl/src/thread/arm/__set_thread_area.c.