aboutsummaryrefslogtreecommitdiff
path: root/src/link/Elf/Object.zig
diff options
context:
space:
mode:
authorJakub Konka <kubkon@jakubkonka.com>2024-02-16 12:43:37 +0100
committerJakub Konka <kubkon@jakubkonka.com>2024-02-16 21:54:43 +0100
commitfc7dd3e285889cd0f75e7270bb0021ad32f73ca3 (patch)
treef3417c9239b2a45148564fbbb16eef9c2826dc28 /src/link/Elf/Object.zig
parent88d4b5cb18bdc68099162f1db8103d614025659c (diff)
downloadzig-fc7dd3e285889cd0f75e7270bb0021ad32f73ca3.tar.gz
zig-fc7dd3e285889cd0f75e7270bb0021ad32f73ca3.zip
elf: enable adding support for additional cpu archs
Diffstat (limited to 'src/link/Elf/Object.zig')
-rw-r--r--src/link/Elf/Object.zig36
1 files changed, 23 insertions, 13 deletions
diff --git a/src/link/Elf/Object.zig b/src/link/Elf/Object.zig
index b29de3fc59..92485ae20b 100644
--- a/src/link/Elf/Object.zig
+++ b/src/link/Elf/Object.zig
@@ -55,6 +55,7 @@ pub fn deinit(self: *Object, allocator: Allocator) void {
pub fn parse(self: *Object, elf_file: *Elf) !void {
const gpa = elf_file.base.comp.gpa;
+ const cpu_arch = elf_file.getTarget().cpu.arch;
const handle = elf_file.fileHandle(self.file_handle);
try self.parseCommon(gpa, handle, elf_file);
@@ -64,8 +65,11 @@ pub fn parse(self: *Object, elf_file: *Elf) !void {
for (self.shdrs.items, 0..) |shdr, i| {
const atom = elf_file.atom(self.atoms.items[i]) orelse continue;
if (!atom.flags.alive) continue;
- if (shdr.sh_type == elf.SHT_X86_64_UNWIND or mem.eql(u8, atom.name(elf_file), ".eh_frame"))
+ if ((cpu_arch == .x86_64 and shdr.sh_type == elf.SHT_X86_64_UNWIND) or
+ mem.eql(u8, atom.name(elf_file), ".eh_frame"))
+ {
try self.parseEhFrame(gpa, handle, @as(u32, @intCast(i)), elf_file);
+ }
}
}
@@ -286,17 +290,22 @@ fn initOutputSection(self: Object, elf_file: *Elf, shdr: elf.Elf64_Shdr) error{O
}
break :blk name;
};
- const @"type" = switch (shdr.sh_type) {
- elf.SHT_NULL => unreachable,
- elf.SHT_PROGBITS => blk: {
- if (std.mem.eql(u8, name, ".init_array") or std.mem.startsWith(u8, name, ".init_array."))
- break :blk elf.SHT_INIT_ARRAY;
- if (std.mem.eql(u8, name, ".fini_array") or std.mem.startsWith(u8, name, ".fini_array."))
- break :blk elf.SHT_FINI_ARRAY;
- break :blk shdr.sh_type;
- },
- elf.SHT_X86_64_UNWIND => elf.SHT_PROGBITS,
- else => shdr.sh_type,
+ const @"type" = tt: {
+ if (elf_file.getTarget().cpu.arch == .x86_64 and
+ shdr.sh_type == elf.SHT_X86_64_UNWIND) break :tt elf.SHT_PROGBITS;
+
+ const @"type" = switch (shdr.sh_type) {
+ elf.SHT_NULL => unreachable,
+ elf.SHT_PROGBITS => blk: {
+ if (std.mem.eql(u8, name, ".init_array") or std.mem.startsWith(u8, name, ".init_array."))
+ break :blk elf.SHT_INIT_ARRAY;
+ if (std.mem.eql(u8, name, ".fini_array") or std.mem.startsWith(u8, name, ".fini_array."))
+ break :blk elf.SHT_FINI_ARRAY;
+ break :blk shdr.sh_type;
+ },
+ else => shdr.sh_type,
+ };
+ break :tt @"type";
};
const flags = blk: {
var flags = shdr.sh_flags;
@@ -596,9 +605,10 @@ pub fn markLive(self: *Object, elf_file: *Elf) void {
}
pub fn markEhFrameAtomsDead(self: Object, elf_file: *Elf) void {
+ const cpu_arch = elf_file.getTarget().cpu.arch;
for (self.atoms.items) |atom_index| {
const atom = elf_file.atom(atom_index) orelse continue;
- const is_eh_frame = atom.inputShdr(elf_file).sh_type == elf.SHT_X86_64_UNWIND or
+ const is_eh_frame = (cpu_arch == .x86_64 and atom.inputShdr(elf_file).sh_type == elf.SHT_X86_64_UNWIND) or
mem.eql(u8, atom.name(elf_file), ".eh_frame");
if (atom.flags.alive and is_eh_frame) atom.flags.alive = false;
}