authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-10-03 08:25:30+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-10-16 19:33:04+02:00
log860beda55fd94fc56fce20c79aa6ddadce9baf39
tree06a55b71c5ee5803dcecc1fc074b9d9b5af2f5c9
parent6faed6269fca56d583d2bc5bf35f55a51eb54cdf

elf: remove dirty from synthetic .got section


2 files changed, 14 insertions(+), 18 deletions(-)

src/link/Elf.zig+8-9
......@@ -111,7 +111,6 @@ symbols_free_list: std.ArrayListUnmanaged(Symbol.Index) = .{},
111111
112112phdr_table_dirty: bool = false,
113113shdr_table_dirty: bool = false,
114got_addresses_dirty: bool = false,
115114
116115debug_strtab_dirty: bool = false,
117116debug_abbrev_section_dirty: bool = false,
......@@ -904,9 +903,10 @@ pub fn growAllocSection(self: *Elf, shdr_index: u16, needed_size: u64) !void {
904903 // and grow.
905904 {
906905 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| {
908907 if (self.symbol(entry.symbol_index).value >= dirty_addr) break true;
909908 } else false;
909 _ = got_addresses_dirty;
910910
911911 // TODO mark relocs dirty
912912 }
......@@ -1504,8 +1504,6 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node
15041504 assert(!self.phdr_table_dirty);
15051505 assert(!self.shdr_table_dirty);
15061506 assert(!self.debug_strtab_dirty);
1507 assert(!self.got.dirty);
1508 assert(!self.got_addresses_dirty);
15091507}
15101508
15111509const ParseError = error{
......@@ -3660,13 +3658,14 @@ fn updateSymtabSize(self: *Elf) !void {
36603658}
36613659
36623660fn writeSyntheticSections(self: *Elf) !void {
3663 if (self.got_addresses_dirty) {
3664 const shdr = &self.shdrs.items[self.got_section_index.?];
3665 var buffer = try std.ArrayList(u8).initCapacity(self.base.allocator, self.got.size(self));
3661 const gpa = self.base.allocator;
3662
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));
36663666 defer buffer.deinit();
3667 try self.got.writeAllEntries(self, buffer.writer());
3667 try self.got.write(self, buffer.writer());
36683668 try self.base.file.?.pwriteAll(buffer.items, shdr.sh_offset);
3669 self.got_addresses_dirty = false;
36703669 }
36713670
36723671 if (self.shstrtab_section_index) |index| {
src/link/Elf/synthetic_sections.zig+6-9
......@@ -1,7 +1,6 @@
11pub const GotSection = struct {
22 entries: std.ArrayListUnmanaged(Entry) = .{},
33 needs_rela: bool = false,
4 dirty: bool = false,
54 output_symtab_size: Elf.SymtabSize = .{},
65
76 pub const Index = u32;
......@@ -48,7 +47,6 @@ pub const GotSection = struct {
4847 break :blk last.cell_index + @as(Index, @intCast(last.len()));
4948 } else 0;
5049 entry.* = .{ .tag = undefined, .symbol_index = undefined, .cell_index = cell_index };
51 got.dirty = true;
5250 return index;
5351 }
5452
......@@ -117,11 +115,11 @@ pub const GotSection = struct {
117115
118116 pub fn writeEntry(got: *GotSection, elf_file: *Elf, index: Index) !void {
119117 const entry_size: u16 = elf_file.archPtrWidthBytes();
120 if (got.dirty) {
121 const needed_size = got.size(elf_file);
122 try elf_file.growAllocSection(elf_file.got_section_index.?, needed_size);
123 got.dirty = false;
124 }
118 // if (got.dirty) {
119 // const needed_size = got.size(elf_file);
120 // try elf_file.growAllocSection(elf_file.got_section_index.?, needed_size);
121 // got.dirty = false;
122 // }
125123 const endian = elf_file.base.options.target.cpu.arch.endian();
126124 const entry = got.entries.items[index];
127125 const shdr = &elf_file.shdrs.items[elf_file.got_section_index.?];
......@@ -169,8 +167,7 @@ pub const GotSection = struct {
169167 }
170168 }
171169
172 pub fn writeAllEntries(got: GotSection, elf_file: *Elf, writer: anytype) !void {
173 assert(!got.dirty);
170 pub fn write(got: GotSection, elf_file: *Elf, writer: anytype) !void {
174171 const entry_size: u16 = elf_file.archPtrWidthBytes();
175172 const endian = elf_file.base.options.target.cpu.arch.endian();
176173 for (got.entries.items) |entry| {