From 539bdfc46ff75a4a4febb97a7700ade393c1cb22 Mon Sep 17 00:00:00 2001 From: Theo Fabi Date: Fri, 24 Jul 2026 12:31:28 -0400 Subject: [PATCH] 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. --- lib/std/debug/MachOFile.zig | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/std/debug/MachOFile.zig b/lib/std/debug/MachOFile.zig index 158e908183715fd06876b1191d4cad0cf2cd5301..8b35d7541d05caae74e065d6146ebbffd4e8d3e4 100644 --- a/lib/std/debug/MachOFile.zig +++ b/lib/std/debug/MachOFile.zig @@ -504,8 +504,11 @@ fn loadOFile(gpa: Allocator, io: Io, o_file_name: []const u8) !OFile { if (!std.mem.eql(u8, "__DWARF", sect.segName())) continue; - const section_index: usize = inline for (@typeInfo(Dwarf.Section.Id).@"enum".field_names, 0..) |section_name, i| { - if (mem.eql(u8, "__" ++ section_name, sect.sectName())) break i; + const section_index: usize = inline for (@typeInfo(Dwarf.Section.Id).@"enum".field_names, 0..) |field_name, i| { + const section_name_long = "__" ++ field_name; + // Some dwarf section names don't fit in the `sectname` buffer, so they are truncated. + const section_name_trunc = section_name_long[0..@min(section_name_long.len, sect.sectname.len)]; + if (mem.eql(u8, section_name_trunc, sect.sectName())) break i; } else continue; if (mapped_ofile.len < sect.offset + sect.size) return error.InvalidMachO; -- 2.54.0