zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit e675af06984d0709d308e3faf60b33cadadf2bbf (tree)
parent d7032705456a67cebeb17ad09a11e10d13f5fb21
Author: Jakub Konka <kubkon@jakubkonka.com>
Date:   Tue, 24 Jan 2023 17:31:13 +0100

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

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

Diffstat:
Msrc/link/Elf.zig | 3++-
Msrc/link/MachO/DebugSymbols.zig | 1+
2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/link/Elf.zig b/src/link/Elf.zig @@ -756,10 +756,11 @@ pub fn populateMissingMetadata(self: *Elf) !void { try self.writeSymbol(0); } - if (self.dwarf) |dw| { + if (self.dwarf) |*dw| { if (self.debug_str_section_index == null) { self.debug_str_section_index = @intCast(u16, self.sections.items.len); assert(dw.strtab.items.len == 0); + try dw.strtab.append(self.base.allocator, 0); try self.sections.append(self.base.allocator, .{ .sh_name = try self.makeString(".debug_str"), .sh_type = elf.SHT_PROGBITS, diff --git a/src/link/MachO/DebugSymbols.zig b/src/link/MachO/DebugSymbols.zig @@ -83,6 +83,7 @@ pub fn populateMissingMetadata(self: *DebugSymbols) !void { if (self.debug_str_section_index == null) { assert(self.dwarf.strtab.items.len == 0); + try self.dwarf.strtab.append(self.allocator, 0); self.debug_str_section_index = try self.allocateSection( "__debug_str", @intCast(u32, self.dwarf.strtab.items.len),