[PATCH] ld: Properly override the IR definition
Alan Modra
amodra@gmail.com
Wed Jul 22 01:01:01 GMT 2020
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.
--
Alan Modra
Australia Development Lab, IBM
More information about the Binutils
mailing list