diff options
| author | Jakub Konka <kubkon@jakubkonka.com> | 2024-05-23 14:21:31 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-05-23 14:21:31 +0200 |
| commit | fb88cfdf6aa3fabba700d8340f025e4a3e0d3fb2 (patch) | |
| tree | f613ac6f06fe2cb46c58cd55eb1eaaee09990e07 /src/link/MachO/Relocation.zig | |
| parent | 9be8a9000faead40b1aec4877506ff10b066659c (diff) | |
| parent | d31eb744cec1d991def2d6d42a14ded82af1dbbe (diff) | |
| download | zig-fb88cfdf6aa3fabba700d8340f025e4a3e0d3fb2.tar.gz zig-fb88cfdf6aa3fabba700d8340f025e4a3e0d3fb2.zip | |
Merge pull request #20032 from ziglang/macho-literals
link/macho: implement logic for merging literals
Diffstat (limited to 'src/link/MachO/Relocation.zig')
| -rw-r--r-- | src/link/MachO/Relocation.zig | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/link/MachO/Relocation.zig b/src/link/MachO/Relocation.zig index 2df9355de9..425171a463 100644 --- a/src/link/MachO/Relocation.zig +++ b/src/link/MachO/Relocation.zig @@ -60,6 +60,59 @@ pub fn lessThan(ctx: void, lhs: Relocation, rhs: Relocation) bool { return lhs.offset < rhs.offset; } +const FormatCtx = struct { Relocation, std.Target.Cpu.Arch }; + +pub fn fmtPretty(rel: Relocation, cpu_arch: std.Target.Cpu.Arch) std.fmt.Formatter(formatPretty) { + return .{ .data = .{ rel, cpu_arch } }; +} + +fn formatPretty( + ctx: FormatCtx, + comptime unused_fmt_string: []const u8, + options: std.fmt.FormatOptions, + writer: anytype, +) !void { + _ = options; + _ = unused_fmt_string; + const rel, const cpu_arch = ctx; + const str = switch (rel.type) { + .signed => "X86_64_RELOC_SIGNED", + .signed1 => "X86_64_RELOC_SIGNED_1", + .signed2 => "X86_64_RELOC_SIGNED_2", + .signed4 => "X86_64_RELOC_SIGNED_4", + .got_load => "X86_64_RELOC_GOT_LOAD", + .tlv => "X86_64_RELOC_TLV", + .zig_got_load => "ZIG_GOT_LOAD", + .page => "ARM64_RELOC_PAGE21", + .pageoff => "ARM64_RELOC_PAGEOFF12", + .got_load_page => "ARM64_RELOC_GOT_LOAD_PAGE21", + .got_load_pageoff => "ARM64_RELOC_GOT_LOAD_PAGEOFF12", + .tlvp_page => "ARM64_RELOC_TLVP_LOAD_PAGE21", + .tlvp_pageoff => "ARM64_RELOC_TLVP_LOAD_PAGEOFF12", + .branch => switch (cpu_arch) { + .x86_64 => "X86_64_RELOC_BRANCH", + .aarch64 => "ARM64_RELOC_BRANCH26", + else => unreachable, + }, + .got => switch (cpu_arch) { + .x86_64 => "X86_64_RELOC_GOT", + .aarch64 => "ARM64_RELOC_POINTER_TO_GOT", + else => unreachable, + }, + .subtractor => switch (cpu_arch) { + .x86_64 => "X86_64_RELOC_SUBTRACTOR", + .aarch64 => "ARM64_RELOC_SUBTRACTOR", + else => unreachable, + }, + .unsigned => switch (cpu_arch) { + .x86_64 => "X86_64_RELOC_UNSIGNED", + .aarch64 => "ARM64_RELOC_UNSIGNED", + else => unreachable, + }, + }; + try writer.writeAll(str); +} + pub const Type = enum { // x86_64 /// RIP-relative displacement (X86_64_RELOC_SIGNED) |
