[1/3] Use version index 1 for defined symbols

H.J. Lu hjl.tools@gmail.com
Fri Nov 21 23:37:04 GMT 2025


On Fri, Nov 21, 2025 at 7:29 PM Alan Modra <amodra@gmail.com> wrote:
>
> On Thu, Nov 20, 2025 at 04:30:17PM +0100, Michael Matz wrote:
> > It's reasonable to use version index 0 for undefined
> > symbols, so let's continue doing that.  For defined (global)
> > symbols that aren't otherwise versioned continue using
> > VER_NDX_GLOBAL (partly reverting behaviour introduced in
> > commit f685e395).
>
> When I approved HJ's patch earlier, I wondered about two things, one
> was whether I should ask him to write the patch without "noversion".
> ie. write "iversym.vs_vers = 0" instead of "noversion = true".  You
> can get exactly the same output without using the extra variable.
>
> The other thing was whether v3 was required.  (What you're doing here
> is effectively going back to v2.)  I decided to trust HJ knew what he
> was doing (he usually does), and that if there was fallout he'd fix
> it.  So while I'm happy to OK this patch and your second in the
> series, rather than reverting the entire patch, I'd like to hear what
> HJ has to say.

ld.so and ld never use version index 0 to decide symbol binding.
Due to the historical mistake, some linkers treat symbol version
index 0 with local binding.  If some applications depend on this
behavior on Linux, they have a latent run-time bug, which can
be a security issue since such symbols aren't local and can be
overridden at run-time.  In my opinion, at least, we should add
a command line option to control the linker behavior and the
default action can be selected at the configure time.

> > bfd/
> >       PR ld/33577
> >       * elflink.c (elf_link_output_extsym): Don't set noversion
> >       for defined syms.
> >
> > ld/
> >       PR ld/33577
> >       * ld-elfvers/vers16.dsym: Add back the "Base" version for
> >       defined syms.
> > ---
> > I got approval for this on in bugzilla, but as there are relations to a
> > readelf change I'll make this part of the whole series.
> >
> > ---
> >  bfd/elflink.c                       | 8 +-------
> >  ld/testsuite/ld-elfvers/vers16.dsym | 2 +-
> >  2 files changed, 2 insertions(+), 8 deletions(-)
> >
> > diff --git a/bfd/elflink.c b/bfd/elflink.c
> > index ec3ad9735fe..7d284c08c00 100644
> > --- a/bfd/elflink.c
> > +++ b/bfd/elflink.c
> > @@ -11158,13 +11158,7 @@ elf_link_output_extsym (struct bfd_hash_entry *bh, void *data)
> >         else
> >           {
> >             if (h->verinfo.vertree == NULL)
> > -             {
> > -               iversym.vs_vers = 1;
> > -               if (elf_tdata (flinfo->output_bfd)->cverdefs == 0)
> > -                 /* Defined symbol has no version if there is no
> > -                    linker version script.  */
> > -                 noversion = true;
> > -             }
> > +             iversym.vs_vers = 1;
> >             else
> >               iversym.vs_vers = h->verinfo.vertree->vernum + 1;
> >             if (flinfo->info->create_default_symver)
> > diff --git a/ld/testsuite/ld-elfvers/vers16.dsym b/ld/testsuite/ld-elfvers/vers16.dsym
> > index 076d0eb07ed..a32abd7aad9 100644
> > --- a/ld/testsuite/ld-elfvers/vers16.dsym
> > +++ b/ld/testsuite/ld-elfvers/vers16.dsym
> > @@ -1,2 +1,2 @@
> > -[0-9a-f]+ g +DF (\.text|\.opd|\*ABS\*)       [0-9a-f]+ +(0x[0-9a-f]+ )?_?show_bar
> > +[0-9a-f]+ g +DF (\.text|\.opd|\*ABS\*)       [0-9a-f]+( +Base +)? +(0x[0-9a-f]+ )?_?show_bar
> >  [0-9a-f]+ +DF \*UND\*        [0-9a-f]+ +(0x[0-9a-f]+ )?_?show_foo
> > --
> > 2.48.1
>
> --
> Alan Modra



-- 
H.J.


More information about the Binutils mailing list