[PATCH v3] elf: Don't set its DT_VERSYM entry for unversioned symbol

H.J. Lu hjl.tools@gmail.com
Fri Oct 31 08:20:25 GMT 2025
On Fri, Oct 31, 2025 at 3:48 PM Jan Beulich <jbeulich@suse.com> wrote:
>
> On 31.10.2025 00:21, H.J. Lu wrote:
> > On Thu, Oct 30, 2025 at 10:27 PM Jan Beulich <jbeulich@suse.com> wrote:
> >>
> >> On 29.10.2025 03:09, H.J. Lu wrote:
> >>> On Wed, Oct 29, 2025 at 9:54 AM H.J. Lu <hjl.tools@gmail.com> wrote:
> >>>>
> >>>> Undefined symbol without version shouldn't have the BASE version in its
> >>>> DT_VERSYM entry.  Instead its DT_VERSYM entry should be all zero to
> >>>> indicate that the symbol doesn't have a version.
> >>>>
> >>>> bfd/
> >>>>
> >>>> PR ld/33577
> >>>> * elflink.c (elf_link_output_extsym): Don't set its DT_VERSYM
> >>>> entry for unversioned symbol.
> >>>>
> >>>> ld/
> >>>>
> >>>> PR ld/33577
> >>>> * testsuite/ld-elf/undefined.d: New file.
> >>>> * testsuite/ld-elf/undefined.map: Likewise.
> >>>> * testsuite/ld-elf/undefined.s: Likewise.
> >>>>
> >>>> OK for master?
> >>>
> >>> Here is the v2 patch to only check undefined symbols.
> >>
> >> Just one question: Wouldn't the new testcase be a better fit in ld-elfvers/?
> >> If you agree, okay with it moved there.
> >
> > Here is the v3 patch with updated tests in ld-elfvers.   I also updated
> > elf_link_output_extsym to handle defined symbol without version with
> > a test.
>
> I'm irritated by you now altering an existing test, but there being no
> new test anymore. Can you clarify this for me, please?

My patch changes the linker behavior which results in the output  change
of

# objdump --dynamic-syms tmpdir/vers16

since the "Base" version is no longer added to show_bar and show_foo
which are unversioned symbols.   I have to change ld-elfvers/vers16.dsym.

> > ---
> > 1. Referenced symbol without '@' has no version.
> > 2. Defined symbol without the .symver directive has no version if there
> > is no linker version script.
>
> As we're talking about the linker, how would the linker know whether there
> had been a .symver directive? Possibly related - is strchr() finding an @
> (or not) really a sufficient indication? Symbol names can in principle

The only way to assign the base version to symbol, foo, with GNU assembler
is to use

.symver hide_original_foo, foo@

in assembly codes.

> include @ for other reasons, and I'm not sure how well the versioning
> machinery would cope with such.

Please check how ELF_VER_CHR is used for symbol version in elflink.c.

> Jan
>
> > Symbol without version shouldn't have the base version in its DT_VERSYM
> > entry.  Instead, its DT_VERSYM entry should be all zero to indicate that
> > the symbol doesn't have a version.
> >
> > NB: Symbol with the base version has a '@' suffix, like "foo@", defined
> > with
> >
> > .symver hide_original_foo, foo@
> >
> > bfd/
> >
> > PR ld/33577
> > * elflink.c (elf_link_output_extsym): Don't set its DT_VERSYM
> > entry for the symbol without version.
> >
> > ld/
> >
> > PR ld/33577
> > * ld-elfvers/vers16.dsym: Remove the "Base" version on symbols
> > without version.
>


-- 
H.J.


More information about the Binutils mailing list