authorgravatar for fabi.theo@gmail.comTheo Fabi <fabi.theo@gmail.com> 2026-07-24 12:31:28-04:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-08-02 14:18:11+02:00
log539bdfc46ff75a4a4febb97a7700ade393c1cb22
treeb981f2dd45e86355043c53cf9642e5be4bcfa045
parent1b7b856a810708ecfc8f78298cdd0a76315e8578

debug.MachOFile: handle truncated dwarf section names

Some dwarf section names like __debug_str_offsets don't fit in a Mach-O sectname buffer, so their actual name in Mach-O binaries is truncated. When searching for sections to load an object file's debug info, we now compare the section name with the truncated name. Before, the full name was checked, so we would unconditionally skip __debug_str_offsets dwarf sections.

1 files changed, 5 insertions(+), 2 deletions(-)

lib/std/debug/MachOFile.zig+5-2
...@@ -504,8 +504,11 @@ fn loadOFile(gpa: Allocator, io: Io, o_file_name: []const u8) !OFile {...@@ -504,8 +504,11 @@ fn loadOFile(gpa: Allocator, io: Io, o_file_name: []const u8) !OFile {
504504
505 if (!std.mem.eql(u8, "__DWARF", sect.segName())) continue;505 if (!std.mem.eql(u8, "__DWARF", sect.segName())) continue;
506506
507 const section_index: usize = inline for (@typeInfo(Dwarf.Section.Id).@"enum".field_names, 0..) |section_name, i| {507 const section_index: usize = inline for (@typeInfo(Dwarf.Section.Id).@"enum".field_names, 0..) |field_name, i| {
508 if (mem.eql(u8, "__" ++ section_name, sect.sectName())) break i;508 const section_name_long = "__" ++ field_name;
509 // Some dwarf section names don't fit in the `sectname` buffer, so they are truncated.
510 const section_name_trunc = section_name_long[0..@min(section_name_long.len, sect.sectname.len)];
511 if (mem.eql(u8, section_name_trunc, sect.sectName())) break i;
509 } else continue;512 } else continue;
510513
511 if (mapped_ofile.len < sect.offset + sect.size) return error.InvalidMachO;514 if (mapped_ofile.len < sect.offset + sect.size) return error.InvalidMachO;