authorgravatar for noam@pixelhero.devNoam Preil <noam@pixelhero.dev> 2020-08-21 07:25:21-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-08-22 12:45:29-07:00
log222e23c6786e0ac307524c6c91b41782111af82a
tree31a5bee623be801a53293cb40ae28ad405bd9ad0
parent096c5d5e4bf6856fc2250c42a07d1df7c31a1775

Linker: make defaults read-only


2 files changed, 7 insertions(+), 10 deletions(-)

src-self-hosted/link.zig+1-1
...@@ -23,7 +23,7 @@ pub const Options = struct {...@@ -23,7 +23,7 @@ pub const Options = struct {
23 /// 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
24 /// the binary file deos not already have such a section.24 /// the binary file deos not already have such a section.
25 program_code_size_hint: u64 = 256 * 1024,25 program_code_size_hint: u64 = 256 * 1024,
26 default_entry_addr: u64 = 0x8000000,26 entry_addr: ?u64 = null,
27};27};
2828
29pub const File = struct {29pub const File = struct {
src-self-hosted/link/Elf.zig+6-9
...@@ -286,10 +286,6 @@ fn createFile(allocator: *Allocator, file: fs.File, options: link.Options) !Elf...@@ -286,10 +286,6 @@ 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
293 // Index 0 is always a null symbol.289 // Index 0 is always a null symbol.
294 try self.local_symbols.append(allocator, .{290 try self.local_symbols.append(allocator, .{
295 .st_name = 0,291 .st_name = 0,
...@@ -466,12 +462,13 @@ pub fn populateMissingMetadata(self: *Elf) !void {...@@ -466,12 +462,13 @@ pub fn populateMissingMetadata(self: *Elf) !void {
466 const p_align = 0x1000;462 const p_align = 0x1000;
467 const off = self.findFreeSpace(file_size, p_align);463 const off = self.findFreeSpace(file_size, p_align);
468 log.debug("found PT_LOAD free space 0x{x} to 0x{x}\n", .{ off, off + file_size });464 log.debug("found PT_LOAD free space 0x{x} to 0x{x}\n", .{ off, off + file_size });
465 const entry_addr: u64 = self.entry_addr orelse if (self.base.options.target.cpu.arch == .spu_2) @as(u64, 0) else default_entry_addr;
469 try self.program_headers.append(self.base.allocator, .{466 try self.program_headers.append(self.base.allocator, .{
470 .p_type = elf.PT_LOAD,467 .p_type = elf.PT_LOAD,
471 .p_offset = off,468 .p_offset = off,
472 .p_filesz = file_size,469 .p_filesz = file_size,
473 .p_vaddr = self.base.options.default_entry_addr,470 .p_vaddr = entry_addr,
474 .p_paddr = self.base.options.default_entry_addr,471 .p_paddr = entry_addr,
475 .p_memsz = file_size,472 .p_memsz = file_size,
476 .p_align = p_align,473 .p_align = p_align,
477 .p_flags = elf.PF_X | elf.PF_R,474 .p_flags = elf.PF_X | elf.PF_R,
...@@ -490,13 +487,13 @@ pub fn populateMissingMetadata(self: *Elf) !void {...@@ -490,13 +487,13 @@ pub fn populateMissingMetadata(self: *Elf) !void {
490 // TODO instead of hard coding the vaddr, make a function to find a vaddr to put things at.487 // TODO instead of hard coding the vaddr, make a function to find a vaddr to put things at.
491 // we'll need to re-use that function anyway, in case the GOT grows and overlaps something488 // we'll need to re-use that function anyway, in case the GOT grows and overlaps something
492 // else in virtual memory.489 // else in virtual memory.
493 const default_got_addr = if (self.base.options.target.cpu.arch.ptrBitWidth() == 16) @as(u32, 0x8000) else 0x4000000;490 const got_addr = if (self.base.options.target.cpu.arch.ptrBitWidth() == 16) @as(u32, 0x8000) else 0x4000000;
494 try self.program_headers.append(self.base.allocator, .{491 try self.program_headers.append(self.base.allocator, .{
495 .p_type = elf.PT_LOAD,492 .p_type = elf.PT_LOAD,
496 .p_offset = off,493 .p_offset = off,
497 .p_filesz = file_size,494 .p_filesz = file_size,
498 .p_vaddr = default_got_addr,495 .p_vaddr = got_addr,
499 .p_paddr = default_got_addr,496 .p_paddr = got_addr,
500 .p_memsz = file_size,497 .p_memsz = file_size,
501 .p_align = p_align,498 .p_align = p_align,
502 .p_flags = elf.PF_R,499 .p_flags = elf.PF_R,