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 {
2323 /// Used for calculating how much space to reserve for executable program code in case
2424 /// the binary file deos not already have such a section.
2525 program_code_size_hint: u64 = 256 * 1024,
26 default_entry_addr: u64 = 0x8000000,
26 entry_addr: ?u64 = null,
2727};
2828
2929pub 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
286286 };
287287 errdefer self.deinit();
288288
289 if (options.target.cpu.arch == .spu_2) {
290 self.base.options.default_entry_addr = 0;
291 }
292
293289 // Index 0 is always a null symbol.
294290 try self.local_symbols.append(allocator, .{
295291 .st_name = 0,
......@@ -466,12 +462,13 @@ pub fn populateMissingMetadata(self: *Elf) !void {
466462 const p_align = 0x1000;
467463 const off = self.findFreeSpace(file_size, p_align);
468464 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;
469466 try self.program_headers.append(self.base.allocator, .{
470467 .p_type = elf.PT_LOAD,
471468 .p_offset = off,
472469 .p_filesz = file_size,
473 .p_vaddr = self.base.options.default_entry_addr,
474 .p_paddr = self.base.options.default_entry_addr,
470 .p_vaddr = entry_addr,
471 .p_paddr = entry_addr,
475472 .p_memsz = file_size,
476473 .p_align = p_align,
477474 .p_flags = elf.PF_X | elf.PF_R,
......@@ -490,13 +487,13 @@ pub fn populateMissingMetadata(self: *Elf) !void {
490487 // TODO instead of hard coding the vaddr, make a function to find a vaddr to put things at.
491488 // we'll need to re-use that function anyway, in case the GOT grows and overlaps something
492489 // 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;
494491 try self.program_headers.append(self.base.allocator, .{
495492 .p_type = elf.PT_LOAD,
496493 .p_offset = off,
497494 .p_filesz = file_size,
498 .p_vaddr = default_got_addr,
499 .p_paddr = default_got_addr,
495 .p_vaddr = got_addr,
496 .p_paddr = got_addr,
500497 .p_memsz = file_size,
501498 .p_align = p_align,
502499 .p_flags = elf.PF_R,