Skip to content

Commit

Permalink
Object: use alignCast with fieldParentPtr when necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
ehaas committed Apr 1, 2024
1 parent cc7a904 commit 5e780e2
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/backend/Object.zig
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub fn create(gpa: Allocator, target: std.Target) !*Object {

pub fn deinit(obj: *Object) void {
switch (obj.format) {
.elf => @as(*Elf, @fieldParentPtr("obj", obj)).deinit(),
.elf => @as(*Elf, @alignCast(@fieldParentPtr("obj", obj))).deinit(),
else => unreachable,
}
}
Expand All @@ -32,7 +32,7 @@ pub const Section = union(enum) {

pub fn getSection(obj: *Object, section: Section) !*std.ArrayList(u8) {
switch (obj.format) {
.elf => return @as(*Elf, @fieldParentPtr("obj", obj)).getSection(section),
.elf => return @as(*Elf, @alignCast(@fieldParentPtr("obj", obj))).getSection(section),
else => unreachable,
}
}
Expand All @@ -53,21 +53,21 @@ pub fn declareSymbol(
size: u64,
) ![]const u8 {
switch (obj.format) {
.elf => return @as(*Elf, @fieldParentPtr("obj", obj)).declareSymbol(section, name, linkage, @"type", offset, size),
.elf => return @as(*Elf, @alignCast(@fieldParentPtr("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 @as(*Elf, @fieldParentPtr("obj", obj)).addRelocation(name, section, address, addend),
.elf => return @as(*Elf, @alignCast(@fieldParentPtr("obj", obj))).addRelocation(name, section, address, addend),
else => unreachable,
}
}

pub fn finish(obj: *Object, file: std.fs.File) !void {
switch (obj.format) {
.elf => return @as(*Elf, @fieldParentPtr("obj", obj)).finish(file),
.elf => return @as(*Elf, @alignCast(@fieldParentPtr("obj", obj))).finish(file),
else => unreachable,
}
}

0 comments on commit 5e780e2

Please sign in to comment.