authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-07-29 12:19:15+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-07-30 02:32:32+02:00
log37275c0f69769774ba4f1fc577b04aa36e24ac6f
treed5358a73be657652d218d8b037e7838dc34d75ee
parentb52e05426160c193c29e01072736a319e5fb6f24
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

std.os.linux.tls: Fix layout computation for the modified Variant I.


1 files changed, 19 insertions(+), 1 deletions(-)

lib/std/os/linux/tls.zig+19-1
...@@ -313,7 +313,7 @@ fn computeAreaDesc(phdrs: []elf.Phdr) void {...@@ -313,7 +313,7 @@ fn computeAreaDesc(phdrs: []elf.Phdr) void {
313 // Compute the total size of the ABI-specific data plus our own `ZigTcb` structure. All the313 // Compute the total size of the ABI-specific data plus our own `ZigTcb` structure. All the
314 // offsets calculated here assume a well-aligned base address.314 // offsets calculated here assume a well-aligned base address.
315 const area_size = switch (current_variant) {315 const area_size = switch (current_variant) {
316 .I_original, .I_modified => blk: {316 .I_original => blk: {
317 var l: usize = 0;317 var l: usize = 0;
318 dtv_offset = l;318 dtv_offset = l;
319 l += @sizeOf(Dtv);319 l += @sizeOf(Dtv);
...@@ -330,6 +330,24 @@ fn computeAreaDesc(phdrs: []elf.Phdr) void {...@@ -330,6 +330,24 @@ fn computeAreaDesc(phdrs: []elf.Phdr) void {
330 l += block_size;330 l += block_size;
331 break :blk l;331 break :blk l;
332 },332 },
333 .I_modified => blk: {
334 var l: usize = 0;
335 dtv_offset = l;
336 l += @sizeOf(Dtv);
337 // In this variant, the TLS blocks must begin immediately after the end of the ABI TCB,
338 // with the TP pointing to the beginning of the TLS blocks. Add padding so that the TP
339 // (`abi_tcb_offset`) is aligned to `align_factor` and the `ZigTcb` structure can be
340 // found by subtracting `@sizeOf(AbiTcb) + @sizeOf(ZigTcb)` from the TP.
341 const delta = (l + @sizeOf(ZigTcb) + @sizeOf(AbiTcb)) & (align_factor - 1);
342 if (delta > 0)
343 l += align_factor - delta;
344 l += @sizeOf(ZigTcb);
345 abi_tcb_offset = l;
346 l += @sizeOf(AbiTcb);
347 block_offset = l;
348 l += block_size;
349 break :blk l;
350 },
333 .II => blk: {351 .II => blk: {
334 var l: usize = 0;352 var l: usize = 0;
335 block_offset = l;353 block_offset = l;