[PATCH] elf: Drop GRP_COMDAT when localizing a global symbol

H.J. Lu hjl.tools@gmail.com
Tue Dec 7 12:46:29 GMT 2021


On Tue, Dec 7, 2021 at 12:00 AM Alan Modra <amodra@gmail.com> wrote:
>
> On Mon, Dec 06, 2021 at 08:54:42AM -0800, H.J. Lu via Binutils wrote:
> > --- a/binutils/objcopy.c
> > +++ b/binutils/objcopy.c
> > @@ -1696,6 +1696,21 @@ filter_symbols (bfd *abfd, bfd *obfd, asymbol **osyms,
> >                     && ! is_specified_symbol (name, keepglobal_specific_htab))
> >                 || (localize_hidden && is_hidden_symbol (sym))))
> >           {
> > +           if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
> > +             {
> > +               sec_ptr s = sym->section;
> > +               if (s != NULL
> > +                   && elf_section_data (s) != NULL
> > +                   && elf_group_name (s) != NULL)
> > +                 {
> > +                   /* When a global symbol in a COMDAT group was
> > +                      changed to local, drop GRP_COMDAT on the
> > +                      group.  */
> > +                   s = elf_sec_group (s);
> > +                   if (s != NULL && s->output_section != NULL)
> > +                     s->output_section->flags &= ~SEC_LINK_ONCE;
> > +                 }
> > +             }
> >             sym->flags &= ~ (BSF_GLOBAL | BSF_WEAK);
> >             sym->flags |= BSF_LOCAL;
> >           }
>
> I don't think this is quite correct.  Surely you only want to change
> the group semantics if the group symbol changes?  This patch would
> change group semantics if *any* symbol defined in the group is
> localised.

This is done on purpose.  When any global symbol in a comdat group
is localized, this comdat group is no longer interchangeable with other
comdat groups of the same group signature.


-- 
H.J.


More information about the Binutils mailing list