| ... | @@ -2201,7 +2201,7 @@ fn writeSectHeader(self: *Elf, index: usize) !void { | ... | @@ -2201,7 +2201,7 @@ fn writeSectHeader(self: *Elf, index: usize) !void { |
| 2201 | fn writeOffsetTableEntry(self: *Elf, index: usize) !void { | 2201 | fn writeOffsetTableEntry(self: *Elf, index: usize) !void { |
| 2202 | const shdr = &self.sections.items[self.got_section_index.?]; | 2202 | const shdr = &self.sections.items[self.got_section_index.?]; |
| 2203 | const phdr = &self.program_headers.items[self.phdr_got_index.?]; | 2203 | const phdr = &self.program_headers.items[self.phdr_got_index.?]; |
| 2204 | const entry_size: u16 = self.ptrWidthBytes(); | 2204 | const entry_size: u16 = self.base.options.target.cpu.arch.ptrBitWidth() / 8; |
| 2205 | if (self.offset_table_count_dirty) { | 2205 | if (self.offset_table_count_dirty) { |
| 2206 | // TODO Also detect virtual address collisions. | 2206 | // TODO Also detect virtual address collisions. |
| 2207 | const allocated_size = self.allocatedSize(shdr.sh_offset); | 2207 | const allocated_size = self.allocatedSize(shdr.sh_offset); |
| ... | @@ -2225,17 +2225,23 @@ fn writeOffsetTableEntry(self: *Elf, index: usize) !void { | ... | @@ -2225,17 +2225,23 @@ fn writeOffsetTableEntry(self: *Elf, index: usize) !void { |
| 2225 | } | 2225 | } |
| 2226 | const endian = self.base.options.target.cpu.arch.endian(); | 2226 | const endian = self.base.options.target.cpu.arch.endian(); |
| 2227 | const off = shdr.sh_offset + @as(u64, entry_size) * index; | 2227 | const off = shdr.sh_offset + @as(u64, entry_size) * index; |
| 2228 | switch (self.ptr_width) { | 2228 | switch (entry_size) { |
| 2229 | .p32 => { | 2229 | 2 => { |
| | 2230 | var buf: [2]u8 = undefined; |
| | 2231 | mem.writeInt(u16, &buf, @intCast(u16, self.offset_table.items[index]), endian); |
| | 2232 | try self.base.file.?.pwriteAll(&buf, off); |
| | 2233 | }, |
| | 2234 | 4 => { |
| 2230 | var buf: [4]u8 = undefined; | 2235 | var buf: [4]u8 = undefined; |
| 2231 | mem.writeInt(u32, &buf, @intCast(u32, self.offset_table.items[index]), endian); | 2236 | mem.writeInt(u32, &buf, @intCast(u32, self.offset_table.items[index]), endian); |
| 2232 | try self.base.file.?.pwriteAll(&buf, off); | 2237 | try self.base.file.?.pwriteAll(&buf, off); |
| 2233 | }, | 2238 | }, |
| 2234 | .p64 => { | 2239 | 8 => { |
| 2235 | var buf: [8]u8 = undefined; | 2240 | var buf: [8]u8 = undefined; |
| 2236 | mem.writeInt(u64, &buf, self.offset_table.items[index], endian); | 2241 | mem.writeInt(u64, &buf, self.offset_table.items[index], endian); |
| 2237 | try self.base.file.?.pwriteAll(&buf, off); | 2242 | try self.base.file.?.pwriteAll(&buf, off); |
| 2238 | }, | 2243 | }, |
| | 2244 | else => unreachable, |
| 2239 | } | 2245 | } |
| 2240 | } | 2246 | } |
| 2241 | | 2247 | |