i think static linking should work (produce a static linked executable without any dynamic linker) even with --dynamic-list, now the produced executable is broken. reproducer: echo 'int main(){}' >a.c echo '{main;};' >foo.list gcc -static -Wl,--dynamic-list=foo.list a.c readelf -l a.out |grep interpreter [Requesting program interpreter: /lib/ld64.so.1] (this is on x86_64, but other targets have the same behaviour) introduced in https://sourceware.org/ml/binutils/2016-02/msg00251.html https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=bf89386a862ace008f0152bca8bddf996d3993c8
also discussed at https://sourceware.org/ml/binutils/2017-01/msg00429.html
Since you asked to put "main" in dynamic symbol table, linker does what you requested. If you don't want to put "main" in dynamic symbol table, you shouldn't use -Wl,--dynamic-list=foo.list.
--dynamic-list is not a request to export the symbol in the dynamic symbol table; -E/-rdynamic does that. --dynamic-list is an exclusion list for -Bsymbolic that makes everything not in the list get treated as -Bsymbolic. As for using --dynamic-list, it's gdb (part of the binutils tree) that's using it in its build process and thus breaking static linking.
(In reply to Rich Felker from comment #3) > --dynamic-list is not a request to export the symbol in the dynamic symbol > table; -E/-rdynamic does that. --dynamic-list is an exclusion list for > -Bsymbolic that makes everything not in the list get treated as -Bsymbolic. -E puts all global symbols in dynamic symbol table and --dynamic-list puts symbols listed in file in dynamic symbol table. If no symbols should be put in dynamic symbol table, --dynamic-list shouldn't be used.
Hi guys, I encoutered this bug when trying to compile a static-linked perf. In my option, there were two serious problem here. First of all, ld should never create a broken executable silently. If "-static" is conflicted with any other option, ld should abort and print information about the conflict. Secondly, "--dynamic-list" should be documented more clearly and directly. "Specify the name of a dynamic list file to the linker. This is typically used when creating shared libraries to specify a list of global symbols whose references shouldn't be bound to the definition within the shared library, or creating dynamically linked executables to specify a list of symbols which should be added to the symbol table in the executable." This paragraph(listed above) in man pages is too obscure to tell users what the option really mean. I thinks we should clearly describe what the option do(and some symbol into dynamic symbol table?) first, and then tell users what are the typical scenarios.
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.
Fixed for 2.29.