unofficial mirror of libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Fangrui Song <i@maskray.me>
To: Carlos O'Donell <codonell@redhat.com>
Cc: Florian Weimer <fweimer@redhat.com>,
	Zack Weinberg <zackw@panix.com>,
	GNU C Library <libc-alpha@sourceware.org>
Subject: Re: Are ifuncs intended to be allowed to resolve to symbols in another DSO?
Date: Mon, 3 Feb 2020 23:15:21 -0800	[thread overview]
Message-ID: <20200204071521.cawphkak4yjrax4t@google.com> (raw)
In-Reply-To: <7012c618-01f4-1e4d-51d0-6491a5e61e2f@redhat.com>

On 2020-02-03, Carlos O'Donell wrote:
>On 2/3/20 3:06 PM, Florian Weimer wrote:
>> * Carlos O'Donell:
>>
>>> If an IFUNC resolver calls a function which is not yet resolved then
>>> isn't that a defect in the IFUNC resolver?
>>
>> There is a position that an IFUNC resolver must not use any non-local
>> relocations.  (We must support some relocations for IFUNCs on
>> !PI_STATIC_AND_HIDDEN targets.)  In this case, yes, such a dependencies
>> would be a bug because all external dependencies are bugs.
>
>Just so I understand the position is, to simplify the implementation, that
>IFUNC resolvers must not use any non-local relocations?
>
>What does non-local relocations mean? Are we saying the target of all
>relocations must be within the same linkmap as the resolver? Are we saying
>then that resolvers can only manipulate local data and make local function
>calls?
>
>I don't think that would be useful since you'd want to call many libc functions
>from the resolver itself and so you would have calls in the resolver that
>could call through a GOT entry that has a relocation against an external
>symbol in another DSO e.g. libc.so.6.
>
>If an IFUNC resolver has relocations that against non-local symbols
>then those symbols must have been a dependency of the object and listed
>in DT_NEEDED and therefore relocated before the current IFUNC resolver
>is running.
>
>> On the other hand, in glibc, we could get rid of many IFUNC resolvers
>> which violate this rule only after changing the loader that eliminated
>> their need for them.  Other IFUNCs that do not follow this rule do not
>> have this luxury.
>
>I don't quite parse your first setnence here, could you expand on that please?
>
>When you speak about luxury, you mean to say that IFUNCs in other projects
>would not have the same possibility to solve such a problem like we do in
>glibc?
>
>>> The code which contains such an IFUNC should have had a DT_NEEDED entry
>>> on all objects to which the resolver called into?
>>
>> This does not help with symbol interposition.
>
>What exact problem does symbol interposition cause?
>
>>> I like solutions that ensure that IFUNC resolvers, which are just foreign
>>> functions, run@a stage *after* their own dependencies have been resolved,
>>> but before their own initializers have run.
>>
>> Lazy binding achieves this because it implicitly tracks this dependency
>> information.  For eager binding, we simply do not have this information.
>> Hence my patch for delayed relocation processing.  But it does not solve
>> the problem completely, of course.
>
>The dependencies are explicitly tracked by DT_NEEDED.
>
>Then when we have underlinked libraries we try to suppliment this and reorder
>by relocation dependencies. This may be causing more problems than it solves?
>
>If we had good visibility into the load order manipulations because of the
>relocations I think users would understand the consequences of these problems
>and we would also be able to better identify underlinked applications and file
>bugs to fix them (if possible).

On powerpc64: A is in one module, B and C are in another module. C is a
non-preemptible ifunc. A calls B, B tail calls C.

The GNU ld generated IPLT code sequence starts with `std r2,24(r1)` .
When B tail calls C, it has popped its stack frame. `std r2,24(r1)`
overwrites the TOC pointer from A's module with the TOC pointer from
B,C's module. When C returns to the call site in A, the TOC pointer
incorrectly restores to the value from B,C's module.

The lld generated IPLT code sequence does not use `std r2,24(r1)`.
The above scenario works, but the resolver and the implementation cannot
be in different modules.

So for powerpc64, an IFUNC resolver returning the implementation in
another module may be unreliable.


On powerpc32 Secure PLT: A is in one translation unit, B and C are in
another translation units.  A, B and C are in the same module. C is a
non-preemptible ifunc. B takes the address of C and passes it to A. A
calls the function pointer.

The IPLT code sequence assumes r30 = .got2(B)+0x8000. Calling it from A
(.got2(A)!=.got2(B)) will be wrong.

So for powerpc, even different translation units can be unreliable.

  reply	other threads:[~2020-02-04  7:16 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
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 [this message]
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=20200204071521.cawphkak4yjrax4t@google.com \
    --to=i@maskray.me \
    --cc=codonell@redhat.com \
    --cc=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).