| ... | ... | @@ -126,7 +126,7 @@ pub fn populateMissingMetadata(self: *DebugSymbols, gpa: Allocator) !void { |
| 126 | 126 | fn allocateSection(self: *DebugSymbols, sectname: []const u8, size: u64, alignment: u16) !u8 { |
| 127 | 127 | const gpa = self.base.base.allocator; |
| 128 | 128 | |
| 129 | | const segment = &self.segments.items[self.dwarf_segment_cmd_index.?]; |
| 129 | const segment = self.getDwarfSegmentPtr(); |
| 130 | 130 | var sect = macho.section_64{ |
| 131 | 131 | .sectname = makeStaticString(sectname), |
| 132 | 132 | .segname = segment.segname, |
| ... | ... | @@ -136,8 +136,6 @@ fn allocateSection(self: *DebugSymbols, sectname: []const u8, size: u64, alignme |
| 136 | 136 | const alignment_pow_2 = try math.powi(u32, 2, alignment); |
| 137 | 137 | const off = self.findFreeSpace(size, alignment_pow_2); |
| 138 | 138 | |
| 139 | | assert(off + size <= segment.fileoff + segment.filesize); // TODO expand |
| 140 | | |
| 141 | 139 | log.debug("found {s},{s} section free space 0x{x} to 0x{x}", .{ |
| 142 | 140 | sect.segName(), |
| 143 | 141 | sect.sectName(), |
| ... | ... | @@ -169,7 +167,7 @@ fn detectAllocCollision(self: *DebugSymbols, start: u64, size: u64) ?u64 { |
| 169 | 167 | } |
| 170 | 168 | |
| 171 | 169 | pub fn findFreeSpace(self: *DebugSymbols, object_size: u64, min_alignment: u64) u64 { |
| 172 | | const segment = self.segments.items[self.dwarf_segment_cmd_index.?]; |
| 170 | const segment = self.getDwarfSegmentPtr(); |
| 173 | 171 | var offset: u64 = segment.fileoff; |
| 174 | 172 | while (self.detectAllocCollision(offset, object_size)) |item_end| { |
| 175 | 173 | offset = mem.alignForwardGeneric(u64, item_end, min_alignment); |
| ... | ... | @@ -248,7 +246,7 @@ pub fn flushModule(self: *DebugSymbols, allocator: Allocator, options: link.Opti |
| 248 | 246 | } |
| 249 | 247 | |
| 250 | 248 | { |
| 251 | | const dwarf_segment = &self.segments.items[self.dwarf_segment_cmd_index.?]; |
| 249 | const dwarf_segment = self.getDwarfSegmentPtr(); |
| 252 | 250 | const debug_strtab_sect = &self.sections.items[self.debug_str_section_index.?]; |
| 253 | 251 | if (self.debug_string_table_dirty or self.dwarf.strtab.items.len != debug_strtab_sect.size) { |
| 254 | 252 | const allocated_size = self.allocatedSize(debug_strtab_sect.offset); |
| ... | ... | @@ -326,7 +324,7 @@ fn finalizeDwarfSegment(self: *DebugSymbols) void { |
| 326 | 324 | const last_seg = self.base.getLinkeditSegmentPtr(); |
| 327 | 325 | break :blk last_seg.vmaddr + last_seg.vmsize; |
| 328 | 326 | }; |
| 329 | | const dwarf_segment = &self.segments.items[self.dwarf_segment_cmd_index.?]; |
| 327 | const dwarf_segment = self.getDwarfSegmentPtr(); |
| 330 | 328 | const aligned_size = mem.alignForwardGeneric( |
| 331 | 329 | u64, |
| 332 | 330 | dwarf_segment.filesize, |
| ... | ... | @@ -419,7 +417,7 @@ fn writeHeader(self: *DebugSymbols, ncmds: u32, sizeofcmds: u32) !void { |
| 419 | 417 | } |
| 420 | 418 | |
| 421 | 419 | pub fn allocatedSize(self: *DebugSymbols, start: u64) u64 { |
| 422 | | const seg = self.segments.items[self.dwarf_segment_cmd_index.?]; |
| 420 | const seg = self.getDwarfSegmentPtr(); |
| 423 | 421 | assert(start >= seg.fileoff); |
| 424 | 422 | var min_pos: u64 = std.math.maxInt(u64); |
| 425 | 423 | for (self.sections.items) |section| { |
| ... | ... | @@ -549,7 +547,12 @@ pub fn getSectionIndexes(self: *DebugSymbols, segment_index: u8) struct { start: |
| 549 | 547 | return .{ .start = start, .end = start + nsects }; |
| 550 | 548 | } |
| 551 | 549 | |
| 552 | | pub fn getLinkeditSegmentPtr(self: *DebugSymbols) *macho.segment_command_64 { |
| 550 | fn getDwarfSegmentPtr(self: *DebugSymbols) *macho.segment_command_64 { |
| 551 | const index = self.dwarf_segment_cmd_index.?; |
| 552 | return &self.segments.items[index]; |
| 553 | } |
| 554 | |
| 555 | fn getLinkeditSegmentPtr(self: *DebugSymbols) *macho.segment_command_64 { |
| 553 | 556 | const index = self.linkedit_segment_cmd_index.?; |
| 554 | 557 | return &self.segments.items[index]; |
| 555 | 558 | } |