authorgravatar for noam@pixelhero.devNoam Preil <noam@pixelhero.dev> 2020-08-21 07:20:51-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-08-22 12:45:29-07:00
logfa1d18a15583253d457c39fc38e5bdda8b3f2cf2
tree7c9ad2d88511693408e535295616a0d1d622f7ec
parentf2796239baf1b5883e007729e6064e144c443b56

Linker: fix GOT production on 16-bit targets


1 files changed, 10 insertions(+), 4 deletions(-)

src-self-hosted/link/Elf.zig+10-4
......@@ -2201,7 +2201,7 @@ fn writeSectHeader(self: *Elf, index: usize) !void {
22012201fn writeOffsetTableEntry(self: *Elf, index: usize) !void {
22022202 const shdr = &self.sections.items[self.got_section_index.?];
22032203 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;
22052205 if (self.offset_table_count_dirty) {
22062206 // TODO Also detect virtual address collisions.
22072207 const allocated_size = self.allocatedSize(shdr.sh_offset);
......@@ -2225,17 +2225,23 @@ fn writeOffsetTableEntry(self: *Elf, index: usize) !void {
22252225 }
22262226 const endian = self.base.options.target.cpu.arch.endian();
22272227 const off = shdr.sh_offset + @as(u64, entry_size) * index;
2228 switch (self.ptr_width) {
2229 .p32 => {
2228 switch (entry_size) {
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 => {
22302235 var buf: [4]u8 = undefined;
22312236 mem.writeInt(u32, &buf, @intCast(u32, self.offset_table.items[index]), endian);
22322237 try self.base.file.?.pwriteAll(&buf, off);
22332238 },
2234 .p64 => {
2239 8 => {
22352240 var buf: [8]u8 = undefined;
22362241 mem.writeInt(u64, &buf, self.offset_table.items[index], endian);
22372242 try self.base.file.?.pwriteAll(&buf, off);
22382243 },
2244 else => unreachable,
22392245 }
22402246}
22412247