diff options
| author | Jakub Konka <kubkon@jakubkonka.com> | 2023-01-24 17:31:13 +0100 |
|---|---|---|
| committer | Jakub Konka <kubkon@jakubkonka.com> | 2023-01-25 09:58:13 +0100 |
| commit | e675af06984d0709d308e3faf60b33cadadf2bbf (patch) | |
| tree | 02f4ecea2131478f58688cff124e4e88182263d9 /src/link | |
| parent | d7032705456a67cebeb17ad09a11e10d13f5fb21 (diff) | |
| download | zig-e675af06984d0709d308e3faf60b33cadadf2bbf.tar.gz zig-e675af06984d0709d308e3faf60b33cadadf2bbf.zip | |
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 (limited to 'src/link')
| -rw-r--r-- | src/link/Elf.zig | 3 | ||||
| -rw-r--r-- | src/link/MachO/DebugSymbols.zig | 1 |
2 files changed, 3 insertions, 1 deletions
diff --git a/src/link/Elf.zig b/src/link/Elf.zig index c27e4f166f..48e0320dc6 100644 --- 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 index a13ad9c9f4..7c22f441cd 100644 --- 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), |
