authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-03-08 14:38:21+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-03-08 22:46:17+01:00
log7258d143e355f6bd92797cdb193c2b1ad2a1650d
tree650ad29890e808d52ac69f478cdd29e1e49037e0
parentb5642b4f85e7962ee7eb3d137e47fadf392a865b

elf+aarch64: fix incorrectly emitted TLSDESC relocs


1 files changed, 13 insertions(+), 3 deletions(-)

src/link/Elf/synthetic_sections.zig+13-3
......@@ -634,8 +634,17 @@ pub const GotSection = struct {
634634 }
635635 },
636636 .tlsdesc => {
637 try writeInt(0, elf_file, writer);
638 try writeInt(0, elf_file, writer);
637 if (symbol.?.flags.import) {
638 try writeInt(0, elf_file, writer);
639 try writeInt(0, elf_file, writer);
640 } else {
641 try writeInt(0, elf_file, writer);
642 const offset = if (apply_relocs)
643 @as(i64, @intCast(symbol.?.address(.{}, elf_file))) - @as(i64, @intCast(elf_file.tlsAddress()))
644 else
645 0;
646 try writeInt(offset, elf_file, writer);
647 }
639648 },
640649 }
641650 }
......@@ -738,8 +747,9 @@ pub const GotSection = struct {
738747 const offset = symbol.?.tlsDescAddress(elf_file);
739748 elf_file.addRelaDynAssumeCapacity(.{
740749 .offset = offset,
741 .sym = extra.?.dynamic,
750 .sym = if (symbol.?.flags.import) extra.?.dynamic else 0,
742751 .type = relocation.encode(.tlsdesc, cpu_arch),
752 .addend = if (symbol.?.flags.import) 0 else @intCast(symbol.?.address(.{}, elf_file) - elf_file.tlsAddress()),
743753 });
744754 },
745755 }