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;...@@ -5,6 +5,9 @@ const fs = std.fs;
5const trace = @import("tracy.zig").trace;5const trace = @import("tracy.zig").trace;
6const Package = @import("Package.zig");6const Package = @import("Package.zig");
7const Type = @import("type.zig").Type;7const 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
9pub const Options = struct {12pub const Options = struct {
10 target: std.Target,13 target: std.Target,
...@@ -20,6 +23,7 @@ pub const Options = struct {...@@ -20,6 +23,7 @@ pub const Options = struct {
20 /// Used for calculating how much space to reserve for executable program code in case23 /// Used for calculating how much space to reserve for executable program code in case
21 /// the binary file deos not already have such a section.24 /// the binary file deos not already have such a section.
22 program_code_size_hint: u64 = 256 * 1024,25 program_code_size_hint: u64 = 256 * 1024,
26 default_entry_addr: u64 = 0x8000000,
23};27};
2428
25pub const File = struct {29pub 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...@@ -286,6 +286,10 @@ fn createFile(allocator: *Allocator, file: fs.File, options: link.Options) !Elf
286 };286 };
287 errdefer self.deinit();287 errdefer self.deinit();
288288
289 if (options.target.cpu.arch == .spu_2) {
290 self.base.options.default_entry_addr = 0;
291 }
292
289 // Index 0 is always a null symbol.293 // Index 0 is always a null symbol.
290 try self.local_symbols.append(allocator, .{294 try self.local_symbols.append(allocator, .{
291 .st_name = 0,295 .st_name = 0,
...@@ -466,8 +470,8 @@ pub fn populateMissingMetadata(self: *Elf) !void {...@@ -466,8 +470,8 @@ pub fn populateMissingMetadata(self: *Elf) !void {
466 .p_type = elf.PT_LOAD,470 .p_type = elf.PT_LOAD,
467 .p_offset = off,471 .p_offset = off,
468 .p_filesz = file_size,472 .p_filesz = file_size,
469 .p_vaddr = default_entry_addr,473 .p_vaddr = self.base.options.default_entry_addr,
470 .p_paddr = default_entry_addr,474 .p_paddr = self.base.options.default_entry_addr,
471 .p_memsz = file_size,475 .p_memsz = file_size,
472 .p_align = p_align,476 .p_align = p_align,
473 .p_flags = elf.PF_X | elf.PF_R,477 .p_flags = elf.PF_X | elf.PF_R,
...@@ -486,7 +490,7 @@ pub fn populateMissingMetadata(self: *Elf) !void {...@@ -486,7 +490,7 @@ pub fn populateMissingMetadata(self: *Elf) !void {
486 // TODO instead of hard coding the vaddr, make a function to find a vaddr to put things at.490 // TODO instead of hard coding the vaddr, make a function to find a vaddr to put things at.
487 // we'll need to re-use that function anyway, in case the GOT grows and overlaps something491 // we'll need to re-use that function anyway, in case the GOT grows and overlaps something
488 // else in virtual memory.492 // 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;
490 try self.program_headers.append(self.base.allocator, .{494 try self.program_headers.append(self.base.allocator, .{
491 .p_type = elf.PT_LOAD,495 .p_type = elf.PT_LOAD,
492 .p_offset = off,496 .p_offset = off,