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 {...@@ -756,10 +756,11 @@ pub fn populateMissingMetadata(self: *Elf) !void {
756 try self.writeSymbol(0);756 try self.writeSymbol(0);
757 }757 }
758758
759 if (self.dwarf) |dw| {759 if (self.dwarf) |*dw| {
760 if (self.debug_str_section_index == null) {760 if (self.debug_str_section_index == null) {
761 self.debug_str_section_index = @intCast(u16, self.sections.items.len);761 self.debug_str_section_index = @intCast(u16, self.sections.items.len);
762 assert(dw.strtab.items.len == 0);762 assert(dw.strtab.items.len == 0);
763 try dw.strtab.append(self.base.allocator, 0);
763 try self.sections.append(self.base.allocator, .{764 try self.sections.append(self.base.allocator, .{
764 .sh_name = try self.makeString(".debug_str"),765 .sh_name = try self.makeString(".debug_str"),
765 .sh_type = elf.SHT_PROGBITS,766 .sh_type = elf.SHT_PROGBITS,
src/link/MachO/DebugSymbols.zig+1
...@@ -83,6 +83,7 @@ pub fn populateMissingMetadata(self: *DebugSymbols) !void {...@@ -83,6 +83,7 @@ pub fn populateMissingMetadata(self: *DebugSymbols) !void {
8383
84 if (self.debug_str_section_index == null) {84 if (self.debug_str_section_index == null) {
85 assert(self.dwarf.strtab.items.len == 0);85 assert(self.dwarf.strtab.items.len == 0);
86 try self.dwarf.strtab.append(self.allocator, 0);
86 self.debug_str_section_index = try self.allocateSection(87 self.debug_str_section_index = try self.allocateSection(
87 "__debug_str",88 "__debug_str",
88 @intCast(u32, self.dwarf.strtab.items.len),89 @intCast(u32, self.dwarf.strtab.items.len),