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 {...@@ -634,8 +634,17 @@ pub const GotSection = struct {
634 }634 }
635 },635 },
636 .tlsdesc => {636 .tlsdesc => {
637 try writeInt(0, elf_file, writer);637 if (symbol.?.flags.import) {
638 try writeInt(0, elf_file, writer);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 }
639 },648 },
640 }649 }
641 }650 }
...@@ -738,8 +747,9 @@ pub const GotSection = struct {...@@ -738,8 +747,9 @@ pub const GotSection = struct {
738 const offset = symbol.?.tlsDescAddress(elf_file);747 const offset = symbol.?.tlsDescAddress(elf_file);
739 elf_file.addRelaDynAssumeCapacity(.{748 elf_file.addRelaDynAssumeCapacity(.{
740 .offset = offset,749 .offset = offset,
741 .sym = extra.?.dynamic,750 .sym = if (symbol.?.flags.import) extra.?.dynamic else 0,
742 .type = relocation.encode(.tlsdesc, cpu_arch),751 .type = relocation.encode(.tlsdesc, cpu_arch),
752 .addend = if (symbol.?.flags.import) 0 else @intCast(symbol.?.address(.{}, elf_file) - elf_file.tlsAddress()),
743 });753 });
744 },754 },
745 }755 }