authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2019-05-07 13:08:19+02:00
committergravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2019-05-07 13:09:20+02:00
logb1db696c10f3895d59d26ddfb4f2ef7a6e7384fb
treef29cb394f1aaef0b4c4b3e33095801764d0462bd
parent2f041239cb0c14c8c8e416ed799a3bacb2470fde

Less error messages

Decrease the overall size of the binary, programming errors are caught with unreachable.

1 files changed, 24 insertions(+), 27 deletions(-)

std/os/linux/tls.zig+24-27
...@@ -128,36 +128,33 @@ pub fn initTLS() void {...@@ -128,36 +128,33 @@ pub fn initTLS() void {
128 var tls_phdr: ?*elf.Phdr = null;128 var tls_phdr: ?*elf.Phdr = null;
129 var img_base: usize = 0;129 var img_base: usize = 0;
130130
131 if (std.os.linux_elf_aux_maybe) |auxv| {131 const auxv = std.os.linux_elf_aux_maybe.?;
132 var at_phent: usize = undefined;132 var at_phent: usize = undefined;
133 var at_phnum: usize = undefined;133 var at_phnum: usize = undefined;
134 var at_phdr: usize = undefined;134 var at_phdr: usize = undefined;
135135
136 var i: usize = 0;136 var i: usize = 0;
137 while (auxv[i].a_type != std.elf.AT_NULL) : (i += 1) {137 while (auxv[i].a_type != std.elf.AT_NULL) : (i += 1) {
138 switch (auxv[i].a_type) {138 switch (auxv[i].a_type) {
139 elf.AT_PHENT => at_phent = auxv[i].a_un.a_val,139 elf.AT_PHENT => at_phent = auxv[i].a_un.a_val,
140 elf.AT_PHNUM => at_phnum = auxv[i].a_un.a_val,140 elf.AT_PHNUM => at_phnum = auxv[i].a_un.a_val,
141 elf.AT_PHDR => at_phdr = auxv[i].a_un.a_val,141 elf.AT_PHDR => at_phdr = auxv[i].a_un.a_val,
142 else => continue,142 else => continue,
143 }
144 }143 }
144 }
145145
146 // Sanity check146 // Sanity check
147 assert(at_phent == @sizeOf(elf.Phdr));147 assert(at_phent == @sizeOf(elf.Phdr));
148148
149 // Search the TLS section149 // Search the TLS section
150 const phdrs = (@intToPtr([*]elf.Phdr, at_phdr))[0..at_phnum];150 const phdrs = (@intToPtr([*]elf.Phdr, at_phdr))[0..at_phnum];
151151
152 for (phdrs) |*phdr| {152 for (phdrs) |*phdr| {
153 switch (phdr.p_type) {153 switch (phdr.p_type) {
154 elf.PT_PHDR => img_base = at_phdr - phdr.p_vaddr,154 elf.PT_PHDR => img_base = at_phdr - phdr.p_vaddr,
155 elf.PT_TLS => tls_phdr = phdr,155 elf.PT_TLS => tls_phdr = phdr,
156 else => continue,156 else => continue,
157 }
158 }157 }
159 } else {
160 @panic("no auxv vector available!");
161 }158 }
162159
163 if (tls_phdr) |phdr| {160 if (tls_phdr) |phdr| {
...@@ -212,7 +209,7 @@ pub fn initTLS() void {...@@ -212,7 +209,7 @@ pub fn initTLS() void {
212}209}
213210
214pub fn copyTLS(addr: usize) usize {211pub fn copyTLS(addr: usize) usize {
215 const tls_img = tls_image orelse @panic("copyTLS called with no TLS section!");212 const tls_img = tls_image.?;
216213
217 // Be paranoid, clear the area we're going to use214 // Be paranoid, clear the area we're going to use
218 @memset(@intToPtr([*]u8, addr), 0, tls_img.alloc_size);215 @memset(@intToPtr([*]u8, addr), 0, tls_img.alloc_size);
...@@ -245,7 +242,7 @@ pub fn allocateTLS(size: usize) usize {...@@ -245,7 +242,7 @@ pub fn allocateTLS(size: usize) usize {
245 const addr = posix.mmap(null, size, posix.PROT_READ | posix.PROT_WRITE,242 const addr = posix.mmap(null, size, posix.PROT_READ | posix.PROT_WRITE,
246 posix.MAP_PRIVATE | posix.MAP_ANONYMOUS, -1, 0);243 posix.MAP_PRIVATE | posix.MAP_ANONYMOUS, -1, 0);
247244
248 if (posix.getErrno(addr) != 0) @panic("allocateTLS failed to allocate memory");245 if (posix.getErrno(addr) != 0) @panic("out of memory");
249246
250 return addr;247 return addr;
251}248}