Bug 25910 - Support --export-dynamic-symbol $symbol
Summary: Support --export-dynamic-symbol $symbol
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.35
: P2 normal
Target Milestone: 2.35
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-05-03 05:58 UTC by Fangrui Song
Modified: 2020-06-03 13:40 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed: 2020-05-23 00:00:00


Attachments
A patch (5.44 KB, patch)
2020-05-23 14:56 UTC, H.J. Lu
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Fangrui Song 2020-05-03 05:58:07 UTC
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).
Comment 1 Fangrui Song 2020-05-03 06:17:11 UTC
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.
Comment 2 H.J. Lu 2020-05-03 12:25:59 UTC
(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.
Comment 3 H.J. Lu 2020-05-22 13:13:25 UTC
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.
Comment 4 H.J. Lu 2020-05-23 14:56:17 UTC
Created attachment 12565 [details]
A patch
Comment 5 Sourceware Commits 2020-06-03 13:38:13 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=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.
Comment 6 H.J. Lu 2020-06-03 13:40:38 UTC
Fixed for 2.35.