PT_GNU_RELRO / 1685382482 does not work in the PHDRS command. % cat a.lds PHDRS { exec PT_LOAD; rw PT_LOAD; dynamic PT_DYNAMIC; relro 1685382482; } SECTIONS { .text : { *(.text) } : exec .dynamic : { *(.data) } : rw : dynamic : relro .data : { *(.data) } : rw } % as /dev/null -o a.o % ./ld-new -T a.lds a.o -o a ./ld-new: BFD (GNU Binutils) 2.37.50.20211014 assertion fail ../../../bfd/elf.c:6262 If I replace 1685382482 with PT_GNU_RELRO, % ./ld-new -T a.lds a.o -o a ./ld-new:a.lds:5: unknown phdr type `PT_GNU_RELRO' (try integer literal)
The master branch has been updated by Nick Clifton <nickc@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=ee9e412f14908c1055cb00fab9307d1723981639 commit ee9e412f14908c1055cb00fab9307d1723981639 Author: Nick Clifton <nickc@redhat.com> Date: Wed Nov 17 15:59:16 2021 +0000 Fix the linker script parser so that it will recognise the PT_GNU_RELRO segment type, and the linker itself so that it will gracefully handle being unable to assign any sections to such a segment. PR 28452 bfd * elf.c (assign_file_positions_for_non_load_sections): Replace assertion with a warning message. ld * ldgram.y: Add support for PT_GNU_RELRO and PT_GNU_PROPERTY. * ldgram.c: Regenerate.
I have applied a small patch so that the PT_GNU_RELRO and PT_GNU_PROPERTY names will be recognised in linker scripts. Plus the linker will now generate a warning message and then continue if it is unable to allocate any sections to the PT_GNU_RELRO segment.