| ... | @@ -38,7 +38,7 @@ error_flags: link.File.ErrorFlags = .{}, | ... | @@ -38,7 +38,7 @@ error_flags: link.File.ErrorFlags = .{}, |
| 38 | ptr_width: PtrWidth, | 38 | ptr_width: PtrWidth, |
| 39 | | 39 | |
| 40 | sections: std.MultiArrayList(Section) = .{}, | 40 | sections: std.MultiArrayList(Section) = .{}, |
| 41 | data_directories: std.ArrayListUnmanaged(coff.ImageDataDirectory) = .{}, | 41 | data_directories: [16]coff.ImageDataDirectory, |
| 42 | | 42 | |
| 43 | text_section_index: ?u16 = null, | 43 | text_section_index: ?u16 = null, |
| 44 | got_section_index: ?u16 = null, | 44 | got_section_index: ?u16 = null, |
| ... | @@ -72,7 +72,6 @@ const default_section_alignment: u16 = 0x1000; | ... | @@ -72,7 +72,6 @@ const default_section_alignment: u16 = 0x1000; |
| 72 | const default_file_alignment: u16 = 0x200; | 72 | const default_file_alignment: u16 = 0x200; |
| 73 | const default_image_base_dll: u64 = 0x10000000; | 73 | const default_image_base_dll: u64 = 0x10000000; |
| 74 | const default_image_base_exe: u64 = 0x10000; | 74 | const default_image_base_exe: u64 = 0x10000; |
| 75 | const default_header_size: u64 = default_section_alignment; | | |
| 76 | | 75 | |
| 77 | const Section = struct { | 76 | const Section = struct { |
| 78 | header: coff.SectionHeader, | 77 | header: coff.SectionHeader, |
| ... | @@ -171,6 +170,7 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*Coff { | ... | @@ -171,6 +170,7 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*Coff { |
| 171 | .file = null, | 170 | .file = null, |
| 172 | }, | 171 | }, |
| 173 | .ptr_width = ptr_width, | 172 | .ptr_width = ptr_width, |
| | 173 | .data_directories = comptime mem.zeroes([16]coff.ImageDataDirectory), |
| 174 | }; | 174 | }; |
| 175 | | 175 | |
| 176 | const use_llvm = build_options.have_llvm and options.use_llvm; | 176 | const use_llvm = build_options.have_llvm and options.use_llvm; |
| ... | @@ -192,7 +192,6 @@ pub fn deinit(self: *Coff) void { | ... | @@ -192,7 +192,6 @@ pub fn deinit(self: *Coff) void { |
| 192 | free_list.deinit(gpa); | 192 | free_list.deinit(gpa); |
| 193 | } | 193 | } |
| 194 | self.sections.deinit(gpa); | 194 | self.sections.deinit(gpa); |
| 195 | self.data_directories.deinit(gpa); | | |
| 196 | | 195 | |
| 197 | for (self.managed_atoms.items) |atom| { | 196 | for (self.managed_atoms.items) |atom| { |
| 198 | gpa.destroy(atom); | 197 | gpa.destroy(atom); |
| ... | @@ -699,7 +698,7 @@ fn writeSectionHeaders(self: *Coff) !void { | ... | @@ -699,7 +698,7 @@ fn writeSectionHeaders(self: *Coff) !void { |
| 699 | | 698 | |
| 700 | fn writeDataDirectoriesHeaders(self: *Coff) !void { | 699 | fn writeDataDirectoriesHeaders(self: *Coff) !void { |
| 701 | const offset = self.getDataDirectoryHeadersOffset(); | 700 | const offset = self.getDataDirectoryHeadersOffset(); |
| 702 | try self.base.file.?.pwriteAll(mem.sliceAsBytes(self.data_directories.items), offset); | 701 | try self.base.file.?.pwriteAll(mem.sliceAsBytes(&self.data_directories), offset); |
| 703 | } | 702 | } |
| 704 | | 703 | |
| 705 | fn writeHeader(self: *Coff) !void { | 704 | fn writeHeader(self: *Coff) !void { |
| ... | @@ -790,7 +789,7 @@ fn writeHeader(self: *Coff) !void { | ... | @@ -790,7 +789,7 @@ fn writeHeader(self: *Coff) !void { |
| 790 | .size_of_heap_reserve = 0, | 789 | .size_of_heap_reserve = 0, |
| 791 | .size_of_heap_commit = 0, | 790 | .size_of_heap_commit = 0, |
| 792 | .loader_flags = 0, | 791 | .loader_flags = 0, |
| 793 | .number_of_rva_and_sizes = @intCast(u32, self.data_directories.items.len), | 792 | .number_of_rva_and_sizes = @intCast(u32, self.data_directories.len), |
| 794 | }; | 793 | }; |
| 795 | writer.writeAll(mem.asBytes(&opt_header)) catch unreachable; | 794 | writer.writeAll(mem.asBytes(&opt_header)) catch unreachable; |
| 796 | }, | 795 | }, |
| ... | @@ -824,7 +823,7 @@ fn writeHeader(self: *Coff) !void { | ... | @@ -824,7 +823,7 @@ fn writeHeader(self: *Coff) !void { |
| 824 | .size_of_heap_reserve = 0, | 823 | .size_of_heap_reserve = 0, |
| 825 | .size_of_heap_commit = 0, | 824 | .size_of_heap_commit = 0, |
| 826 | .loader_flags = 0, | 825 | .loader_flags = 0, |
| 827 | .number_of_rva_and_sizes = @intCast(u32, self.data_directories.items.len), | 826 | .number_of_rva_and_sizes = @intCast(u32, self.data_directories.len), |
| 828 | }; | 827 | }; |
| 829 | writer.writeAll(mem.asBytes(&opt_header)) catch unreachable; | 828 | writer.writeAll(mem.asBytes(&opt_header)) catch unreachable; |
| 830 | }, | 829 | }, |
| ... | @@ -841,32 +840,13 @@ pub fn padToIdeal(actual_size: anytype) @TypeOf(actual_size) { | ... | @@ -841,32 +840,13 @@ pub fn padToIdeal(actual_size: anytype) @TypeOf(actual_size) { |
| 841 | } | 840 | } |
| 842 | | 841 | |
| 843 | // fn detectAllocCollision(self: *Coff, start: u64, size: u64) ?u64 { | 842 | // fn detectAllocCollision(self: *Coff, start: u64, size: u64) ?u64 { |
| 844 | // if (start < default_header_size) | 843 | // const headers_size = self.getSizeOfHeaders(); |
| 845 | // return default_header_size; | 844 | // if (start < headers_size) |
| | 845 | // return headers_size; |
| 846 | | 846 | |
| 847 | // const end = start + padToIdeal(size); | 847 | // const end = start + padToIdeal(size); |
| 848 | | 848 | |
| 849 | // if (self.symtab_offset) |off| { | 849 | // for (self.sections.items(.header)) |header| { |
| 850 | // const shdr_size: u64 = if (small_ptr) @sizeOf(elf.Elf32_Shdr) else @sizeOf(elf.Elf64_Shdr); | | |
| 851 | // const tight_size = self.sections.items.len * shdr_size; | | |
| 852 | // const increased_size = padToIdeal(tight_size); | | |
| 853 | // const test_end = off + increased_size; | | |
| 854 | // if (end > off and start < test_end) { | | |
| 855 | // return test_end; | | |
| 856 | // } | | |
| 857 | // } | | |
| 858 | | | |
| 859 | // if (self.phdr_table_offset) |off| { | | |
| 860 | // const phdr_size: u64 = if (small_ptr) @sizeOf(elf.Elf32_Phdr) else @sizeOf(elf.Elf64_Phdr); | | |
| 861 | // const tight_size = self.sections.items.len * phdr_size; | | |
| 862 | // const increased_size = padToIdeal(tight_size); | | |
| 863 | // const test_end = off + increased_size; | | |
| 864 | // if (end > off and start < test_end) { | | |
| 865 | // return test_end; | | |
| 866 | // } | | |
| 867 | // } | | |
| 868 | | | |
| 869 | // for (self.sections.items) |section| { | | |
| 870 | // const increased_size = padToIdeal(section.sh_size); | 850 | // const increased_size = padToIdeal(section.sh_size); |
| 871 | // const test_end = section.sh_offset + increased_size; | 851 | // const test_end = section.sh_offset + increased_size; |
| 872 | // if (end > section.sh_offset and start < test_end) { | 852 | // if (end > section.sh_offset and start < test_end) { |
| ... | @@ -926,7 +906,7 @@ inline fn getOptionalHeaderSize(self: Coff) usize { | ... | @@ -926,7 +906,7 @@ inline fn getOptionalHeaderSize(self: Coff) usize { |
| 926 | } | 906 | } |
| 927 | | 907 | |
| 928 | inline fn getDataDirectoryHeadersSize(self: Coff) usize { | 908 | inline fn getDataDirectoryHeadersSize(self: Coff) usize { |
| 929 | return self.data_directories.items.len * @sizeOf(coff.ImageDataDirectory); | 909 | return self.data_directories.len * @sizeOf(coff.ImageDataDirectory); |
| 930 | } | 910 | } |
| 931 | | 911 | |
| 932 | inline fn getSectionHeadersSize(self: Coff) usize { | 912 | inline fn getSectionHeadersSize(self: Coff) usize { |