macho: fix dead stripping logic to exclude debug sections

This commit is contained in:
Jakub Konka 2024-01-12 11:40:07 +01:00
parent 10a5536a7c
commit ef9aea75d0
2 changed files with 7 additions and 1 deletions

View File

@ -173,6 +173,7 @@ pub fn initOutputSection(sect: macho.section_64, macho_file: *MachO) !u8 {
pub fn scanRelocs(self: Atom, macho_file: *MachO) !void {
const tracy = trace(@src());
defer tracy.end();
assert(self.flags.alive);
const object = self.getFile(macho_file).object;
const relocs = self.getRelocs(macho_file);

View File

@ -91,7 +91,12 @@ fn mark(roots: []*Atom, objects: []const File.Index, macho_file: *MachO) void {
for (macho_file.getFile(index).?.getAtoms()) |atom_index| {
const atom = macho_file.getAtom(atom_index).?;
const isec = atom.getInputSection(macho_file);
if (isec.isDontDeadStripIfReferencesLive() and !atom.flags.alive and refersLive(atom, macho_file)) {
if (isec.isDontDeadStripIfReferencesLive() and
!(mem.eql(u8, isec.sectName(), "__eh_frame") or
mem.eql(u8, isec.sectName(), "__compact_unwind") or
isec.attrs() & macho.S_ATTR_DEBUG != 0) and
!atom.flags.alive and refersLive(atom, macho_file))
{
markLive(atom, macho_file);
loop = true;
}