Bug 28452 - ld: unknown phdr type `PT_GNU_RELRO' (try integer literal)
Summary: ld: unknown phdr type `PT_GNU_RELRO' (try integer literal)
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
Depends on:
Reported: 2021-10-14 16:51 UTC by Fangrui Song
Modified: 2021-11-17 16:02 UTC (History)
1 user (show)

See Also:
Last reconfirmed:


Note You need to log in before you can comment on or make changes to this bug.
Description Fangrui Song 2021-10-14 16:51:27 UTC
PT_GNU_RELRO / 1685382482 does not work in the PHDRS command.

% cat a.lds
  exec PT_LOAD;
  rw   PT_LOAD;
  dynamic PT_DYNAMIC;
  relro 1685382482;
  .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) 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)
Comment 1 cvs-commit@gcc.gnu.org 2021-11-17 16:01:00 UTC
The master branch has been updated by Nick Clifton <nickc@sourceware.org>:


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.
Comment 2 Nick Clifton 2021-11-17 16:02:52 UTC
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.