Bug 19617 - ELF: Allow -E to work without -pic/-pie/-shared in the absence of undefined symbols
Summary: ELF: Allow -E to work without -pic/-pie/-shared in the absence of undefined s...
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.27
: P2 enhancement
Target Milestone: 2.27
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-02-11 21:53 UTC by H. Peter Anvin
Modified: 2017-04-21 19:01 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
A patch (312 bytes, patch)
2016-02-11 23:58 UTC, H.J. Lu
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description H. Peter Anvin 2016-02-11 21:53:50 UTC
If neither -pic, -pie, or -shared is specified, *and* there are no undefined symbols in the executable, ld produces no dynamic sections.  However, if -E is specified, the executable is supposed to export its symbols to modules loaded in the future.

This configuration is common in embedded environments, including boot loaders.  The current workaround is to use -pie, but that generates a manifest .rel.dyn section which is pure waste if -pie isn't actually required.
Comment 1 H.J. Lu 2016-02-11 23:58:09 UTC
Created attachment 8979 [details]
A patch

Try this with master branch.
Comment 2 H.J. Lu 2016-02-12 03:45:39 UTC
You also can use

 --dynamic-list FILE         Read dynamic list

to specify which symbols to export.
Comment 3 H. Peter Anvin 2016-02-12 04:08:23 UTC
The patch works.
Comment 4 Sourceware Commits 2016-02-18 11:15:29 UTC
The master branch has been updated by H.J. Lu <hjl@sourceware.org>:

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

commit bf89386a862ace008f0152bca8bddf996d3993c8
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Thu Feb 18 03:13:19 2016 -0800

    Always create dynamic sections for -E/--dynamic-list
    
    In embedded environments, including boot loaders, the non-PIC executable
    needs to export its symbols to modules loaded in the future.  We should
    always create dynamic sections for -E/--dynamic-list.
    
    bfd/
    
    	PR ld/19617
    	* elflink.c (elf_link_add_object_symbols): Always create dynamic
    	sections for -E/--dynamic-list.
    
    ld/
    
    	PR ld/19617
    	* testsuite/ld-elf/pr19617.s: New file.
    	* testsuite/ld-elf/pr19617a.d: Likewise.
    	* testsuite/ld-elf/pr19617b.d: Likewise.
    	* testsuite/ld-elf/pr19617c.d: Likewise.
Comment 5 H.J. Lu 2016-02-18 11:27:56 UTC
Fixed for 2.27.
Comment 6 Sourceware Commits 2016-02-18 15:51:28 UTC
The master branch has been updated by H.J. Lu <hjl@sourceware.org>:

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

commit c304e18e5ca825f57963bd0c5f022fa8f5797b29
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Thu Feb 18 07:48:57 2016 -0800

    Enable PR ld/19617 tests only for Linux/GNU/Solaris
    
    Since PR ld/19617 tests require share library support, enable them
    only for Linux/GNU/Solaris targets.
    
    	* testsuite/ld-elf/pr19617a.d: Enable only for *-*-linux*,
    	*-*-gnu* and *-*-solaris*.
    	* testsuite/ld-elf/pr19617b.d: Likewise.
    	* testsuite/ld-elf/pr19617c.d: Likewise.
Comment 7 Sourceware Commits 2017-04-21 19:01:54 UTC
The master branch has been updated by H.J. Lu <hjl@sourceware.org>:

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

commit 3c5fce9bc29b216af7d10f8d6e4d8c3f11a48359
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Fri Apr 21 12:00:55 2017 -0700

    Require --no-dynamic-linker with -static -E/--dynamic-list
    
    When -static -E/--dynamic-list are passed to linker, linker may create
    executable with dynamic sections which aren't supported by run-time.
    We require --no-dynamic-linker together with -static -E/--dynamic-list
    before adding dynamic symbol table to static executable.
    
    bfd/
    
    	PR ld/19617
    	PR ld/21086
    	* elflink.c (elf_link_add_object_symbols): Require
    	--no-dynamic-linker with -E/--dynamic-list when creating
    	dynamic sections.
    
    ld/
    
    	PR ld/19617
    	PR ld/21086
    	* testsuite/ld-elf/pr19617a.d: Pass --no-dynamic-linker to ld.
    	* testsuite/ld-elf/pr19617b.d: Likewise.
    	* testsuite/ld-elf/pr19617c.d: Likewise.
    	*testsuite/ld-i386/pr19636-4d.d: Likewise.
    	* testsuite/ld-elf/readelf.exp: Pass --no-dynamic-linker to ld
    	with --export-dynamic.
    	* testsuite/ld-elf/shared.exp: Pass --no-dynamic-linker to ld
    	with -E.