authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-12-04 12:37:45+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-12-04 16:58:45+01:00
logd67de87baa9ebc45f51e3a83fed761e03367f904
tree47512c95ce088c2d6ea5269b1fb3b9c7ab334847
parent73d76b26a22fca71636bd2c995de4919a1b6d343

dsym: add helper for accessing dwarf seg pointer


1 files changed, 11 insertions(+), 8 deletions(-)

src/link/MachO/DebugSymbols.zig+11-8
......@@ -126,7 +126,7 @@ pub fn populateMissingMetadata(self: *DebugSymbols, gpa: Allocator) !void {
126126fn allocateSection(self: *DebugSymbols, sectname: []const u8, size: u64, alignment: u16) !u8 {
127127 const gpa = self.base.base.allocator;
128128
129 const segment = &self.segments.items[self.dwarf_segment_cmd_index.?];
129 const segment = self.getDwarfSegmentPtr();
130130 var sect = macho.section_64{
131131 .sectname = makeStaticString(sectname),
132132 .segname = segment.segname,
......@@ -136,8 +136,6 @@ fn allocateSection(self: *DebugSymbols, sectname: []const u8, size: u64, alignme
136136 const alignment_pow_2 = try math.powi(u32, 2, alignment);
137137 const off = self.findFreeSpace(size, alignment_pow_2);
138138
139 assert(off + size <= segment.fileoff + segment.filesize); // TODO expand
140
141139 log.debug("found {s},{s} section free space 0x{x} to 0x{x}", .{
142140 sect.segName(),
143141 sect.sectName(),
......@@ -169,7 +167,7 @@ fn detectAllocCollision(self: *DebugSymbols, start: u64, size: u64) ?u64 {
169167}
170168
171169pub 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();
173171 var offset: u64 = segment.fileoff;
174172 while (self.detectAllocCollision(offset, object_size)) |item_end| {
175173 offset = mem.alignForwardGeneric(u64, item_end, min_alignment);
......@@ -248,7 +246,7 @@ pub fn flushModule(self: *DebugSymbols, allocator: Allocator, options: link.Opti
248246 }
249247
250248 {
251 const dwarf_segment = &self.segments.items[self.dwarf_segment_cmd_index.?];
249 const dwarf_segment = self.getDwarfSegmentPtr();
252250 const debug_strtab_sect = &self.sections.items[self.debug_str_section_index.?];
253251 if (self.debug_string_table_dirty or self.dwarf.strtab.items.len != debug_strtab_sect.size) {
254252 const allocated_size = self.allocatedSize(debug_strtab_sect.offset);
......@@ -326,7 +324,7 @@ fn finalizeDwarfSegment(self: *DebugSymbols) void {
326324 const last_seg = self.base.getLinkeditSegmentPtr();
327325 break :blk last_seg.vmaddr + last_seg.vmsize;
328326 };
329 const dwarf_segment = &self.segments.items[self.dwarf_segment_cmd_index.?];
327 const dwarf_segment = self.getDwarfSegmentPtr();
330328 const aligned_size = mem.alignForwardGeneric(
331329 u64,
332330 dwarf_segment.filesize,
......@@ -419,7 +417,7 @@ fn writeHeader(self: *DebugSymbols, ncmds: u32, sizeofcmds: u32) !void {
419417}
420418
421419pub fn allocatedSize(self: *DebugSymbols, start: u64) u64 {
422 const seg = self.segments.items[self.dwarf_segment_cmd_index.?];
420 const seg = self.getDwarfSegmentPtr();
423421 assert(start >= seg.fileoff);
424422 var min_pos: u64 = std.math.maxInt(u64);
425423 for (self.sections.items) |section| {
......@@ -549,7 +547,12 @@ pub fn getSectionIndexes(self: *DebugSymbols, segment_index: u8) struct { start:
549547 return .{ .start = start, .end = start + nsects };
550548}
551549
552pub fn getLinkeditSegmentPtr(self: *DebugSymbols) *macho.segment_command_64 {
550fn getDwarfSegmentPtr(self: *DebugSymbols) *macho.segment_command_64 {
551 const index = self.dwarf_segment_cmd_index.?;
552 return &self.segments.items[index];
553}
554
555fn getLinkeditSegmentPtr(self: *DebugSymbols) *macho.segment_command_64 {
553556 const index = self.linkedit_segment_cmd_index.?;
554557 return &self.segments.items[index];
555558}