This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: PATCH: Add STB_SECONDARY support
On Tue, Jul 3, 2012 at 4:45 PM, Alan Modra <amodra@gmail.com> wrote:
> On Tue, Jul 03, 2012 at 09:26:11AM -0700, H.J. Lu wrote:
>> This scheme works for simple link-time backup.
>
> Right. I thought that's what you wanted, because run-time backup can
> be done easily right now.
>
>> It doesn't
>> work with backup symbol defined in DSO. You can't override
>> it at run-time.
>
> If you want run-time backup, use a shared library for your backup.
> The ELF spec has well defined search order rules for resolving
> multiple global symbols in shared libraries. I'm sure you know the
> rules, and could devise a way of linking a backup library.
>
> Needing to provide a backup implementation of some function isn't a
> new thing. How have we managed without secondary symbols in over 20
> years since ELF was invented?
>
Take binutils as an example, when you use --enable-shared, you
get
[hjl@gnu-6 local]$ readelf -d ./bin/ld
Dynamic section at offset 0xca530 contains 28 entries:
Tag Type Name/Value
0x0000000000000001 (NEEDED) Shared library:
[libbfd-2.22.52.20120703.so]
0x0000000000000001 (NEEDED) Shared library: [libz.so.1]
0x0000000000000001 (NEEDED) Shared library: [libdl.so.2]
0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
libbfd-2.22.52.20120703.so is linked against libiberty.a. When you build
binutils, libbfd will include a backup copy of standard functions
which don't exist
in libc.so at the time when you compile it. Even after you upgrade your
libc.so with the latest and greatest standard functions, ld stiil uses
the backup one from libiberty since ld.so searches libbfd.so before
libc.so.6. STB_SECONDARY solves this problem by making the
backup copy "dynamic weak". The the latest and greatest standard
functions in libc.so will be used instead of the backup copy in libbfd.so.
--
H.J.