[PATCH v2] elf: Treat undefined version as hidden
H.J. Lu
hjl.tools@gmail.com
Mon Aug 2 23:38:48 GMT 2021
On Sun, Aug 1, 2021 at 7:51 PM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> On Sun, Aug 1, 2021 at 7:03 PM Alan Modra <amodra@gmail.com> wrote:
> >
> > On Sun, Aug 01, 2021 at 07:31:04AM -0700, H.J. Lu via Binutils wrote:
> > > Since undefined version can't be used to resolve any references,
> >
> > Testcase please, specifically when the "undefined version" is that
>
> Here is the v2 patch with a testcase.
>
> > for a .dynbss symbol definition. I did a little experiment myself and
> > I don't think you are correct. My testcase might be faulty, so please
> > write one yourself.
> >
> > Mine had
> > a) One shared lib with a definition of a variable foo, a function to
> > print foo seen by that lib, and another function to set a hidden alias
> > of foo. foo was made versioned using a version script.
> > b) A second lib with a reference to a foo, a function to print foo
> > seen by the lib, and another function to set foo. No version script
> > was used.
> > c) A main program with a text reference to foo in order to force a
> > dynbss copy of foo.
> >
> > Output is
> >
> > b foo = 1
> > c foo = 1
> > c setting foo to 2
> > b foo = 2
> > c foo = 2
> > b setting foo alias to 3
> > b foo = 2
> > c foo = 2
> >
> > readelf shows there is just one dynamic foo in the main program, the
> > dynbss copy: GLOBAL DEFAULT 25 foo@VER (2).
> >
> > LD_DEBUG=all | grep foo shows
> > 3541018: symbol=foo; lookup in file=./prxxxxx [0]
> > 3541018: binding file ./prxxxxxc.so [0] to ./prxxxxx [0]: normal symbol `foo'
> > 3541018: symbol=foo; lookup in file=./prxxxxx [0]
> > 3541018: binding file ./prxxxxxb.so [0] to ./prxxxxx [0]: normal symbol `foo' [VER]
> > 3541018: symbol=foo; lookup in file=./prxxxxx [0]
> > 3541018: binding file ./prxxxxx [0] to ./prxxxxx [0]: normal symbol `foo' [VER]
> > 3541018: symbol=foo; lookup in file=./prxxxxxb.so [0]
> > 3541018: binding file ./prxxxxx [0] to ./prxxxxxb.so [0]: normal symbol `foo' [VER]
> >
>
> It is not the same as hidden since it is used to resolve reference to
> unversioned symbol. But it is not the real definition.
The versioned symbol from copy relocation in the executable can change
over time. Today, foo@VER is used to resolve the unversioned reference
in another shared library. When foo@VER becomes hidden in the shared
library tomorrow, the executable runs normally. But foo@VER in the
executable will no longer be used to resolve the unversioned reference.
It is all because foo@VER in the executable is actually undefined. I
prefer readelf's behavior.
--
H.J.
More information about the Binutils
mailing list