authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-01-24 17:31:13+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-01-25 09:58:13+01:00
loge675af06984d0709d308e3faf60b33cadadf2bbf
tree02f4ecea2131478f58688cff124e4e88182263d9
parentd7032705456a67cebeb17ad09a11e10d13f5fb21

elf+macho: append null to DWARF strtab to avoid overlapping sects

Otherwise, we were risking having strtab zero-sized and overlap with another section.

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

src/link/Elf.zig+2-1
......@@ -756,10 +756,11 @@ pub fn populateMissingMetadata(self: *Elf) !void {
756756 try self.writeSymbol(0);
757757 }
758758
759 if (self.dwarf) |dw| {
759 if (self.dwarf) |*dw| {
760760 if (self.debug_str_section_index == null) {
761761 self.debug_str_section_index = @intCast(u16, self.sections.items.len);
762762 assert(dw.strtab.items.len == 0);
763 try dw.strtab.append(self.base.allocator, 0);
763764 try self.sections.append(self.base.allocator, .{
764765 .sh_name = try self.makeString(".debug_str"),
765766 .sh_type = elf.SHT_PROGBITS,
src/link/MachO/DebugSymbols.zig+1
......@@ -83,6 +83,7 @@ pub fn populateMissingMetadata(self: *DebugSymbols) !void {
8383
8484 if (self.debug_str_section_index == null) {
8585 assert(self.dwarf.strtab.items.len == 0);
86 try self.dwarf.strtab.append(self.allocator, 0);
8687 self.debug_str_section_index = try self.allocateSection(
8788 "__debug_str",
8889 @intCast(u32, self.dwarf.strtab.items.len),