| ... | ... | @@ -4565,14 +4565,20 @@ fn writeAtoms(self: *Elf) !void { |
| 4565 | 4565 | try self.base.file.?.pwriteAll(buffer, sh_offset); |
| 4566 | 4566 | } |
| 4567 | 4567 | |
| 4568 | | for (self.thunks.items) |th| { |
| 4569 | | const shdr = self.shdrs.items[th.output_section_index]; |
| 4570 | | const offset = th.value + shdr.sh_offset; |
| 4571 | | const buffer = try gpa.alloc(u8, th.size(self)); |
| 4572 | | defer gpa.free(buffer); |
| 4573 | | var stream = std.io.fixedBufferStream(buffer); |
| 4574 | | try th.write(self, stream.writer()); |
| 4575 | | try self.base.file.?.pwriteAll(buffer, offset); |
| 4568 | if (self.requiresThunks()) { |
| 4569 | var buffer = std.ArrayList(u8).init(gpa); |
| 4570 | defer buffer.deinit(); |
| 4571 | |
| 4572 | for (self.thunks.items) |th| { |
| 4573 | const thunk_size = th.size(self); |
| 4574 | try buffer.ensureUnusedCapacity(thunk_size); |
| 4575 | const shdr = self.shdrs.items[th.output_section_index]; |
| 4576 | const offset = th.value + shdr.sh_offset; |
| 4577 | try th.write(self, buffer.writer()); |
| 4578 | assert(buffer.items.len == thunk_size); |
| 4579 | try self.base.file.?.pwriteAll(buffer.items, offset); |
| 4580 | buffer.clearRetainingCapacity(); |
| 4581 | } |
| 4576 | 4582 | } |
| 4577 | 4583 | |
| 4578 | 4584 | try self.reportUndefinedSymbols(&undefs); |
| ... | ... | @@ -4603,12 +4609,12 @@ pub fn updateSymtabSize(self: *Elf) !void { |
| 4603 | 4609 | nlocals += 1; |
| 4604 | 4610 | } |
| 4605 | 4611 | |
| 4606 | | for (self.thunks.items) |*th| { |
| 4612 | if (self.requiresThunks()) for (self.thunks.items) |*th| { |
| 4607 | 4613 | th.output_symtab_ctx.ilocal = nlocals + 1; |
| 4608 | 4614 | th.calcSymtabSize(self); |
| 4609 | 4615 | nlocals += th.output_symtab_ctx.nlocals; |
| 4610 | 4616 | strsize += th.output_symtab_ctx.strsize; |
| 4611 | | } |
| 4617 | }; |
| 4612 | 4618 | |
| 4613 | 4619 | for (files.items) |index| { |
| 4614 | 4620 | const file_ptr = self.file(index).?; |
| ... | ... | @@ -4840,9 +4846,9 @@ pub fn writeSymtab(self: *Elf) !void { |
| 4840 | 4846 | |
| 4841 | 4847 | self.writeSectionSymbols(); |
| 4842 | 4848 | |
| 4843 | | for (self.thunks.items) |th| { |
| 4849 | if (self.requiresThunks()) for (self.thunks.items) |th| { |
| 4844 | 4850 | th.writeSymtab(self); |
| 4845 | | } |
| 4851 | }; |
| 4846 | 4852 | |
| 4847 | 4853 | if (self.zigObjectPtr()) |zig_object| { |
| 4848 | 4854 | zig_object.asFile().writeSymtab(self); |
| ... | ... | @@ -6007,10 +6013,14 @@ fn fmtDumpState( |
| 6007 | 6013 | try writer.print("linker_defined({d}) : (linker defined)\n", .{index}); |
| 6008 | 6014 | try writer.print("{}\n", .{linker_defined.fmtSymtab(self)}); |
| 6009 | 6015 | } |
| 6010 | | try writer.writeAll("thunks\n"); |
| 6011 | | for (self.thunks.items, 0..) |th, index| { |
| 6012 | | try writer.print("thunk({d}) : {}\n", .{ index, th.fmt(self) }); |
| 6016 | |
| 6017 | if (self.requiresThunks()) { |
| 6018 | try writer.writeAll("thunks\n"); |
| 6019 | for (self.thunks.items, 0..) |th, index| { |
| 6020 | try writer.print("thunk({d}) : {}\n", .{ index, th.fmt(self) }); |
| 6021 | } |
| 6013 | 6022 | } |
| 6023 | |
| 6014 | 6024 | try writer.print("{}\n", .{self.zig_got.fmt(self)}); |
| 6015 | 6025 | try writer.print("{}\n", .{self.got.fmt(self)}); |
| 6016 | 6026 | try writer.print("{}\n", .{self.plt.fmt(self)}); |