Skip to content

Commit

Permalink
elf+aarch64: handle gottp and .tls_common
Browse files Browse the repository at this point in the history
  • Loading branch information
kubkon committed Feb 26, 2024
1 parent 22a9d23 commit 0995d99
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
23 changes: 23 additions & 0 deletions src/Elf/Atom.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1249,6 +1249,12 @@ const aarch64 = struct {
if (is_shared) try atom.picError(symbol, rel, elf_file);
},

.TLSIE_ADR_GOTTPREL_PAGE21,
.TLSIE_LD64_GOTTPREL_LO12_NC,
=> {
symbol.flags.gottp = true;
},

.TLSDESC_ADR_PAGE21,
.TLSDESC_LD64_LO12,
.TLSDESC_ADD_LO12,
Expand Down Expand Up @@ -1390,6 +1396,23 @@ const aarch64 = struct {
aarch64_util.writeAddImmInst(@bitCast(value), code);
},

.TLSIE_ADR_GOTTPREL_PAGE21 => {
const S_: i64 = @intCast(target.getGotTpAddress(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.getGotTpAddress(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.tlsdesc) {
const S_: i64 = @intCast(target.getTlsDescAddress(elf_file));
Expand Down
1 change: 0 additions & 1 deletion test/elf.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2059,7 +2059,6 @@ fn testStrip(b: *Build, opts: Options) *Step {
fn testTlsCommon(b: *Build, opts: Options) *Step {
const test_step = b.step("test-elf-tls-common", "");

if (builtin.target.cpu.arch == .aarch64) return skipTestStep(test_step);
if (opts.system_compiler != .gcc) return skipTestStep(test_step);

const a_o = cc(b, "a.o", opts);
Expand Down

0 comments on commit 0995d99

Please sign in to comment.