authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-02-21 22:07:51+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-02-21 22:07:51+01:00
logd7d47a2c0c1585885d6ba45beb10744af48c2092
tree357e2cba04201d04804280f7a8b04fb328331a8f
parentee364d542a91293fc048ea47dd8530f824916e5a

elf+aarch64: implement some scanReloc logic


1 files changed, 59 insertions(+), 0 deletions(-)

src/link/Elf/Atom.zig+59
...@@ -438,6 +438,10 @@ pub fn scanRelocs(self: Atom, elf_file: *Elf, code: ?[]const u8, undefs: anytype...@@ -438,6 +438,10 @@ pub fn scanRelocs(self: Atom, elf_file: *Elf, code: ?[]const u8, undefs: anytype
438 error.RelocFailure => has_reloc_errors = true,438 error.RelocFailure => has_reloc_errors = true,
439 else => |e| return e,439 else => |e| return e,
440 },440 },
441 .aarch64 => aarch64.scanReloc(self, elf_file, rel, symbol, code, &it) catch |err| switch (err) {
442 error.RelocFailure => has_reloc_errors = true,
443 else => |e| return e,
444 },
441 else => return error.UnsupportedCpuArch,445 else => return error.UnsupportedCpuArch,
442 }446 }
443 }447 }
...@@ -1549,6 +1553,61 @@ const x86_64 = struct {...@@ -1549,6 +1553,61 @@ const x86_64 = struct {
1549 const Instruction = encoder.Instruction;1553 const Instruction = encoder.Instruction;
1550};1554};
15511555
1556const aarch64 = struct {
1557 fn scanReloc(
1558 atom: Atom,
1559 elf_file: *Elf,
1560 rel: elf.Elf64_Rela,
1561 symbol: *Symbol,
1562 code: ?[]const u8,
1563 it: *RelocsIterator,
1564 ) !void {
1565 _ = code;
1566 _ = it;
1567
1568 const r_type: elf.R_AARCH64 = @enumFromInt(rel.r_type());
1569 switch (r_type) {
1570 .ABS64 => {
1571 try atom.scanReloc(symbol, rel, dynAbsRelocAction(symbol, elf_file), elf_file);
1572 },
1573
1574 .ADR_PREL_PG_HI21 => {
1575 try atom.scanReloc(symbol, rel, pcRelocAction(symbol, elf_file), elf_file);
1576 },
1577
1578 .ADR_GOT_PAGE => {
1579 // TODO: relax if possible
1580 symbol.flags.needs_got = true;
1581 },
1582
1583 .LD64_GOT_LO12_NC,
1584 .LD64_GOTPAGE_LO15,
1585 => {
1586 symbol.flags.needs_got = true;
1587 },
1588
1589 .CALL26,
1590 .JUMP26,
1591 => {
1592 if (symbol.flags.import) {
1593 symbol.flags.needs_plt = true;
1594 }
1595 },
1596
1597 .ADD_ABS_LO12_NC,
1598 .ADR_PREL_LO21,
1599 .LDST8_ABS_LO12_NC,
1600 .LDST16_ABS_LO12_NC,
1601 .LDST32_ABS_LO12_NC,
1602 .LDST64_ABS_LO12_NC,
1603 .LDST128_ABS_LO12_NC,
1604 => {},
1605
1606 else => try atom.reportUnhandledRelocError(rel, elf_file),
1607 }
1608 }
1609};
1610
1552const ResolveArgs = struct { i64, i64, i64, i64, i64, i64, i64, i64 };1611const ResolveArgs = struct { i64, i64, i64, i64, i64, i64, i64, i64 };
15531612
1554const RelocError = error{1613const RelocError = error{