diff options
| author | Jakub Konka <kubkon@jakubkonka.com> | 2023-10-09 22:31:52 +0200 |
|---|---|---|
| committer | Jakub Konka <kubkon@jakubkonka.com> | 2023-10-16 19:33:05 +0200 |
| commit | 0b37a9c78d5b554fa137cfd5c66c756cf4a64893 (patch) | |
| tree | 7886c25492c4541c73fed6b0ddc10f99c9de14b3 /src | |
| parent | 898c87bd2ab7d49fbbcb1d01e6b72fec54bdfd09 (diff) | |
| download | zig-0b37a9c78d5b554fa137cfd5c66c756cf4a64893.tar.gz zig-0b37a9c78d5b554fa137cfd5c66c756cf4a64893.zip | |
elf: fix GotSection.write in presence of TLSLD symbol
Diffstat (limited to 'src')
| -rw-r--r-- | src/link/Elf/synthetic_sections.zig | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/src/link/Elf/synthetic_sections.zig b/src/link/Elf/synthetic_sections.zig index 1f336043e8..e8a9334fa3 100644 --- a/src/link/Elf/synthetic_sections.zig +++ b/src/link/Elf/synthetic_sections.zig @@ -366,15 +366,18 @@ pub const GotSection = struct { const apply_relocs = true; // TODO add user option for this for (got.entries.items) |entry| { - const symbol = elf_file.symbol(entry.symbol_index); + const symbol = switch (entry.tag) { + .tlsld => null, + inline else => elf_file.symbol(entry.symbol_index), + }; switch (entry.tag) { .got => { const value = blk: { - const value = symbol.address(.{ .plt = false }, elf_file); - if (symbol.flags.import) break :blk 0; - if (symbol.isIFunc(elf_file)) + const value = symbol.?.address(.{ .plt = false }, elf_file); + if (symbol.?.flags.import) break :blk 0; + if (symbol.?.isIFunc(elf_file)) break :blk if (apply_relocs) value else 0; - if (elf_file.base.options.pic and !symbol.isAbs(elf_file)) + if (elf_file.base.options.pic and !symbol.?.isAbs(elf_file)) break :blk if (apply_relocs) value else 0; break :blk value; }; @@ -385,26 +388,26 @@ pub const GotSection = struct { try writeInt(0, elf_file, writer); }, .tlsgd => { - if (symbol.flags.import) { + if (symbol.?.flags.import) { try writeInt(0, elf_file, writer); try writeInt(0, elf_file, writer); } else { try writeInt(if (is_dyn_lib) @as(u64, 0) else 1, elf_file, writer); - const offset = symbol.address(.{}, elf_file) - elf_file.dtpAddress(); + const offset = symbol.?.address(.{}, elf_file) - elf_file.dtpAddress(); try writeInt(offset, elf_file, writer); } }, .gottp => { - if (symbol.flags.import) { + if (symbol.?.flags.import) { try writeInt(0, elf_file, writer); } else if (is_dyn_lib) { const offset = if (apply_relocs) - symbol.address(.{}, elf_file) - elf_file.tlsAddress() + symbol.?.address(.{}, elf_file) - elf_file.tlsAddress() else 0; try writeInt(offset, elf_file, writer); } else { - const offset = @as(i64, @intCast(symbol.address(.{}, elf_file))) - + const offset = @as(i64, @intCast(symbol.?.address(.{}, elf_file))) - @as(i64, @intCast(elf_file.tpAddress())); try writeInt(offset, elf_file, writer); } |
