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 {...@@ -2201,7 +2201,7 @@ fn writeSectHeader(self: *Elf, index: usize) !void {
2201fn writeOffsetTableEntry(self: *Elf, index: usize) !void {2201fn 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}
22412247