Skip to content

Commit

Permalink
macho: create atoms for __DWARF, input __compact_unwind and __eh_fram…
Browse files Browse the repository at this point in the history
…e and kill them
  • Loading branch information
kubkon committed Jan 3, 2024
1 parent 54c470d commit 72915f0
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions src/MachO/Object.zig
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,17 @@ pub fn parse(self: *Object, macho_file: *MachO) !void {

self.initPlatform();
try self.initDwarfInfo(gpa);

for (self.atoms.items) |atom_index| {
const atom = macho_file.getAtom(atom_index).?;
const isec = atom.getInputSection(macho_file);
if (isec.attrs() & macho.S_ATTR_DEBUG != 0 or
mem.eql(u8, isec.sectName(), "__eh_frame") or
mem.eql(u8, isec.segName(), "__compact_unwind"))
{
atom.flags.alive = false;
}
}
}

inline fn isLiteral(sect: macho.section_64) bool {
Expand All @@ -163,9 +174,6 @@ fn initSubsections(self: *Object, nlists: anytype, macho_file: *MachO) !void {
const gpa = macho_file.base.allocator;
const slice = self.sections.slice();
for (slice.items(.header), slice.items(.subsections), 0..) |sect, *subsections, n_sect| {
if (sect.attrs() & macho.S_ATTR_DEBUG != 0) continue;
if (mem.eql(u8, sect.sectName(), "__eh_frame")) continue;
if (mem.eql(u8, sect.sectName(), "__compact_unwind")) continue;
if (isLiteral(sect)) continue;

const nlist_start = for (nlists, 0..) |nlist, i| {
Expand Down Expand Up @@ -237,9 +245,6 @@ fn initSections(self: *Object, nlists: anytype, macho_file: *MachO) !void {
try self.atoms.ensureUnusedCapacity(gpa, self.sections.items(.header).len);

for (slice.items(.header), 0..) |sect, n_sect| {
if (sect.attrs() & macho.S_ATTR_DEBUG != 0) continue;
if (mem.eql(u8, sect.sectName(), "__eh_frame")) continue;
if (mem.eql(u8, sect.sectName(), "__compact_unwind")) continue;
if (isLiteral(sect)) continue;

const name = try std.fmt.allocPrintZ(gpa, "{s}${s}", .{ sect.segName(), sect.sectName() });
Expand Down Expand Up @@ -316,9 +321,6 @@ fn initLiteralSections(self: *Object, macho_file: *MachO) !void {
try self.atoms.ensureUnusedCapacity(gpa, self.sections.items(.header).len);

for (slice.items(.header), 0..) |sect, n_sect| {
if (sect.attrs() & macho.S_ATTR_DEBUG != 0) continue;
if (mem.eql(u8, sect.sectName(), "__eh_frame")) continue;
if (mem.eql(u8, sect.sectName(), "__compact_unwind")) continue;
if (!isLiteral(sect)) continue;

const name = try std.fmt.allocPrintZ(gpa, "{s}${s}", .{ sect.segName(), sect.sectName() });
Expand Down Expand Up @@ -390,10 +392,6 @@ fn linkNlistToAtom(self: *Object, macho_file: *MachO) !void {
defer tracy.end();
for (self.symtab.items(.nlist), self.symtab.items(.atom)) |nlist, *atom| {
if (!nlist.stab() and nlist.sect()) {
const sect = self.sections.items(.header)[nlist.n_sect - 1];
if (sect.attrs() & macho.S_ATTR_DEBUG != 0) continue;
if (mem.eql(u8, sect.sectName(), "__eh_frame")) continue;
if (mem.eql(u8, sect.sectName(), "__compact_unwind")) continue;
if (self.findAtomInSection(nlist.n_value, nlist.n_sect - 1)) |atom_index| {
atom.* = atom_index;
} else {
Expand Down

0 comments on commit 72915f0

Please sign in to comment.