diff options
| author | Veikka Tuominen <git@vexu.eu> | 2023-10-02 07:08:53 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-10-02 07:08:53 +0300 |
| commit | fc4d53e2ea6b41440e37caf32d2fd236d0f58c93 (patch) | |
| tree | be400bc7033d3f198978ad04c05c14f15b8c5324 /deps/aro/Object.zig | |
| parent | 0f1652dc603ad43be733cfdd721cedf38d9e45d9 (diff) | |
| parent | 5792570197f44b2c7599fb756f5c1e9d59bd0a9a (diff) | |
| download | zig-fc4d53e2ea6b41440e37caf32d2fd236d0f58c93.tar.gz zig-fc4d53e2ea6b41440e37caf32d2fd236d0f58c93.zip | |
Merge pull request #17221 from Vexu/aro-translate-c
Aro translate-c
Diffstat (limited to 'deps/aro/Object.zig')
| -rw-r--r-- | deps/aro/Object.zig | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/deps/aro/Object.zig b/deps/aro/Object.zig new file mode 100644 index 0000000000..d739c16764 --- /dev/null +++ b/deps/aro/Object.zig @@ -0,0 +1,73 @@ +const std = @import("std"); +const Compilation = @import("Compilation.zig"); +const Elf = @import("object/Elf.zig"); + +const Object = @This(); + +format: std.Target.ObjectFormat, +comp: *Compilation, + +pub fn create(comp: *Compilation) !*Object { + switch (comp.target.ofmt) { + .elf => return Elf.create(comp), + else => unreachable, + } +} + +pub fn deinit(obj: *Object) void { + switch (obj.format) { + .elf => @fieldParentPtr(Elf, "obj", obj).deinit(), + else => unreachable, + } +} + +pub const Section = union(enum) { + undefined, + data, + read_only_data, + func, + strings, + custom: []const u8, +}; + +pub fn getSection(obj: *Object, section: Section) !*std.ArrayList(u8) { + switch (obj.format) { + .elf => return @fieldParentPtr(Elf, "obj", obj).getSection(section), + else => unreachable, + } +} + +pub const SymbolType = enum { + func, + variable, + external, +}; + +pub fn declareSymbol( + obj: *Object, + section: Section, + name: ?[]const u8, + linkage: std.builtin.GlobalLinkage, + @"type": SymbolType, + offset: u64, + size: u64, +) ![]const u8 { + switch (obj.format) { + .elf => return @fieldParentPtr(Elf, "obj", obj).declareSymbol(section, name, linkage, @"type", offset, size), + else => unreachable, + } +} + +pub fn addRelocation(obj: *Object, name: []const u8, section: Section, address: u64, addend: i64) !void { + switch (obj.format) { + .elf => return @fieldParentPtr(Elf, "obj", obj).addRelocation(name, section, address, addend), + else => unreachable, + } +} + +pub fn finish(obj: *Object, file: std.fs.File) !void { + switch (obj.format) { + .elf => return @fieldParentPtr(Elf, "obj", obj).finish(file), + else => unreachable, + } +} |
