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

Otherwise, we were risking having strtab zero-sized and overlap
with another section.
This commit is contained in:
Jakub Konka 2023-01-24 17:31:13 +01:00
parent d703270545
commit e675af0698
2 changed files with 3 additions and 1 deletions

View File

@ -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,

View File

@ -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),