Commit b343103567

Jakub Konka <kubkon@jakubkonka.com>
2024-03-08 14:43:23
elf+aarch64: handle gottp and .tls_common
1 parent 7258d14
Changed files (1)
src
link
src/link/Elf/Atom.zig
@@ -1628,6 +1628,12 @@ const aarch64 = struct {
                 if (is_dyn_lib) try atom.reportPicError(symbol, rel, elf_file);
             },
 
+            .TLSIE_ADR_GOTTPREL_PAGE21,
+            .TLSIE_LD64_GOTTPREL_LO12_NC,
+            => {
+                symbol.flags.needs_gottp = true;
+            },
+
             .TLSDESC_ADR_PAGE21,
             .TLSDESC_LD64_LO12,
             .TLSDESC_ADD_LO12,
@@ -1769,6 +1775,23 @@ const aarch64 = struct {
                 aarch64_util.writeAddImmInst(@bitCast(value), code);
             },
 
+            .TLSIE_ADR_GOTTPREL_PAGE21 => {
+                const S_: i64 = @intCast(target.gotTpAddress(elf_file));
+                const saddr: u64 = @intCast(P);
+                const taddr: u64 = @intCast(S_ + A);
+                relocs_log.debug("      [{x} => {x}]", .{ P, taddr });
+                const pages: u21 = @bitCast(try aarch64_util.calcNumberOfPages(saddr, taddr));
+                aarch64_util.writeAdrpInst(pages, code);
+            },
+
+            .TLSIE_LD64_GOTTPREL_LO12_NC => {
+                const S_: i64 = @intCast(target.gotTpAddress(elf_file));
+                const taddr: u64 = @intCast(S_ + A);
+                relocs_log.debug("      [{x} => {x}]", .{ P, taddr });
+                const offset: u12 = try math.divExact(u12, @truncate(taddr), 8);
+                aarch64_util.writeLoadStoreRegInst(offset, code);
+            },
+
             .TLSDESC_ADR_PAGE21 => {
                 if (target.flags.has_tlsdesc) {
                     const S_: i64 = @intCast(target.tlsDescAddress(elf_file));