| ... | ... | @@ -845,12 +845,21 @@ pub fn allocateDeclIndexes(self: *MachO, decl: *Module.Decl) !void { |
| 845 | 845 | try self.local_symbols.ensureCapacity(self.base.allocator, self.local_symbols.items.len + 1); |
| 846 | 846 | try self.offset_table.ensureCapacity(self.base.allocator, self.offset_table.items.len + 1); |
| 847 | 847 | |
| 848 | | log.debug("allocating symbol index {} for {}\n", .{ self.local_symbols.items.len, decl.name }); |
| 849 | | decl.link.macho.local_sym_index = @intCast(u32, self.local_symbols.items.len); |
| 850 | | _ = self.local_symbols.addOneAssumeCapacity(); |
| 848 | if (self.local_symbol_free_list.popOrNull()) |i| { |
| 849 | log.debug("reusing symbol index {} for {}\n", .{i, decl.name}); |
| 850 | decl.link.macho.local_sym_index = i; |
| 851 | } else { |
| 852 | log.debug("allocating symbol index {} for {}\n", .{ self.local_symbols.items.len, decl.name }); |
| 853 | decl.link.macho.local_sym_index = @intCast(u32, self.local_symbols.items.len); |
| 854 | _ = self.local_symbols.addOneAssumeCapacity(); |
| 855 | } |
| 851 | 856 | |
| 852 | | decl.link.macho.offset_table_index = @intCast(u32, self.offset_table.items.len); |
| 853 | | _ = self.offset_table.addOneAssumeCapacity(); |
| 857 | if (self.offset_table_free_list.popOrNull()) |i| { |
| 858 | decl.link.macho.offset_table_index = i; |
| 859 | } else { |
| 860 | decl.link.macho.offset_table_index = @intCast(u32, self.offset_table.items.len); |
| 861 | _ = self.offset_table.addOneAssumeCapacity(); |
| 862 | } |
| 854 | 863 | |
| 855 | 864 | self.local_symbols.items[decl.link.macho.local_sym_index] = .{ |
| 856 | 865 | .n_strx = 0, |
| ... | ... | @@ -1401,12 +1410,11 @@ fn allocateTextBlock(self: *MachO, text_block: *TextBlock, new_block_size: u64, |
| 1401 | 1410 | } |
| 1402 | 1411 | else if (self.last_text_block) |last| { |
| 1403 | 1412 | const last_symbol = self.local_symbols.items[last.local_sym_index]; |
| 1404 | | // TODO pad out with NOPs and reenable |
| 1405 | | // const ideal_capacity = last.size * alloc_num / alloc_den; |
| 1406 | | // const ideal_capacity_end_addr = last_symbol.n_value + ideal_capacity; |
| 1407 | | // const new_start_addr = mem.alignForwardGeneric(u64, ideal_capacity_end_addr, alignment); |
| 1408 | | const end_vaddr = last_symbol.n_value + last.size; |
| 1409 | | const new_start_vaddr = mem.alignForwardGeneric(u64, end_vaddr, alignment); |
| 1413 | // TODO We should pad out the excess capacity with NOPs. For executables, |
| 1414 | // no padding seems to be OK, but it will probably not be for objects. |
| 1415 | const ideal_capacity = last.size * alloc_num / alloc_den; |
| 1416 | const ideal_capacity_end_vaddr = last_symbol.n_value + ideal_capacity; |
| 1417 | const new_start_vaddr = mem.alignForwardGeneric(u64, ideal_capacity_end_vaddr, alignment); |
| 1410 | 1418 | block_placement = last; |
| 1411 | 1419 | break :blk new_start_vaddr; |
| 1412 | 1420 | } else { |
| ... | ... | @@ -1421,7 +1429,7 @@ fn allocateTextBlock(self: *MachO, text_block: *TextBlock, new_block_size: u64, |
| 1421 | 1429 | assert(needed_size <= text_capacity); // TODO must move the entire text section. |
| 1422 | 1430 | |
| 1423 | 1431 | self.last_text_block = text_block; |
| 1424 | | text_section.size = needed_size; // TODO temp until we pad out with NOPs |
| 1432 | text_section.size = needed_size; |
| 1425 | 1433 | |
| 1426 | 1434 | self.cmd_table_dirty = true; |
| 1427 | 1435 | } |