It specify a symbol that should be added to the dynamic symbol table (like an addition to --dynamic-list). It can also trigger linking of additional modules from archive (like -u).
https://sourceware.org/pipermail/binutils/2020-May/110930.html [PATCH] ld: Add --export-dynamic-symbol Note, in gold and lld, --export-dynamic-symbol foo does not add foo to .symtab if foo does not exist. I prefer the semantics, but (I don't know hot to implement the semantics) my patch behaves like regular -u: there is an undefined symbol in .symtab . This difference does not really in practice, though.
(In reply to Fangrui Song from comment #1) > https://sourceware.org/pipermail/binutils/2020-May/110930.html [PATCH] ld: > Add --export-dynamic-symbol > > Note, in gold and lld, --export-dynamic-symbol foo does not add foo to > .symtab if foo does not exist. I prefer the semantics, but (I don't know hot When foo is undefined, 1. If foo isn't referenced, --export-dynamic-symbol foo should be NOP since there is nothing to export. 2. If foo is referenced, --export-dynamic-symbol foo should be NOP since foo should be dynamic. > to implement the semantics) my patch behaves like regular -u: there is an > undefined symbol in .symtab . This difference does not really in practice, > though.
You should 1. Extend --dynamic-list* to executables. Symbol binding is unchanged. Only add symbols to dynamic symbol table. 2. Make --export-dynamic-symbol an alias of --dynamic-list* for executables. and ignore --export-dynamic-symbol for -shared. It has to be done at the end of command-line parsing.
Created attachment 12565 [details] A patch
The master branch has been updated by H.J. Lu <hjl@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=37a141bfed4dd3c33d77c15dfde00e4b4f5b24c7 commit 37a141bfed4dd3c33d77c15dfde00e4b4f5b24c7 Author: Fangrui Song <maskray@google.com> Date: Wed Jun 3 06:37:39 2020 -0700 ld: Add --export-dynamic-symbol and --export-dynamic-symbol-list --export-dynamic-symbol-list is like a dynamic list, but without the symbolic property for unspecified symbols. When creating an executable, --export-dynamic-symbol-list is treated like --dynamic-list. When creating a shared library, it is treated like --dynamic-list if -Bsymbolic or --dynamic-list are used, otherwise, it is ignored, so that references to matched symbols will not be bound to the definitions within the shared library. PR ld/25910 * NEWS: Mention --export-dynamic-symbol[-list]. * ld.texi: Document --export-dynamic-symbol[-list]. * ldgram.y: Pass current_dynamic_list_p to lang_append_dynamic_list. * ldlang.c (current_dynamic_list_p): New. (ang_append_dynamic_list): Updated to take a pointer to struct bfd_elf_dynamic_list * argument instead of using link_info.dynamic_list. (lang_append_dynamic_list_cpp_typeinfo): Pass &link_info.dynamic_list to ang_append_dynamic_list. (lang_append_dynamic_list_cpp_new): Likewise. * ldlang.h (current_dynamic_list_p): New. (lang_append_dynamic_list): Add a pointer to struct bfd_elf_dynamic_list * argument. * ldlex.h (option_values): Add OPTION_EXPORT_DYNAMIC_SYMBOL and OPTION_EXPORT_DYNAMIC_SYMBOL_LIST. * lexsup.c (ld_options): Add entries for OPTION_EXPORT_DYNAMIC_SYMBOL and OPTION_EXPORT_DYNAMIC_SYMBOL_LIST. (parse_args): Handle --export-dynamic-symbol and --export-dynamic-symbol-list. * testsuite/ld-dynamic/export-dynamic-symbol-1.d: New. * testsuite/ld-dynamic/export-dynamic-symbol-2.d: New. * testsuite/ld-dynamic/export-dynamic-symbol-glob.d: New. * testsuite/ld-dynamic/export-dynamic-symbol-list-1.d: New. * testsuite/ld-dynamic/export-dynamic-symbol-list-2.d: New. * testsuite/ld-dynamic/export-dynamic-symbol-list-glob.d: New. * testsuite/ld-dynamic/export-dynamic-symbol.exp: New. * testsuite/ld-dynamic/export-dynamic-symbol.s: New. * testsuite/ld-dynamic/foo-bar.list: New. * testsuite/ld-dynamic/foo.list: New. * testsuite/ld-dynamic/foo.s: New. * testsuite/ld-dynamic/fstar.list: New. * testsuite/ld-elf/dlempty.list: New. * testsuite/ld-elf/shared.exp: Add tests for --export-dynamic-symbol and --export-dynamic-symbol-list.
Fixed for 2.35.