authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2020-12-18 09:15:17+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-12-18 14:22:30-05:00
logce65533985caa9e2da567948e36d7d4ba0185005
treead9a50fd42fcd366185216eff120dc80753cde1a
parentad055099309d0faeb2725764ec441b1ee847ecbf

std: Properly fix the TLS alignment problem

ad05509 introduced a fix for the wrong problem, the logic to align the start of main_thread_tls_buffer was already there but was flawed. Fix it for good and avoid wasting too many bytes for alignment purposes.

1 files changed, 4 insertions(+), 2 deletions(-)

lib/std/os/linux/tls.zig+4-2
......@@ -327,7 +327,7 @@ pub fn prepareTLS(area: []u8) usize {
327327 if (tls_tp_points_past_tcb) tls_image.data_offset else tls_image.tcb_offset;
328328}
329329
330var main_thread_tls_buffer: [256]u8 align(16) = undefined;
330var main_thread_tls_buffer: [256]u8 = undefined;
331331
332332pub fn initStaticTLS() void {
333333 initTLS();
......@@ -351,7 +351,9 @@ pub fn initStaticTLS() void {
351351 };
352352
353353 // Make sure the slice is correctly aligned
354 const start = @ptrToInt(alloc_tls_area.ptr) & (tls_image.alloc_align - 1);
354 const begin_addr = @ptrToInt(alloc_tls_area.ptr);
355 const begin_aligned_addr = mem.alignForward(begin_addr, tls_image.alloc_align);
356 const start = begin_aligned_addr - begin_addr;
355357 const tls_area = alloc_tls_area[start .. start + tls_image.alloc_size];
356358
357359 const tp_value = prepareTLS(tls_area);