authorgravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2019-08-29 18:12:58+02:00
committergravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2019-08-29 18:12:58+02:00
log2323da3a680f48207d35db26f63ea0553e74d956
tree4670d28b0cae89d11d18e66a68a2fc30a1ed85db
parente4c262b804dded7e47aea0bb61f4578b94a7fa86

add __aeabi_read_tp


4 files changed, 46 insertions(+), 0 deletions(-)

std/os/bits/linux/arm-eabi.zig+24
......@@ -474,6 +474,30 @@ pub const VDSO_USEFUL = true;
474474pub const VDSO_CGT_SYM = "__vdso_clock_gettime";
475475pub const VDSO_CGT_VER = "LINUX_2.6";
476476
477pub const HWCAP_SWP = 1 << 0;
478pub const HWCAP_HALF = 1 << 1;
479pub const HWCAP_THUMB = 1 << 2;
480pub const HWCAP_26BIT = 1 << 3;
481pub const HWCAP_FAST_MULT = 1 << 4;
482pub const HWCAP_FPA = 1 << 5;
483pub const HWCAP_VFP = 1 << 6;
484pub const HWCAP_EDSP = 1 << 7;
485pub const HWCAP_JAVA = 1 << 8;
486pub const HWCAP_IWMMXT = 1 << 9;
487pub const HWCAP_CRUNCH = 1 << 10;
488pub const HWCAP_THUMBEE = 1 << 11;
489pub const HWCAP_NEON = 1 << 12;
490pub const HWCAP_VFPv3 = 1 << 13;
491pub const HWCAP_VFPv3D16 = 1 << 14;
492pub const HWCAP_TLS = 1 << 15;
493pub const HWCAP_VFPv4 = 1 << 16;
494pub const HWCAP_IDIVA = 1 << 17;
495pub const HWCAP_IDIVT = 1 << 18;
496pub const HWCAP_VFPD32 = 1 << 19;
497pub const HWCAP_IDIV = HWCAP_IDIVA | HWCAP_IDIVT;
498pub const HWCAP_LPAE = 1 << 20;
499pub const HWCAP_EVTSTRM = 1 << 21;
500
477501pub const msghdr = extern struct {
478502 msg_name: ?*sockaddr,
479503 msg_namelen: socklen_t,
std/os/linux/arm-eabi.zig+8
......@@ -78,3 +78,11 @@ pub fn syscall6(
7878
7979/// This matches the libc clone function.
8080pub extern fn clone(func: extern fn (arg: usize) u8, stack: usize, flags: u32, arg: usize, ptid: *i32, tls: usize, ctid: *i32) usize;
81
82// LLVM calls this when the read-tp-hard feature is set to false. Currently, there is no way to pass
83// that to llvm via zig. See https://github.com/ziglang/zig/issues/2883
84pub nakedcc fn getThreadPointer() usize {
85 return asm volatile("mrc p15, 0, %[ret], c13, c0, 3"
86 : [ret] "=r" (-> usize)
87 );
88}
\ No newline at end of file
std/os/linux/tls.zig+12
......@@ -133,6 +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;
136137
137138 var i: usize = 0;
138139 while (auxv[i].a_type != std.elf.AT_NULL) : (i += 1) {
......@@ -140,10 +141,21 @@ pub fn initTLS() void {
140141 elf.AT_PHENT => at_phent = auxv[i].a_un.a_val,
141142 elf.AT_PHNUM => at_phnum = auxv[i].a_un.a_val,
142143 elf.AT_PHDR => at_phdr = auxv[i].a_un.a_val,
144 elf.AT_HWCAP => at_phdr = auxv[i].a_un.a_val,
143145 else => continue,
144146 }
145147 }
146148
149 // If the cpu is arm-based, check if it supports the TLS register
150 if (builtin.arch == builtin.Arch.arm and builtin.os == .linux) {
151 if (at_hwcap & std.os.linux.HWCAP_TLS == 0) {
152 // If the CPU does not support TLS via a coprocessor register,
153 // it could be accessed via a kernel helper function
154 // see musl/src/thread/arm/ for details
155 @panic("cpu does not support TLS via coprocessor register");
156 }
157 }
158
147159 // Sanity check
148160 assert(at_phent == @sizeOf(elf.Phdr));
149161
std/special/c.zig+2
......@@ -25,6 +25,8 @@ comptime {
2525 @export("strncmp", strncmp, .Strong);
2626 @export("strerror", strerror, .Strong);
2727 @export("strlen", strlen, .Strong);
28 } else if (builtin.arch == builtin.Arch.arm and builtin.os == .linux) {
29 @export("__aeabi_read_tp", std.os.linux.getThreadPointer, .Strong);
2830 }
2931}
3032