[PATCH v2 19/21] riscv: linker script: create separate PT_LOAD segments for text, rodata, and data
Ahmad Fatoum
a.fatoum at pengutronix.de
Tue Jan 6 06:12:59 PST 2026
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?
Cheers,
Ahmad
--
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