[PATCH v2 19/21] riscv: linker script: create separate PT_LOAD segments for text, rodata, and data
Sascha Hauer
s.hauer at pengutronix.de
Thu Jan 8 07:25:14 PST 2026
On Tue, Jan 06, 2026 at 03:12:59PM +0100, Ahmad Fatoum wrote:
> Hi,
>
> On 1/6/26 1:53 PM, Sascha Hauer wrote:
> > Fix the linker script to generate three distinct PT_LOAD segments with
> > correct permissions instead of combining .rodata with .data.
>
> Does this need to be moved before the previous patch to avoid
> intermittent breakage?
>
> > Before this fix, the linker auto-generated only two PT_LOAD segments:
> > 1. Text segment (PF_R|PF_X)
> > 2. Data segment (PF_R|PF_W) - containing .rodata, .data, .bss, etc.
> >
> > This caused .rodata to be mapped with write permissions when
> > riscv_mmu_setup_from_elf() or riscv_pmp_setup_from_elf() set up memory
> > permissions based on ELF segments, defeating the W^X protection.
> >
> > With explicit PHDRS directives, we now generate three segments:
> > 1. text segment (PF_R|PF_X): .text and related code sections
> > 2. rodata segment (PF_R): .rodata and related read-only sections
> > 3. data segment (PF_R|PF_W): .data, .bss, and related sections
> >
> > This ensures riscv_mmu_setup_from_elf() and riscv_pmp_setup_from_elf()
> > correctly map .rodata as read-only instead of read-write.
> >
> > Also update the prelink script to handle binaries without a PT_DYNAMIC
> > segment, as the new PHDRS layout may result in this case.
>
> Did you observe this happening?
I did during development, but not any longer. Maybe this is no longer
necessary due to other changes. I'll remove that for now.
Sascha
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
More information about the barebox
mailing list