lib/choir/src/backends/artifact/model/linkage/relocation.zig
daab053ee43316e1809a84551d573ddd1e5bf3d2
1 const std = @import("std");
2 const linkage = @import("root.zig");
3
4 const Allocator = std.mem.Allocator;
5
6 pub const RelocationKind = enum(u8) {
7 unknown = 1,
8 call = 2,
9 absolute = 3,
10 relative = 4,
11 got = 5,
12 plt = 6,
13 };
14
15 pub const Relocation = struct {
16 offset: u64,
17 symbol: []const u8,
18 kind: RelocationKind = .unknown,
19 addend: i64 = 0,
20 width_bits: ?u16 = null,
21
22 pub fn dupe(self: Relocation, allocator: Allocator) Allocator.Error!Relocation {
23 return .{
24 .offset = self.offset,
25 .symbol = try linkage.slice.dupe(allocator, self.symbol),
26 .kind = self.kind,
27 .addend = self.addend,
28 .width_bits = self.width_bits,
29 };
30 }
31
32 pub fn deinit(self: Relocation, allocator: Allocator) void {
33 linkage.slice.free(allocator, self.symbol);
34 }
35
36 pub fn eql(self: Relocation, other: Relocation) bool {
37 return self.offset == other.offset and
38 self.kind == other.kind and
39 self.addend == other.addend and
40 self.width_bits == other.width_bits and
41 std.mem.eql(u8, self.symbol, other.symbol);
42 }
43 };