authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-09-27 20:05:46+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-09-27 20:05:46+02:00
log8f90dbba557b33db4f84729925bf9773f9c5c168
tree080cd468cd403f7fb4054d2c2f6924d1e2cf78de
parent8b7255c22a9dcdd9396bbd1f7c212a5c2be71dd0

elf: fix typo in selecting larger addrspace for load segments


1 files changed, 5 insertions(+), 4 deletions(-)

src/link/Elf.zig+5-4
...@@ -534,6 +534,7 @@ pub fn populateMissingMetadata(self: *Elf) !void {...@@ -534,6 +534,7 @@ pub fn populateMissingMetadata(self: *Elf) !void {
534 };534 };
535 const ptr_size: u8 = self.ptrWidthBytes();535 const ptr_size: u8 = self.ptrWidthBytes();
536 const is_linux = self.base.options.target.os.tag == .linux;536 const is_linux = self.base.options.target.os.tag == .linux;
537 const large_addrspace = self.base.options.target.ptrBitWidth() >= 32;
537 const image_base = self.calcImageBase();538 const image_base = self.calcImageBase();
538539
539 if (self.phdr_table_index == null) {540 if (self.phdr_table_index == null) {
...@@ -581,7 +582,7 @@ pub fn populateMissingMetadata(self: *Elf) !void {...@@ -581,7 +582,7 @@ pub fn populateMissingMetadata(self: *Elf) !void {
581 }582 }
582583
583 if (self.phdr_got_index == null) {584 if (self.phdr_got_index == null) {
584 const addr: u64 = if (ptr_size >= 4) 0x4000000 else 0x8000;585 const addr: u64 = if (large_addrspace) 0x4000000 else 0x8000;
585 // We really only need ptr alignment but since we are using PROGBITS, linux requires586 // We really only need ptr alignment but since we are using PROGBITS, linux requires
586 // page align.587 // page align.
587 const alignment = if (is_linux) self.page_size else @as(u16, ptr_size);588 const alignment = if (is_linux) self.page_size else @as(u16, ptr_size);
...@@ -594,7 +595,7 @@ pub fn populateMissingMetadata(self: *Elf) !void {...@@ -594,7 +595,7 @@ pub fn populateMissingMetadata(self: *Elf) !void {
594 }595 }
595596
596 if (self.phdr_load_ro_index == null) {597 if (self.phdr_load_ro_index == null) {
597 const addr: u64 = if (ptr_size >= 4) 0xc000000 else 0xa000;598 const addr: u64 = if (large_addrspace) 0xc000000 else 0xa000;
598 const alignment = if (is_linux) self.page_size else @as(u16, ptr_size);599 const alignment = if (is_linux) self.page_size else @as(u16, ptr_size);
599 self.phdr_load_ro_index = try self.allocateSegment(.{600 self.phdr_load_ro_index = try self.allocateSegment(.{
600 .addr = addr,601 .addr = addr,
...@@ -605,7 +606,7 @@ pub fn populateMissingMetadata(self: *Elf) !void {...@@ -605,7 +606,7 @@ pub fn populateMissingMetadata(self: *Elf) !void {
605 }606 }
606607
607 if (self.phdr_load_rw_index == null) {608 if (self.phdr_load_rw_index == null) {
608 const addr: u64 = if (ptr_size >= 4) 0x10000000 else 0xc000;609 const addr: u64 = if (large_addrspace) 0x10000000 else 0xc000;
609 const alignment = if (is_linux) self.page_size else @as(u16, ptr_size);610 const alignment = if (is_linux) self.page_size else @as(u16, ptr_size);
610 self.phdr_load_rw_index = try self.allocateSegment(.{611 self.phdr_load_rw_index = try self.allocateSegment(.{
611 .addr = addr,612 .addr = addr,
...@@ -616,7 +617,7 @@ pub fn populateMissingMetadata(self: *Elf) !void {...@@ -616,7 +617,7 @@ pub fn populateMissingMetadata(self: *Elf) !void {
616 }617 }
617618
618 if (self.phdr_load_zerofill_index == null) {619 if (self.phdr_load_zerofill_index == null) {
619 const addr: u64 = if (ptr_size >= 4) 0x14000000 else 0xf000;620 const addr: u64 = if (large_addrspace) 0x14000000 else 0xf000;
620 const alignment = if (is_linux) self.page_size else @as(u16, ptr_size);621 const alignment = if (is_linux) self.page_size else @as(u16, ptr_size);
621 self.phdr_load_zerofill_index = try self.allocateSegment(.{622 self.phdr_load_zerofill_index = try self.allocateSegment(.{
622 .addr = addr,623 .addr = addr,