Bug 27952 - ld: Disallow ET_DYN DF_1_PIE linker input?
Summary: ld: Disallow ET_DYN DF_1_PIE linker input?
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: 2.37
Assignee: Alan Modra
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-06-04 05:46 UTC by Fangrui Song
Modified: 2021-06-12 13:15 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Last reconfirmed: 2021-06-08 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Fangrui Song 2021-06-04 05:46:09 UTC
An input ET_EXEC will cause

% as /dev/null -o a.o
% ld.bfd a.o -o a; ld.bfd a
...
ld.bfd: Using an executable file (a) as input to a link is deprecated - support is likely to be removed in the future

Shall we report a similar error for ET_DYN DF_1_PIE input?

If a DT_NEEDED entry is a PIE, glibc since 2.30 will report something like:
./b: error while loading shared libraries: b: cannot dynamically load position-independent executable
Comment 1 Alan Modra 2021-06-08 05:51:53 UTC
Makes sense.
Comment 2 cvs-commit@gcc.gnu.org 2021-06-11 08:04:39 UTC
The master branch has been updated by Alan Modra <amodra@sourceware.org>:

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

commit f64b9b13ce4bb927f47a1fe0257c3794c6357c8c
Author: Alan Modra <amodra@gmail.com>
Date:   Fri Jun 11 14:06:47 2021 +0930

    PR27952, Disallow ET_DYN DF_1_PIE linker input
    
    This patch adds a new elf_tdata flag, is_pie, set during the linker's
    open_input_bfds processing.  The flag is then used to reject attempts
    to link a PIE as if it were a shared library.
    
    bfd/
            PR 27952
            * elf-bfd.h (struct elf_obj_tdata): Add is_pie.
            * elflink.c (elf_link_add_object_symbols): Set is_pie.
    ld/
            PR 27952
            * ldelf.c (ldelf_after_open): Error on input PIEs too.
Comment 3 Alan Modra 2021-06-12 13:15:38 UTC
Patch applied