[PATCH] ld: Add --export-dynamic-symbol and --export-dynamic-symbol-list

H.J. Lu hjl.tools@gmail.com
Wed May 13 15:36:20 GMT 2020


On Wed, May 13, 2020 at 8:24 AM Fangrui Song <maskray@google.com> wrote:
>
> On 2020-05-13, H.J. Lu wrote:
> >On Tue, May 12, 2020 at 9:38 PM Fangrui Song <maskray@google.com> wrote:
> >>
> >> On 2020-05-11, H.J. Lu wrote:
> >> >On Sun, May 10, 2020 at 11:46 PM Fangrui Song <maskray@google.com> wrote:
> >> >>
> >> >> On 2020-05-08, H.J. Lu wrote:
> >> >> >On Fri, May 8, 2020 at 8:12 AM Fangrui Song <maskray@google.com> wrote:
> >> >> >>
> >> >> >>
> >> >> >> On 2020-05-08, H.J. Lu wrote:
> >> >> >> >On Fri, May 8, 2020 at 7:54 AM Fangrui Song <maskray@google.com> wrote:
> >> >> >> >>
> >> >> >> >> On 2020-05-08, H.J. Lu wrote:
> >> >> >> >> >On Wed, May 6, 2020 at 11:42 AM Fangrui Song <maskray@google.com> wrote:
> >> >> >> >> >>
> >> >> >> >> >> On 2020-05-05, H.J. Lu wrote:
> >> >> >> >> >> >On Tue, May 5, 2020 at 9:55 AM Fangrui Song <maskray@google.com> wrote:
> >> >> >> >> >> >>
> >> >> >> >> >> >>
> >> >> >> >> >> >> On 2020-05-05, H.J. Lu wrote:
> >> >> >> >> >> >> >On Tue, May 5, 2020 at 8:30 AM Fangrui Song <maskray@google.com> wrote:
> >> >> >> >> >> >> >>
> >> >> >> >> >> >> >> On 2020-05-05, H.J. Lu wrote:
> >> >> >> >> >> >> >> >On Mon, May 4, 2020 at 7:10 PM Fangrui Song <maskray@google.com> wrote:
> >> >> >> >> >> >> >> >>
> >> >> >> >> >> >> >> >> On 2020-05-04, H.J. Lu wrote:
> >> >> >> >> >> >> >> >> >On Mon, May 4, 2020 at 10:48 AM Fangrui Song <maskray@google.com> wrote:
> >> >> >> >> >> >> >> >> >>
> >> >> >> >> >> >> >> >> >> On 2020-05-03, H.J. Lu wrote:
> >> >> >> >> >> >> >> >> >> >On Sat, May 2, 2020 at 11:15 PM Fangrui Song via Binutils
> >> >> >> >> >> >> >> >> >> ><binutils@sourceware.org> wrote:
> >> >> >> >> >> >> >> >> >> >>
> >> >> >> >> >> >> >> >> >> >>         PR ld/25910
> >> >> >> >> >> >> >> >> >> >>         * ldlang.c (export_dynamic_symbol_list): New.
> >> >> >> >> >> >> >> >> >> >>         (ldlang_add_export_dynamic_symbol): New.
> >> >> >> >> >> >> >> >> >> >>         (lang_place_export_dynamic_symbols): New.
> >> >> >> >> >> >> >> >> >> >>         (lang_process): Handle export_dynamic_symbol_list.
> >> >> >> >> >> >> >> >> >> >>         * ldlang.h (ldlang_add_export_dynamic_symbol): New.
> >> >> >> >> >> >> >> >> >> >>         * ldlex.h (option_values): Add OPTION_EXPORT_DYNAMIC_SYMBOL.
> >> >> >> >> >> >> >> >> >> >>         * lexsup.c (ld_options): Add entry for OPTION_EXPORT_DYNAMIC_SYMBOL.
> >> >> >> >> >> >> >> >> >> >>         (parse_args): Handle it.
> >> >> >> >> >> >> >> >> >> >>         * ld.texi: Add --export-dynamic-symbol documentation.
> >> >> >> >> >> >> >> >> >> >>         * testsuite/ld-undefined/export-dynamic-symbol.exp: Run new test.
> >> >> >> >> >> >> >> >> >> >>         * testsuite/ld-undefined/export-dynamic-symbol-1.d: New.
> >> >> >> >> >> >> >> >> >> >> ---
> >> >> >> >> >> >> >> >> >> >>  ld/ld.texi                                    |  8 +++++
> >> >> >> >> >> >> >> >> >> >>  ld/ldlang.c                                   | 26 ++++++++++++++
> >> >> >> >> >> >> >> >> >> >>  ld/ldlang.h                                   |  2 ++
> >> >> >> >> >> >> >> >> >> >>  ld/ldlex.h                                    |  1 +
> >> >> >> >> >> >> >> >> >> >>  ld/lexsup.c                                   |  7 ++++
> >> >> >> >> >> >> >> >> >> >>  .../ld-undefined/export-dynamic-symbol-1.d    |  8 +++++
> >> >> >> >> >> >> >> >> >> >>  .../ld-undefined/export-dynamic-symbol.exp    | 35 +++++++++++++++++++
> >> >> >> >> >> >> >> >> >> >>  7 files changed, 87 insertions(+)
> >> >> >> >> >> >> >> >> >> >>  create mode 100644 ld/testsuite/ld-undefined/export-dynamic-symbol-1.d
> >> >> >> >> >> >> >> >> >> >>  create mode 100644 ld/testsuite/ld-undefined/export-dynamic-symbol.exp
> >> >> >> >> >> >> >> >> >> >>
> >> >> >> >> >> >> >> >> >> >> diff --git a/ld/ld.texi b/ld/ld.texi
> >> >> >> >> >> >> >> >> >> >> index 4dc78e65fa..b3dc95f314 100644
> >> >> >> >> >> >> >> >> >> >> --- a/ld/ld.texi
> >> >> >> >> >> >> >> >> >> >> +++ b/ld/ld.texi
> >> >> >> >> >> >> >> >> >> >> @@ -569,6 +569,14 @@ Note that this option is specific to ELF targeted ports.  PE targets
> >> >> >> >> >> >> >> >> >> >>  support a similar function to export all symbols from a DLL or EXE; see
> >> >> >> >> >> >> >> >> >> >>  the description of @samp{--export-all-symbols} below.
> >> >> >> >> >> >> >> >> >> >>
> >> >> >> >> >> >> >> >> >> >> +@kindex --export-dynamic-symbol=@var{symbol}
> >> >> >> >> >> >> >> >> >> >> +@cindex export dynamic symbol
> >> >> >> >> >> >> >> >> >> >> +@item --export-dynamic-symbol=@var{symbol}
> >> >> >> >> >> >> >> >> >> >> +Specify a symbol that should be added to the dynamic symbol table.
> >> >> >> >> >> >> >> >> >> >> +Additionally, force @var{symbol} to be entered in the output file as an
> >> >> >> >> >> >> >> >> >> >> +undefined symbol.  Doing this may, for example, trigger linking of additional
> >> >> >> >> >> >> >> >> >> >> +modules from archives.
> >> >> >> >> >> >> >> >> >> >> +
> >> >> >> >> >> >> >> >> >> >>  @ifclear SingleFormat
> >> >> >> >> >> >> >> >> >> >>  @cindex big-endian objects
> >> >> >> >> >> >> >> >> >> >>  @cindex endianness
> >> >> >> >> >> >> >> >> >> >> diff --git a/ld/ldlang.c b/ld/ldlang.c
> >> >> >> >> >> >> >> >> >> >> index b2cdb3603a..e7ecdfeaf0 100644
> >> >> >> >> >> >> >> >> >> >> --- a/ld/ldlang.c
> >> >> >> >> >> >> >> >> >> >> +++ b/ld/ldlang.c
> >> >> >> >> >> >> >> >> >> >> @@ -3910,6 +3910,26 @@ lang_place_undefineds (void)
> >> >> >> >> >> >> >> >> >> >>      insert_undefined (ptr->name);
> >> >> >> >> >> >> >> >> >> >>  }
> >> >> >> >> >> >> >> >> >> >>
> >> >> >> >> >> >> >> >> >> >> +static struct bfd_sym_chain export_dynamic_symbol_list = { NULL, NULL };
> >> >> >> >> >> >> >> >> >> >> +
> >> >> >> >> >> >> >> >> >> >> +void
> >> >> >> >> >> >> >> >> >> >> +ldlang_add_export_dynamic_symbol (const char *const name)
> >> >> >> >> >> >> >> >> >> >> +{
> >> >> >> >> >> >> >> >> >> >> +  struct bfd_sym_chain *sym;
> >> >> >> >> >> >> >> >> >> >> +  sym = stat_alloc (sizeof (*sym));
> >> >> >> >> >> >> >> >> >> >> +  sym->name = xstrdup (name);
> >> >> >> >> >> >> >> >> >> >> +  sym->next = export_dynamic_symbol_list.next;
> >> >> >> >> >> >> >> >> >> >> +  export_dynamic_symbol_list.next = sym;
> >> >> >> >> >> >> >> >> >> >> +}
> >> >> >> >> >> >> >> >> >> >> +
> >> >> >> >> >> >> >> >> >> >> +static void
> >> >> >> >> >> >> >> >> >> >> +lang_place_export_dynamic_symbols (void)
> >> >> >> >> >> >> >> >> >> >> +{
> >> >> >> >> >> >> >> >> >> >> +  struct bfd_sym_chain *sym;
> >> >> >> >> >> >> >> >> >> >> +  for (sym = export_dynamic_symbol_list.next; sym != NULL; sym = sym->next)
> >> >> >> >> >> >> >> >> >> >> +    insert_undefined (sym->name);
> >> >> >> >> >> >> >> >> >> >> +}
> >> >> >> >> >> >> >> >> >> >> +
> >> >> >> >> >> >> >> >> >> >>  /* Structure used to build the list of symbols that the user has required
> >> >> >> >> >> >> >> >> >> >>     be defined.  */
> >> >> >> >> >> >> >> >> >> >>
> >> >> >> >> >> >> >> >> >> >> @@ -7795,6 +7815,10 @@ void
> >> >> >> >> >> >> >> >> >> >>  lang_process (void)
> >> >> >> >> >> >> >> >> >> >>  {
> >> >> >> >> >> >> >> >> >> >>    /* Finalize dynamic list.  */
> >> >> >> >> >> >> >> >> >> >> +  struct bfd_sym_chain *sym;
> >> >> >> >> >> >> >> >> >> >> +  for (sym = export_dynamic_symbol_list.next; sym != NULL; sym = sym->next)
> >> >> >> >> >> >> >> >> >> >> +    lang_append_dynamic_list (
> >> >> >> >> >> >> >> >> >> >> +        lang_new_vers_pattern (NULL, sym->name, NULL, FALSE));
> >> >> >> >> >> >> >> >> >> >>    if (link_info.dynamic_list)
> >> >> >> >> >> >> >> >> >> >>      lang_finalize_version_expr_head (&link_info.dynamic_list->head);
> >> >> >> >> >> >> >> >> >> >>
> >> >> >> >> >> >> >> >> >> >> @@ -7808,6 +7832,8 @@ lang_process (void)
> >> >> >> >> >> >> >> >> >> >>
> >> >> >> >> >> >> >> >> >> >>    /* Add to the hash table all undefineds on the command line.  */
> >> >> >> >> >> >> >> >> >> >>    lang_place_undefineds ();
> >> >> >> >> >> >> >> >> >> >> +  /* Add --export-dynamic-symbol symbols to the hash table.  */
> >> >> >> >> >> >> >> >> >> >> +  lang_place_export_dynamic_symbols ();
> >> >> >> >> >> >> >> >> >> >>
> >> >> >> >> >> >> >> >> >> >>    if (!bfd_section_already_linked_table_init ())
> >> >> >> >> >> >> >> >> >> >>      einfo (_("%F%P: can not create hash table: %E\n"));
> >> >> >> >> >> >> >> >> >> >> diff --git a/ld/ldlang.h b/ld/ldlang.h
> >> >> >> >> >> >> >> >> >> >> index 2aa3930f95..8c004b173c 100644
> >> >> >> >> >> >> >> >> >> >> --- a/ld/ldlang.h
> >> >> >> >> >> >> >> >> >> >> +++ b/ld/ldlang.h
> >> >> >> >> >> >> >> >> >> >> @@ -606,6 +606,8 @@ extern lang_output_section_statement_type *next_matching_output_section_statemen
> >> >> >> >> >> >> >> >> >> >>    (lang_output_section_statement_type *, int);
> >> >> >> >> >> >> >> >> >> >>  extern void ldlang_add_undef
> >> >> >> >> >> >> >> >> >> >>    (const char *const, bfd_boolean);
> >> >> >> >> >> >> >> >> >> >> +extern void ldlang_add_export_dynamic_symbol
> >> >> >> >> >> >> >> >> >> >> +  (const char *const);
> >> >> >> >> >> >> >> >> >> >>  extern void ldlang_add_require_defined
> >> >> >> >> >> >> >> >> >> >>    (const char *const);
> >> >> >> >> >> >> >> >> >> >>  extern void lang_add_output_format
> >> >> >> >> >> >> >> >> >> >> diff --git a/ld/ldlex.h b/ld/ldlex.h
> >> >> >> >> >> >> >> >> >> >> index 22b928d2d9..70f2da5636 100644
> >> >> >> >> >> >> >> >> >> >> --- a/ld/ldlex.h
> >> >> >> >> >> >> >> >> >> >> +++ b/ld/ldlex.h
> >> >> >> >> >> >> >> >> >> >> @@ -81,6 +81,7 @@ enum option_values
> >> >> >> >> >> >> >> >> >> >>    OPTION_DYNAMIC_LIST_CPP_NEW,
> >> >> >> >> >> >> >> >> >> >>    OPTION_DYNAMIC_LIST_CPP_TYPEINFO,
> >> >> >> >> >> >> >> >> >> >>    OPTION_DYNAMIC_LIST_DATA,
> >> >> >> >> >> >> >> >> >> >> +  OPTION_EXPORT_DYNAMIC_SYMBOL,
> >> >> >> >> >> >> >> >> >> >>    OPTION_WARN_COMMON,
> >> >> >> >> >> >> >> >> >> >>    OPTION_WARN_CONSTRUCTORS,
> >> >> >> >> >> >> >> >> >> >>    OPTION_WARN_FATAL,
> >> >> >> >> >> >> >> >> >> >> diff --git a/ld/lexsup.c b/ld/lexsup.c
> >> >> >> >> >> >> >> >> >> >> index d1955b9afa..0a0c2f2873 100644
> >> >> >> >> >> >> >> >> >> >> --- a/ld/lexsup.c
> >> >> >> >> >> >> >> >> >> >> +++ b/ld/lexsup.c
> >> >> >> >> >> >> >> >> >> >> @@ -504,6 +504,8 @@ static const struct ld_option ld_options[] =
> >> >> >> >> >> >> >> >> >> >>      '\0', NULL, N_("Use C++ typeinfo dynamic list"), TWO_DASHES },
> >> >> >> >> >> >> >> >> >> >>    { {"dynamic-list", required_argument, NULL, OPTION_DYNAMIC_LIST},
> >> >> >> >> >> >> >> >> >> >>      '\0', N_("FILE"), N_("Read dynamic list"), TWO_DASHES },
> >> >> >> >> >> >> >> >> >> >> +  { {"export-dynamic-symbol", required_argument, NULL, OPTION_EXPORT_DYNAMIC_SYMBOL},
> >> >> >> >> >> >> >> >> >> >> +    '\0', N_("SYMBOL"), N_("Read dynamic list"), TWO_DASHES },
> >> >> >> >> >> >> >> >> >> >>    { {"warn-common", no_argument, NULL, OPTION_WARN_COMMON},
> >> >> >> >> >> >> >> >> >> >>      '\0', NULL, N_("Warn about duplicate common symbols"), TWO_DASHES },
> >> >> >> >> >> >> >> >> >> >>    { {"warn-constructors", no_argument, NULL, OPTION_WARN_CONSTRUCTORS},
> >> >> >> >> >> >> >> >> >> >> @@ -1425,6 +1427,11 @@ parse_args (unsigned argc, char **argv)
> >> >> >> >> >> >> >> >> >> >>           if (opt_symbolic == symbolic)
> >> >> >> >> >> >> >> >> >> >>             opt_symbolic = symbolic_unset;
> >> >> >> >> >> >> >> >> >> >>           break;
> >> >> >> >> >> >> >> >> >> >> +       case OPTION_EXPORT_DYNAMIC_SYMBOL:
> >> >> >> >> >> >> >> >> >> >> +         ldlang_add_export_dynamic_symbol (optarg);
> >> >> >> >> >> >> >> >> >> >> +         if (opt_dynamic_list != dynamic_list_data)
> >> >> >> >> >> >> >> >> >> >> +           opt_dynamic_list = dynamic_list;
> >> >> >> >> >> >> >> >> >> >> +         break;
> >> >> >> >> >> >> >> >> >> >>         case OPTION_WARN_COMMON:
> >> >> >> >> >> >> >> >> >> >>           config.warn_common = TRUE;
> >> >> >> >> >> >> >> >> >> >>           break;
> >> >> >> >> >> >> >> >> >> >> diff --git a/ld/testsuite/ld-undefined/export-dynamic-symbol-1.d b/ld/testsuite/ld-undefined/export-dynamic-symbol-1.d
> >> >> >> >> >> >> >> >> >> >> new file mode 100644
> >> >> >> >> >> >> >> >> >> >> index 0000000000..768bf0abd6
> >> >> >> >> >> >> >> >> >> >> --- /dev/null
> >> >> >> >> >> >> >> >> >> >> +++ b/ld/testsuite/ld-undefined/export-dynamic-symbol-1.d
> >> >> >> >> >> >> >> >> >> >> @@ -0,0 +1,8 @@
> >> >> >> >> >> >> >> >> >> >> +#name: --export-dynamic-symbol foo archive
> >> >> >> >> >> >> >> >> >> >> +#source: require-defined.s
> >> >> >> >> >> >> >> >> >> >> +#ld: -pie --export-dynamic-symbol foo tmpdir/libentry.a
> >> >> >> >> >> >> >> >> >> >
> >> >> >> >> >> >> >> >> >> >I assume that it supports
> >> >> >> >> >> >> >> >> >> >
> >> >> >> >> >> >> >> >> >> >$ ld -pie --export-dynamic-symbol foo --export-dynamic-symbol bar ...
> >> >> >> >> >> >> >> >> >> >
> >> >> >> >> >> >> >> >> >> >Please add another --export-dynamic-symbol to your test.
> >> >> >> >> >> >> >> >> >> >
> >> >> >> >> >> >> >> >> >> >--
> >> >> >> >> >> >> >> >> >> >H.J.
> >> >> >> >> >> >> >> >> >>
> >> >> >> >> >> >> >> >> >> I face a test difficulty. If I add another `#nm:`, runtest complains:
> >> >> >> >> >> >> >> >> >>
> >> >> >> >> >> >> >> >> >> % cd Debug/ld
> >> >> >> >> >> >> >> >> >> % runtest --tool ld --srcdir ../../ld/testsuite/ export-dynamic-symbol.exp
> >> >> >> >> >> >> >> >> >> ...
> >> >> >> >> >> >> >> >> >> ERROR: option nm multiply set in ../../ld/testsuite/ld-undefined/export-dynamic-symbol-1.d
> >> >> >> >> >> >> >> >> >>
> >> >> >> >> >> >> >> >> >> There may also be a problem of symbol table order determinism. I don't
> >> >> >> >> >> >> >> >> >> know whether another symbol may be ordered before foo in some ports and
> >> >> >> >> >> >> >> >> >> after foo in other ports.
> >> >> >> >> >> >> >> >> >>
> >> >> >> >> >> >> >> >> >> Honestly, I think for a number of tests, even if they test generic
> >> >> >> >> >> >> >> >> >> behavior, it might be fine to restrict them to run on certain hosts,
> >> >> >> >> >> >> >> >> >> e.g. Linux x86. What I know about testing is lacking, though, I don't
> >> >> >> >> >> >> >> >> >> know what can be tested.
> >> >> >> >> >> >> >> >> >>
> >> >> >> >> >> >> >> >> >> Ideally `#nm:` should just be free-form shell scripts but unfortunately
> >> >> >> >> >> >> >> >> >> it seems to support very limited features (undocumented?)
> >> >> >> >> >> >> >> >> >
> >> >> >> >> >> >> >> >> >You can't add another #nm.  But you can pass additional options to nm.
> >> >> >> >> >> >> >> >> >
> >> >> >> >> >> >> >> >> >--
> >> >> >> >> >> >> >> >> >H.J.
> >> >> >> >> >> >> >> >>
> >> >> >> >> >> >> >> >> Attached PATCH v2.
> >> >> >> >> >> >> >> >>
> >> >> >> >> >> >> >> >> Added export-dynamic-symbol-2.d
> >> >> >> >> >> >> >> >
> >> >> >> >> >> >> >> >There is
> >> >> >> >> >> >> >> >
> >> >> >> >> >> >> >> >'--dynamic-list=DYNAMIC-LIST-FILE'
> >> >> >> >> >> >> >> >     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 option is only
> >> >> >> >> >> >> >> >     meaningful on ELF platforms which support shared libraries.
> >> >> >> >> >> >> >> >
> >> >> >> >> >> >> >> >The new --export-dynamic-symbol option puts it on command-line
> >> >> >> >> >> >> >> >and implicitly adds -u.  This makes the new option different from
> >> >> >> >> >> >> >> >--dynamic-list.  I don't think -u should be added implicitly.  If needed,
> >> >> >> >> >> >> >> >you should add another option to add -u for all symbols on dynamic
> >> >> >> >> >> >> >> >list.
> >> >> >> >> >> >> >> >
> >> >> >> >> >> >> >> >--
> >> >> >> >> >> >> >> >H.J.
> >> >> >> >> >> >> >>
> >> >> >> >> >> >> >> I would also hope gold did not add -u. I don't particularly like it (see
> >> >> >> >> >> >> >> also https://reviews.llvm.org/D43103)
> >> >> >> >> >> >> >
> >> >> >> >> >> >> >Please drop implicit -u.
> >> >> >> >> >> >>
> >> >> >> >> >> >> Done. Attached PATCH v3.
> >> >> >> >> >> >> Improved tests to check a glob pattern and multiple --export-dynamic-symbol.
> >> >> >> >> >> >>
> >> >> >> >> >> >> Moved ld-undefined/ to ld-dynamic/ since the feature is decoupled from -u now.
> >> >> >> >> >> >>
> >> >> >> >> >> >> >> If you think we can correct this, I think it should be fine.
> >> >> >> >> >> >> >
> >> >> >> >> >> >> >Please open a gold bug for this.
> >> >> >> >> >> >> >
> >> >> >> >> >> >> >Thanks.
> >> >> >> >> >> >> >
> >> >> >> >> >> >> >--
> >> >> >> >> >> >> >H.J.
> >> >> >> >> >> >>
> >> >> >> >> >> >> Filed https://sourceware.org/bugzilla/show_bug.cgi?id=25925 (--export-dynamic-symbol should drop implicit -u)
> >> >> >> >> >> >>
> >> >> >> >> >> >>
> >> >> >> >> >> >> I may have to migrate some internal projects if they rely on the
> >> >> >> >> >> >> --export-dynamic-symbol semantics, but hopefully there will not be much
> >> >> >> >> >> >> work. I am glad that --export-dynamic-symbol semantic will be orthogonal!
> >> >> >> >> >> >
> >> >> >> >> >> >+ case OPTION_EXPORT_DYNAMIC_SYMBOL:
> >> >> >> >> >> >+   ldlang_add_export_dynamic_symbol (optarg);
> >> >> >> >> >> >
> >> >> >> >> >> >Can you simply call
> >> >> >> >> >> >
> >> >> >> >> >> >lang_append_dynamic_list (lang_new_vers_pattern (NULL, optarg, NULL, FALSE));
> >> >> >> >> >> >
> >> >> >> >> >> >here?
> >> >> >> >> >> >
> >> >> >> >> >> >--
> >> >> >> >> >> >H.J.
> >> >> >> >> >>
> >> >> >> >> >> Attached PATCH v4, which also handles -shared.  The previous patches do not handle -shared.
> >> >> >> >> >> Added two tests to ld-elf/shared.exp
> >> >> >> >> >>
> >> >> >> >> >> The updated semantics:
> >> >> >> >> >>
> >> >> >> >> >> + @kindex --export-dynamic-symbol=@var{glob}
> >> >> >> >> >> + @cindex export dynamic symbol
> >> >> >> >> >> + @item --export-dynamic-symbol=@var{glob}
> >> >> >> >> >> + When creating a dynamically linked executable, symbols matching
> >> >> >> >> >> + @var{glob} will be added to the dynamic symbol table. When creating a
> >> >> >> >> >> + shared library, references to symbols matching @var{glob} will not be
> >> >> >> >> >> + bound to the definitions within the shared library. This option is a
> >> >> >> >> >> + no-op when creating a shared library and @samp{--dynamic-list} is not
> >> >> >> >> >> + specified. This option is only meaningful on ELF platforms which
> >> >> >> >> >> + support shared libraries.
> >> >> >> >> >>
> >> >> >> >> >> i.e. --export-dynamic-symbol is like addition to --dynamic-list,
> >> >> >> >> >> except: -shared --export-dynamic-symbol without --dynamic-list will not
> >> >> >> >> >> act as -Bsymbolic.
> >> >> >> >> >>
> >> >> >> >> >> In the option processing loop, we cannot call lang_append_dynamic_list
> >> >> >> >> >> because when -shared is specified but --dynamic-list is not specified,
> >> >> >> >> >> --export-dynamic-symbol should be a no-op.
> >> >> >> >> >
> >> >> >> >> >--dynamic-list implies -Bsymbolic.  If we add --export-dynamic-symbol,
> >> >> >> >> >we should also add --export-dynamic-symbol-list, which is similar to
> >> >> >> >> >--dynamic-list, but without -Bsymbolic.
> >> >> >> >>
> >> >> >> >> --export-dynamic-symbol-list a.list  where a.list is a plain text like:
> >> >> >> >> foo
> >> >> >> >> bar
> >> >> >> >> ?
> >> >> >> >
> >> >> >> >I prefer to use the same format as --dynamic-list.
> >> >> >> >
> >> >> >> >> The feature can be provided by a response file @a.rsp
> >> >> >> >> --export-dynamic-symbol foo
> >> >> >> >> --export-dynamic-symbol bar
> >> >> >>
> >> >> >> Adding --export-dynamic-symbol-list is fine. We can implement that separately.
> >> >> >
> >> >> >Since implement --export-dynamic-symbol-list at the same time may impact how
> >> >> >--export-dynamic-symbol is implemented, they should be added together.
> >> >>
> >> >> OK. Added --export-dynamic-symbol-list as well.
> >> >>
> >> >> Retitled.
> >> >
> >> >A couple comments:
> >>
> >> Thanks for the review!
> >>
> >> >1. Please add an entry to ld/NEWS.
> >> >2. Please a note to ld.texi for the difference between --dynamic-list and
> >> >--export-dynamic-symbol.
> >>
> >> >3.  What happens when there are both --dynamic-list and and
> >> >--export-dynamic-symbol, with and without -Bsymbolic?
> >>
> >> --export-symbol-symbol adds additional entries to --dynamic-list.
> >
> >I don't think so.  See below.
> >
> >>
> >> I'd expect --dynamic-list to override -Bsymbolic (i.e. --dynamic-list is a
> >> refined -Bsymbolic).
> >> gold and
> >> LLD (https://github.com/llvm/llvm-project/blob/master/lld/ELF/Symbols.cpp#L368)
> >> behave this way.
> >> GNU ld seems to make every symbol symbolic.
> >
> >Ld manual says
> >
> >'--dynamic-list=DYNAMIC-LIST-FILE'
> >     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 option is only
> >     meaningful on ELF platforms which support shared libraries.
> >
> >     The format of the dynamic list is the same as the version node
> >     without scope and node name.  See *note VERSION:: for more
> >     information.
> >
> >When producing a shared library,  --dynamic-list implies -Bsymbolic
> >with exception for the symbols on the dynamic list.
>
> This is my understanding. By using `implies`, do you mean -Bsymbolic is
> ignored (gold and LLD's interpretation)? If so, GNU ld should be fixed.

--dynamic-list should be the same as -Bsymbolic --dynamic-list.

> I don't think any project is using the combination, so changing the
> semantics should not be a problem.
>
> >> This can be tested with:
> >>
> >> .globl main, foo, bar
> >> main: call foo
> >> foo: call bar
> >> bar: ret
> >>
> >> // a.list
> >> { foo; };
> >>
> >> It is also fine if you think -Bsymbolic should override --dynamic-list.
> >> (Please add a test for that so that I know how to test --export-dynamic-list)
> >> We can then file a gold bug.
> >>
> >> >4.  Can you reuse lang_append_dynamic_list to implement
> >> >--export-dynamic-symbol?
> >>
> >> This is difficult. It seems that another global variable needs to be introduced.
> >> yacc code duplication may not be that bad compared with the alternative.
> >
> >Since --export-dynamic-symbol is a NOP for -shared and identical with
> >--dynamic-list otherwise, let's only consider the -shared case:
>
> Combined with both points below, --export-dynamic-symbol can be treated
> as a NOP when -shared is specified.  This is acceptable because (as far
> as I can tell from my observation) --export-dynamic is a NOP with
> -shared.
>
> >1. Without -Bsymbolic nor --dynamic-list,  --export-dynamic-symbol should
> >be dropped.
>
> Looks good.
>
> >2. With -Bsymbolic or --dynamic-list, --export-dynamic-symbol should also
> >be dropped since --export-dynamic-symbol doesn't change symbol binding.
>
> Is the intention that --export-dynamic-symbol should be similar more to
> --export-dynamic and less to --dynamic-list? I'm fine with the change.
>
>
> If a.list contains { foo; };
>
>
> # all global symbols are exported. foo is symbolic. --export-dynamic is ignored.
> ld.bfd -shared --dynamic-list=a.list --export-dynamic
>
> # all global symbols are exported. foo is symbolic. --export-dynamic-bar is ignored.
> ld.bfd -shared --dynamic-list=a.list --export-dynamic-symbol=bar
>
> # all global symbols are exported.
> ld.bfd -pie --dynamic-list=a.list --export-dynamic
>
> # foo and bar are exported.
> ld.bfd -pie --dynamic-list=a.list --export-dynamic-symbol=bar
>
> >I think we should add a bit field to bfd_elf_version_expr to indicate if symbol
> >binding should be symbolic (-Bsymbolic) and use lang_append_dynamic_list
> >for both --dynamic-list and --export-dynamic-symbol.  The only
> >difference is that
> >symbols from --export-dynamic-symbol aren't symbolic and can be dropped for
> >-shared.
>
> Like my patch does, we need a separate list for --export-dynamic-symbol.
> We cannot call lang_append_dynamic_list yet when processing options,
> because it is unknown whether -shared will occur.

The dynamic list should be processed after all command line options have
been seen.

-- 
H.J.


More information about the Binutils mailing list