[PATCH] ld: Properly override the IR definition
H.J. Lu
hjl.tools@gmail.com
Wed Jul 22 01:50:19 GMT 2020
On Tue, Jul 21, 2020 at 6:01 PM Alan Modra <amodra@gmail.com> wrote:
>
> On Tue, Jul 21, 2020 at 06:37:31AM -0700, H.J. Lu wrote:
> > After all LTO symbols have been read, a new definition in real object
> > overrides the previous definition in the IR object. Before all LTO
> > symbols have been read, a new non-weak definition overrides the weak
> > definition in the IR object.
> >
> > OK for master?
>
> diff --git a/ld/plugin.c b/ld/plugin.c
> index b455af6d67..ff9f00e452 100644
> --- a/ld/plugin.c
> +++ b/ld/plugin.c
> @@ -1433,12 +1433,20 @@ plugin_notice (struct bfd_link_info *info,
> new value from a real BFD. Weak symbols are not normally
> overridden by a new weak definition, and strong symbols
> will normally cause multiple definition errors. Avoid
> - this by making the symbol appear to be undefined. */
> - else if (((h->type == bfd_link_hash_defweak
> - || h->type == bfd_link_hash_defined)
> - && is_ir_dummy_bfd (sym_bfd = h->u.def.section->owner))
> - || (h->type == bfd_link_hash_common
> - && is_ir_dummy_bfd (sym_bfd = h->u.c.p->section->owner)))
> + this by making the symbol appear to be undefined.
> +
> + NB: After all LTO symbols have been read, a new definition in
> + real object overrides the previous definition in the IR object.
> + Before all LTO symbols have been read, a new non-weak definition
> + overrides the weak definition in the IR object. */
> + else if ((((h->type == bfd_link_hash_defweak
> + || h->type == bfd_link_hash_defined)
> + && is_ir_dummy_bfd (sym_bfd = h->u.def.section->owner))
> + || (h->type == bfd_link_hash_common
> + && is_ir_dummy_bfd (sym_bfd = h->u.c.p->section->owner)))
> + && (info->lto_all_symbols_read
> + || ((flags & BSF_WEAK) == 0
> + && h->type == bfd_link_hash_defweak)))
> {
> h->type = bfd_link_hash_undefweak;
> h->u.undef.abfd = sym_bfd;
>
> Can't this just be the following, since non-weak will override weak
> without any changes to h->type here?
>
> else if ((((h->type == bfd_link_hash_defweak
> || h->type == bfd_link_hash_defined)
> && is_ir_dummy_bfd (sym_bfd = h->u.def.section->owner))
> || (h->type == bfd_link_hash_common
> && is_ir_dummy_bfd (sym_bfd = h->u.c.p->section->owner)))
> && info->lto_all_symbols_read)
>
> OK with that simplification, if you have tested your patch with a gcc
> regression test.
I am testing this patch with GCC regression test. I will check it in if there
are no regressions.
Thanks.
--
H.J.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-ld-Properly-override-the-IR-definition.patch
Type: text/x-patch
Size: 8386 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20200721/ad816047/attachment.bin>
More information about the Binutils
mailing list