From d5d6ada3fd289f932021d1c0b310936f45c1bf48 Mon Sep 17 00:00:00 2001 From: PulkoMandy Date: Fri, 1 Jan 2021 00:39:48 +0100 Subject: [PATCH] sparc: Fix linker script for PIE Our bootloader really doesn't want the executable section to also be writable (even if it needs to, for relocation purposes). Force it to be read-only in program headers by explicitly setting the flags. Change-Id: I5b780f6fd9df5f073f0cbc6cc96bc21479004d2c Reviewed-on: https://review.haiku-os.org/c/haiku/+/3584 Reviewed-by: waddlesplash --- src/system/ldscripts/sparc/kernel.ld | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/system/ldscripts/sparc/kernel.ld b/src/system/ldscripts/sparc/kernel.ld index 58809ffff1..f465690d66 100644 --- a/src/system/ldscripts/sparc/kernel.ld +++ b/src/system/ldscripts/sparc/kernel.ld @@ -6,7 +6,7 @@ ENTRY(_start) PHDRS { headers PT_PHDR PHDRS ; - text PT_LOAD FILEHDR PHDRS ; + text PT_LOAD FILEHDR PHDRS FLAGS(5) ; data PT_LOAD ; dynamic PT_DYNAMIC ; } @@ -42,8 +42,8 @@ SECTIONS .altcodepatch : { *(.altcodepatch) } altcodepatch_end = .; - /* writable data */ - . = ALIGN (0x1000); + /* writable data - in a separate page for memory protection purposes */ + . = ALIGN (0x2000); __data_start = .; .data : { *(.data .data.* .gnu.linkonce.d.*) } :data @@ -58,10 +58,12 @@ SECTIONS .dynamic : { *(.dynamic) } :dynamic :data /* uninitialized data (in same segment as writable data) */ + . = ALIGN(0x8); __bss_start = .; .bss : { *(.bss .bss.* .gnu.linkonce.b.*) } :data - . = ALIGN(0x1000); + /* make sure to end on a page boundary */ + . = ALIGN(0x2000); _end = . ; /* Strip unnecessary stuff */