| ... | @@ -49,6 +49,7 @@ globals: std.StringArrayHashMapUnmanaged(SymbolWithLoc) = .{}, | ... | @@ -49,6 +49,7 @@ globals: std.StringArrayHashMapUnmanaged(SymbolWithLoc) = .{}, |
| 49 | locals_free_list: std.ArrayListUnmanaged(u32) = .{}, | 49 | locals_free_list: std.ArrayListUnmanaged(u32) = .{}, |
| 50 | | 50 | |
| 51 | strtab: StringTable(.strtab) = .{}, | 51 | strtab: StringTable(.strtab) = .{}, |
| | 52 | strtab_offset: ?u32 = null, |
| 52 | | 53 | |
| 53 | got_entries: std.AutoArrayHashMapUnmanaged(SymbolWithLoc, u32) = .{}, | 54 | got_entries: std.AutoArrayHashMapUnmanaged(SymbolWithLoc, u32) = .{}, |
| 54 | got_entries_free_list: std.ArrayListUnmanaged(u32) = .{}, | 55 | got_entries_free_list: std.ArrayListUnmanaged(u32) = .{}, |
| ... | @@ -138,17 +139,6 @@ pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Option | ... | @@ -138,17 +139,6 @@ pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Option |
| 138 | }); | 139 | }); |
| 139 | self.base.file = file; | 140 | self.base.file = file; |
| 140 | | 141 | |
| 141 | // Index 0 is always a null symbol. | | |
| 142 | try self.locals.append(allocator, .{ | | |
| 143 | .name = [_]u8{0} ** 8, | | |
| 144 | .value = 0, | | |
| 145 | .section_number = @intToEnum(coff.SectionNumber, 0), | | |
| 146 | .@"type" = .{ .base_type = .NULL, .complex_type = .NULL }, | | |
| 147 | .storage_class = .NULL, | | |
| 148 | .number_of_aux_symbols = 0, | | |
| 149 | }); | | |
| 150 | try self.strtab.buffer.append(allocator, 0); | | |
| 151 | | | |
| 152 | try self.populateMissingMetadata(); | 142 | try self.populateMissingMetadata(); |
| 153 | | 143 | |
| 154 | return self; | 144 | return self; |
| ... | @@ -209,8 +199,25 @@ pub fn deinit(self: *Coff) void { | ... | @@ -209,8 +199,25 @@ pub fn deinit(self: *Coff) void { |
| 209 | } | 199 | } |
| 210 | | 200 | |
| 211 | fn populateMissingMetadata(self: *Coff) !void { | 201 | fn populateMissingMetadata(self: *Coff) !void { |
| | 202 | const gpa = self.base.allocator; |
| | 203 | |
| 212 | if (self.text_section_index == null) {} | 204 | if (self.text_section_index == null) {} |
| | 205 | |
| 213 | if (self.got_section_index == null) {} | 206 | if (self.got_section_index == null) {} |
| | 207 | |
| | 208 | if (self.strtab_offset == null) { |
| | 209 | try self.strtab.buffer.append(gpa, 0); |
| | 210 | } |
| | 211 | |
| | 212 | // Index 0 is always a null symbol. |
| | 213 | try self.locals.append(gpa, .{ |
| | 214 | .name = [_]u8{0} ** 8, |
| | 215 | .value = 0, |
| | 216 | .section_number = @intToEnum(coff.SectionNumber, 0), |
| | 217 | .@"type" = .{ .base_type = .NULL, .complex_type = .NULL }, |
| | 218 | .storage_class = .NULL, |
| | 219 | .number_of_aux_symbols = 0, |
| | 220 | }); |
| 214 | } | 221 | } |
| 215 | | 222 | |
| 216 | pub fn allocateDeclIndexes(self: *Coff, decl_index: Module.Decl.Index) !void { | 223 | pub fn allocateDeclIndexes(self: *Coff, decl_index: Module.Decl.Index) !void { |
| ... | @@ -733,7 +740,7 @@ fn writeHeader(self: *Coff) !void { | ... | @@ -733,7 +740,7 @@ fn writeHeader(self: *Coff) !void { |
| 733 | .machine = coff.MachineType.fromTargetCpuArch(self.base.options.target.cpu.arch), | 740 | .machine = coff.MachineType.fromTargetCpuArch(self.base.options.target.cpu.arch), |
| 734 | .number_of_sections = @intCast(u16, self.sections.slice().len), // TODO what if we prune a section | 741 | .number_of_sections = @intCast(u16, self.sections.slice().len), // TODO what if we prune a section |
| 735 | .time_date_stamp = 0, // TODO | 742 | .time_date_stamp = 0, // TODO |
| 736 | .pointer_to_symbol_table = 0, | 743 | .pointer_to_symbol_table = self.strtab_offset orelse 0, |
| 737 | .number_of_symbols = 0, | 744 | .number_of_symbols = 0, |
| 738 | .size_of_optional_header = size_of_optional_header, | 745 | .size_of_optional_header = size_of_optional_header, |
| 739 | .flags = flags, | 746 | .flags = flags, |
| ... | @@ -846,6 +853,14 @@ fn detectAllocCollision(self: *Coff, start: u64, size: u64) ?u64 { | ... | @@ -846,6 +853,14 @@ fn detectAllocCollision(self: *Coff, start: u64, size: u64) ?u64 { |
| 846 | | 853 | |
| 847 | const end = start + padToIdeal(size); | 854 | const end = start + padToIdeal(size); |
| 848 | | 855 | |
| | 856 | if (self.strtab_offset) |off| { |
| | 857 | const increased_size = padToIdeal(self.strtab.len()); |
| | 858 | const test_end = off + increased_size; |
| | 859 | if (end > off and start < test_end) { |
| | 860 | return test_end; |
| | 861 | } |
| | 862 | } |
| | 863 | |
| 849 | for (self.sections.items(.header)) |header| { | 864 | for (self.sections.items(.header)) |header| { |
| 850 | const increased_size = padToIdeal(header.size_of_raw_data); | 865 | const increased_size = padToIdeal(header.size_of_raw_data); |
| 851 | const test_end = header.pointer_to_raw_data + increased_size; | 866 | const test_end = header.pointer_to_raw_data + increased_size; |
| ... | @@ -861,6 +876,9 @@ pub fn allocatedSize(self: *Coff, start: u64) u64 { | ... | @@ -861,6 +876,9 @@ pub fn allocatedSize(self: *Coff, start: u64) u64 { |
| 861 | if (start == 0) | 876 | if (start == 0) |
| 862 | return 0; | 877 | return 0; |
| 863 | var min_pos: u64 = std.math.maxInt(u64); | 878 | var min_pos: u64 = std.math.maxInt(u64); |
| | 879 | if (self.strtab_offset) |off| { |
| | 880 | if (off > start and off < min_pos) min_pos = off; |
| | 881 | } |
| 864 | for (self.sections.items(.header)) |header| { | 882 | for (self.sections.items(.header)) |header| { |
| 865 | if (header.pointer_to_raw_data <= start) continue; | 883 | if (header.pointer_to_raw_data <= start) continue; |
| 866 | if (header.pointer_to_raw_data < min_pos) min_pos = header.pointer_to_raw_data; | 884 | if (header.pointer_to_raw_data < min_pos) min_pos = header.pointer_to_raw_data; |