Bug 25585

Summary: [2.34 Regression] error: PHDR segment not covered by LOAD segment
Product: binutils Reporter: H.J. Lu <hjl.tools>
Component: ldAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED INVALID    
Severity: normal CC: amodra
Priority: P2    
Version: 2.35   
Target Milestone: ---   
Host: Target:
Build: Last reconfirmed:
Bug Depends on:    
Bug Blocks: 4499    

Description H.J. Lu 2020-02-21 13:07:54 UTC
When building ACRN hypervisor:

https://github.com/projectacrn/acrn-hypervisor

on Fedora 31/x86-64 with

$ dnf install python3-pip
$ pip3 install kconfiglib
$ make all BOARD=nuc7i7dnb SCENARIO=industry RELEASE=0

I got

cc -Wl,-Map=/export/gnu/import/git/github/acrn-hypervisor/build/hypervisor/acrn.map -o /export/gnu/import/git/github/acrn-hypervisor/build/hypervisor/acrn.out  -Wl,--gc-sections -nostartfiles -nostdlib -Wl,-n,-z,max-page-size=0x1000 -pie -z noreloc-overflow   -T/export/gnu/import/git/github/acrn-hypervisor/build/hypervisor/link_ram.ld \
	-Wl,--start-group /export/gnu/import/git/github/acrn-hypervisor/build/hypervisor/modules/lib_mod.a /export/gnu/import/git/github/acrn-hypervisor/build/hypervisor/modules/boot_mod.a /export/gnu/import/git/github/acrn-hypervisor/build/hypervisor/modules/hw_mod.a /export/gnu/import/git/github/acrn-hypervisor/build/hypervisor/modules/vp_base_mod.a /export/gnu/import/git/github/acrn-hypervisor/build/hypervisor/modules/vp_dm_mod.a /export/gnu/import/git/github/acrn-hypervisor/build/hypervisor/modules/vp_trusty_mod.a /export/gnu/import/git/github/acrn-hypervisor/build/hypervisor/modules/vp_hcall_mod.a /export/gnu/import/git/github/acrn-hypervisor/build/hypervisor/modules/libdebug.a /export/gnu/import/git/github/acrn-hypervisor/build/hypervisor/modules/sys_init_mod.a -Wl,--end-group
/usr/local/bin/ld: /export/gnu/import/git/github/acrn-hypervisor/build/hypervisor/acrn.out: error: PHDR segment not covered by LOAD segment
collect2: error: ld returned 1 exit status

This is caused by

commit 30fe183248b2523ecff9da36853e2f893c4c4b91
Author: Alan Modra <amodra@gmail.com>
Date:   Wed Oct 23 17:40:51 2019 +1030

    PR4499, assign file positions assumes segment offsets increasing
    
    This rewrites much of assign_file_positions_for_non_load_sections to
    allow objcopy and strip to handle cases like that in PR4499 where
    program headers were not in their usual position immediately after the
    ELF file header, and PT_LOAD headers were not sorted by paddr.
Comment 1 Alan Modra 2020-02-22 00:27:40 UTC
This isn't a binutils bug, unless you believe that "PHDR segment not covered by LOAD segment" should not cause a link error.  I think the ELF standard is quite clear: "PT_PHDR ... may occur only if the program header table is part of the memory image of the program"

binutils-2.30, 2.31, 2.32 and 2.33 all generate a PHDR that isn't loaded by any LOAD segment, but the code checking for that problem was ineffective.  This needs fixing in the linker script used by the project, or since it seems like the binary being generated is never meant to run directly on a glibc system, by linking with --no-dynamic-linker.
Comment 2 Sourceware Commits 2020-02-22 02:39:10 UTC
The master branch has been updated by Alan Modra <amodra@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=7b3c27152b5695177a2cd5adc0d7b0255f99aca0

commit 7b3c27152b5695177a2cd5adc0d7b0255f99aca0
Author: Alan Modra <amodra@gmail.com>
Date:   Sat Feb 22 12:46:33 2020 +1030

    PR25585, PHDR segment not covered by LOAD segment
    
    I closed this bug as invalid, but I think it is worth mentioning in NEWS
    that older linkers didn't check PT_PHDR very well.  The patch also allows
    people to force an output file with --noinhibit-exec after the error.
    
    bfd/
    	PR 25585
    	* elf.c (assign_file_positions_for_load_sections): Continue linking
    	on "PHDR segment not covered by LOAD segment" errors.
    ld/
    	PR 25585
    	* NEWS: Mention better "PHDR segment not covered by LOAD segment"
    	checking.
Comment 3 Sourceware Commits 2020-02-22 03:05:45 UTC
The binutils-2_34-branch branch has been updated by Alan Modra <amodra@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=acc4a8b8ac83077819948126bc7501d35eb1ea74

commit acc4a8b8ac83077819948126bc7501d35eb1ea74
Author: Alan Modra <amodra@gmail.com>
Date:   Sat Feb 22 12:46:33 2020 +1030

    PR25585, PHDR segment not covered by LOAD segment
    
    I closed this bug as invalid, but I think it is worth mentioning in NEWS
    that older linkers didn't check PT_PHDR very well.  The patch also allows
    people to force an output file with --noinhibit-exec after the error.
    
    bfd/
    	PR 25585
    	* elf.c (assign_file_positions_for_load_sections): Continue linking
    	on "PHDR segment not covered by LOAD segment" errors.
    ld/
    	PR 25585
    	* NEWS: Mention better "PHDR segment not covered by LOAD segment"
    	checking.
    
    (cherry picked from commit 7b3c27152b5695177a2cd5adc0d7b0255f99aca0)