unofficial mirror of libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Florian Weimer <fweimer@redhat.com>
To: Zack Weinberg <zackw@panix.com>
Cc: GNU C Library <libc-alpha@sourceware.org>
Subject: Re: Are ifuncs intended to be allowed to resolve to symbols in another DSO?
Date: Thu, 09 Jan 2020 21:37:30 +0100	[thread overview]
Message-ID: <87sgko4b91.fsf@oldenburg2.str.redhat.com> (raw)
In-Reply-To: <CAKCAbMjHxyv8ymquQWatGb+7OCkUu8VtrFpiQSk3owus5g8oWw@mail.gmail.com> (Zack Weinberg's message of "Thu, 9 Jan 2020 13:29:08 -0500")

* Zack Weinberg:

> Suppose I have two major versions of the same shared library
> (libfoo.so.1 and libfoo.so.2) and the only difference is that
> libfoo.so.2 drops a whole bunch of compatibility aliases.  For
> instance, libfoo.so.1 defines two names, `blurf` and `xblurf`, for the
> same function, but libfoo.so.2 defines only the `blurf` name.
>
> Any program that winds up loading both shared libraries (via
> transitive dependencies) is going to have two copies of the actual
> code for `blurf` in memory.  I could eliminate this duplication by
> having libfoo.so.1 be a thin wrapper around libfoo.so.2, providing
> only a definition for `xblurf` that calls `blurf`.  Good so far, but
> now old applications are making two jumps through the PLT whenever
> they call `xblurf`.  It occurred to me to wonder whether I could
> eliminate the extra indirection (on the second and subsequent calls)
> by making xblurf an ifunc:
>
> extern int blurf(char *arg1, int arg2); // defined in libfoo.so.2
> static int (*resolve_xblurf(void))(char *, int)
> {
>   return blurf;
> }
> int xblurf(char *, int) __attribute__((ifunc("resolve_xblurf")));

This only works if libfoo.so.1 has already been relocated when the IFUNC
resolver is called.  Old glibcs always relocated objects in the wrong
order (bug 12892, fixed in glibc 2.15, probably not widely backported).

Even with that fixed, missing DT_NEEDED entries and LD_PRELOAD can
result in calls to yet-unrelocated IFUNC resolvers.  I had a patch to
mostly fix this, but it added quite a bit of complexity (delayed
relocation processing), and there are still difficult-to-describe
failure cases for complex dependency trees.  The community wasn't
enthusiastic about it.

Lazy binding obscures some of these problems, to the degree that some
programmers call getenv in IFUNC resolvers.

Thanks,
Florian


  reply	other threads:[~2020-01-09 20:37 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-09 18:29 Are ifuncs intended to be allowed to resolve to symbols in another DSO? Zack Weinberg
2020-01-09 20:37 ` Florian Weimer [this message]
2020-02-01  6:27   ` Carlos O'Donell
2020-02-03 20:06     ` Florian Weimer
2020-02-03 22:03       ` Carlos O'Donell
2020-02-04  7:15         ` Fangrui Song
2020-02-21 13:28         ` Florian Weimer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/libc/involved.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87sgko4b91.fsf@oldenburg2.str.redhat.com \
    --to=fweimer@redhat.com \
    --cc=libc-alpha@sourceware.org \
    --cc=zackw@panix.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).