| author | |
| committer | |
| log | 860beda55fd94fc56fce20c79aa6ddadce9baf39 |
| tree | 06a55b71c5ee5803dcecc1fc074b9d9b5af2f5c9 |
| parent | 6faed6269fca56d583d2bc5bf35f55a51eb54cdf |
2 files changed, 14 insertions(+), 18 deletions(-)
src/link/Elf.zig+8-9| ... | @@ -111,7 +111,6 @@ symbols_free_list: std.ArrayListUnmanaged(Symbol.Index) = .{}, | ... | @@ -111,7 +111,6 @@ symbols_free_list: std.ArrayListUnmanaged(Symbol.Index) = .{}, |
| 111 | 111 | ||
| 112 | phdr_table_dirty: bool = false, | 112 | phdr_table_dirty: bool = false, |
| 113 | shdr_table_dirty: bool = false, | 113 | shdr_table_dirty: bool = false, |
| 114 | got_addresses_dirty: bool = false, | ||
| 115 | 114 | ||
| 116 | debug_strtab_dirty: bool = false, | 115 | debug_strtab_dirty: bool = false, |
| 117 | debug_abbrev_section_dirty: bool = false, | 116 | debug_abbrev_section_dirty: bool = false, |
| ... | @@ -904,9 +903,10 @@ pub fn growAllocSection(self: *Elf, shdr_index: u16, needed_size: u64) !void { | ... | @@ -904,9 +903,10 @@ pub fn growAllocSection(self: *Elf, shdr_index: u16, needed_size: u64) !void { |
| 904 | // and grow. | 903 | // and grow. |
| 905 | { | 904 | { |
| 906 | const dirty_addr = phdr.p_vaddr + phdr.p_memsz; | 905 | const dirty_addr = phdr.p_vaddr + phdr.p_memsz; |
| 907 | self.got_addresses_dirty = for (self.got.entries.items) |entry| { | 906 | const got_addresses_dirty = for (self.got.entries.items) |entry| { |
| 908 | if (self.symbol(entry.symbol_index).value >= dirty_addr) break true; | 907 | if (self.symbol(entry.symbol_index).value >= dirty_addr) break true; |
| 909 | } else false; | 908 | } else false; |
| 909 | _ = got_addresses_dirty; | ||
| 910 | 910 | ||
| 911 | // TODO mark relocs dirty | 911 | // TODO mark relocs dirty |
| 912 | } | 912 | } |
| ... | @@ -1504,8 +1504,6 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node | ... | @@ -1504,8 +1504,6 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node |
| 1504 | assert(!self.phdr_table_dirty); | 1504 | assert(!self.phdr_table_dirty); |
| 1505 | assert(!self.shdr_table_dirty); | 1505 | assert(!self.shdr_table_dirty); |
| 1506 | assert(!self.debug_strtab_dirty); | 1506 | assert(!self.debug_strtab_dirty); |
| 1507 | assert(!self.got.dirty); | ||
| 1508 | assert(!self.got_addresses_dirty); | ||
| 1509 | } | 1507 | } |
| 1510 | 1508 | ||
| 1511 | const ParseError = error{ | 1509 | const ParseError = error{ |
| ... | @@ -3660,13 +3658,14 @@ fn updateSymtabSize(self: *Elf) !void { | ... | @@ -3660,13 +3658,14 @@ fn updateSymtabSize(self: *Elf) !void { |
| 3660 | } | 3658 | } |
| 3661 | 3659 | ||
| 3662 | fn writeSyntheticSections(self: *Elf) !void { | 3660 | fn writeSyntheticSections(self: *Elf) !void { |
| 3663 | if (self.got_addresses_dirty) { | 3661 | const gpa = self.base.allocator; |
| 3664 | const shdr = &self.shdrs.items[self.got_section_index.?]; | 3662 | |
| 3665 | var buffer = try std.ArrayList(u8).initCapacity(self.base.allocator, self.got.size(self)); | 3663 | if (self.got_section_index) |index| { |
| 3664 | const shdr = self.shdrs.items[index]; | ||
| 3665 | var buffer = try std.ArrayList(u8).initCapacity(gpa, self.got.size(self)); | ||
| 3666 | defer buffer.deinit(); | 3666 | defer buffer.deinit(); |
| 3667 | try self.got.writeAllEntries(self, buffer.writer()); | 3667 | try self.got.write(self, buffer.writer()); |
| 3668 | try self.base.file.?.pwriteAll(buffer.items, shdr.sh_offset); | 3668 | try self.base.file.?.pwriteAll(buffer.items, shdr.sh_offset); |
| 3669 | self.got_addresses_dirty = false; | ||
| 3670 | } | 3669 | } |
| 3671 | 3670 | ||
| 3672 | if (self.shstrtab_section_index) |index| { | 3671 | if (self.shstrtab_section_index) |index| { |
src/link/Elf/synthetic_sections.zig+6-9| ... | @@ -1,7 +1,6 @@ | ... | @@ -1,7 +1,6 @@ |
| 1 | pub const GotSection = struct { | 1 | pub const GotSection = struct { |
| 2 | entries: std.ArrayListUnmanaged(Entry) = .{}, | 2 | entries: std.ArrayListUnmanaged(Entry) = .{}, |
| 3 | needs_rela: bool = false, | 3 | needs_rela: bool = false, |
| 4 | dirty: bool = false, | ||
| 5 | output_symtab_size: Elf.SymtabSize = .{}, | 4 | output_symtab_size: Elf.SymtabSize = .{}, |
| 6 | 5 | ||
| 7 | pub const Index = u32; | 6 | pub const Index = u32; |
| ... | @@ -48,7 +47,6 @@ pub const GotSection = struct { | ... | @@ -48,7 +47,6 @@ pub const GotSection = struct { |
| 48 | break :blk last.cell_index + @as(Index, @intCast(last.len())); | 47 | break :blk last.cell_index + @as(Index, @intCast(last.len())); |
| 49 | } else 0; | 48 | } else 0; |
| 50 | entry.* = .{ .tag = undefined, .symbol_index = undefined, .cell_index = cell_index }; | 49 | entry.* = .{ .tag = undefined, .symbol_index = undefined, .cell_index = cell_index }; |
| 51 | got.dirty = true; | ||
| 52 | return index; | 50 | return index; |
| 53 | } | 51 | } |
| 54 | 52 | ||
| ... | @@ -117,11 +115,11 @@ pub const GotSection = struct { | ... | @@ -117,11 +115,11 @@ pub const GotSection = struct { |
| 117 | 115 | ||
| 118 | pub fn writeEntry(got: *GotSection, elf_file: *Elf, index: Index) !void { | 116 | pub fn writeEntry(got: *GotSection, elf_file: *Elf, index: Index) !void { |
| 119 | const entry_size: u16 = elf_file.archPtrWidthBytes(); | 117 | const entry_size: u16 = elf_file.archPtrWidthBytes(); |
| 120 | if (got.dirty) { | 118 | // if (got.dirty) { |
| 121 | const needed_size = got.size(elf_file); | 119 | // const needed_size = got.size(elf_file); |
| 122 | try elf_file.growAllocSection(elf_file.got_section_index.?, needed_size); | 120 | // try elf_file.growAllocSection(elf_file.got_section_index.?, needed_size); |
| 123 | got.dirty = false; | 121 | // got.dirty = false; |
| 124 | } | 122 | // } |
| 125 | const endian = elf_file.base.options.target.cpu.arch.endian(); | 123 | const endian = elf_file.base.options.target.cpu.arch.endian(); |
| 126 | const entry = got.entries.items[index]; | 124 | const entry = got.entries.items[index]; |
| 127 | const shdr = &elf_file.shdrs.items[elf_file.got_section_index.?]; | 125 | const shdr = &elf_file.shdrs.items[elf_file.got_section_index.?]; |
| ... | @@ -169,8 +167,7 @@ pub const GotSection = struct { | ... | @@ -169,8 +167,7 @@ pub const GotSection = struct { |
| 169 | } | 167 | } |
| 170 | } | 168 | } |
| 171 | 169 | ||
| 172 | pub fn writeAllEntries(got: GotSection, elf_file: *Elf, writer: anytype) !void { | 170 | pub fn write(got: GotSection, elf_file: *Elf, writer: anytype) !void { |
| 173 | assert(!got.dirty); | ||
| 174 | const entry_size: u16 = elf_file.archPtrWidthBytes(); | 171 | const entry_size: u16 = elf_file.archPtrWidthBytes(); |
| 175 | const endian = elf_file.base.options.target.cpu.arch.endian(); | 172 | const endian = elf_file.base.options.target.cpu.arch.endian(); |
| 176 | for (got.entries.items) |entry| { | 173 | for (got.entries.items) |entry| { |