authorgravatar for noam@pixelhero.devNoam Preil <noam@pixelhero.dev> 2020-08-19 11:42:19-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-08-22 12:45:29-07:00
log8c321f0cf5f38e9286476170f51608dbc7b92c50
treeecba5f4b6a438af60e6e5c43d7c3d25daab2efcc
parentcdefc6acbaf7f582c6689d1e003405819f797181

SPU-II: Fix linking


2 files changed, 11 insertions(+), 3 deletions(-)

src-self-hosted/link.zig+4
......@@ -5,6 +5,9 @@ const fs = std.fs;
55const trace = @import("tracy.zig").trace;
66const Package = @import("Package.zig");
77const Type = @import("type.zig").Type;
8const build_options = @import("build_options");
9
10const producer_string = if (std.builtin.is_test) "zig test" else "zig " ++ build_options.version;
811
912pub const Options = struct {
1013 target: std.Target,
......@@ -20,6 +23,7 @@ pub const Options = struct {
2023 /// Used for calculating how much space to reserve for executable program code in case
2124 /// the binary file deos not already have such a section.
2225 program_code_size_hint: u64 = 256 * 1024,
26 default_entry_addr: u64 = 0x8000000,
2327};
2428
2529pub const File = struct {
src-self-hosted/link/Elf.zig+7-3
......@@ -286,6 +286,10 @@ fn createFile(allocator: *Allocator, file: fs.File, options: link.Options) !Elf
286286 };
287287 errdefer self.deinit();
288288
289 if (options.target.cpu.arch == .spu_2) {
290 self.base.options.default_entry_addr = 0;
291 }
292
289293 // Index 0 is always a null symbol.
290294 try self.local_symbols.append(allocator, .{
291295 .st_name = 0,
......@@ -466,8 +470,8 @@ pub fn populateMissingMetadata(self: *Elf) !void {
466470 .p_type = elf.PT_LOAD,
467471 .p_offset = off,
468472 .p_filesz = file_size,
469 .p_vaddr = default_entry_addr,
470 .p_paddr = default_entry_addr,
473 .p_vaddr = self.base.options.default_entry_addr,
474 .p_paddr = self.base.options.default_entry_addr,
471475 .p_memsz = file_size,
472476 .p_align = p_align,
473477 .p_flags = elf.PF_X | elf.PF_R,
......@@ -486,7 +490,7 @@ pub fn populateMissingMetadata(self: *Elf) !void {
486490 // TODO instead of hard coding the vaddr, make a function to find a vaddr to put things at.
487491 // we'll need to re-use that function anyway, in case the GOT grows and overlaps something
488492 // else in virtual memory.
489 const default_got_addr = if (ptr_size == 2) @as(u32, 0x8000) else 0x4000000;
493 const default_got_addr = if (self.base.options.target.cpu.arch.ptrBitWidth() == 16) @as(u32, 0x8000) else 0x4000000;
490494 try self.program_headers.append(self.base.allocator, .{
491495 .p_type = elf.PT_LOAD,
492496 .p_offset = off,