public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug dynamic-link/27279] New: x86_64 _dl_runtime_resolve should preserve r10/r11
@ 2021-01-29 19:35 foom at fuhm dot net
  2021-02-01  8:45 ` [Bug dynamic-link/27279] " fweimer at redhat dot com
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: foom at fuhm dot net @ 2021-01-29 19:35 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=27279

            Bug ID: 27279
           Summary: x86_64 _dl_runtime_resolve should preserve r10/r11
           Product: glibc
           Version: unspecified
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: dynamic-link
          Assignee: unassigned at sourceware dot org
          Reporter: foom at fuhm dot net
  Target Milestone: ---

This is arguably _not_ actually a bug. Yet, I still think it should probably be
fixed.

The x86-64 abi does not specify which registers should be preserved through a
lazy PLT stub resolution (unlike, say, the AARCH64 psABI which specifies that
all registers but r16, r17 must be preserved). Thus, it's arguably unacceptable
to use _any_ non-standard calling convention when calling through a PLT that
might invoke lazy binding.

However, users do this, and expect it to work, and are upset when it doesn't
work.

Because of that, the current state of x86_64's _dl_runtime_resolve is that it
_does_ preserve nearly every register, even those which are not required by any
specification. This changed most recently in 2017, via bug 21265, after some
debate -- seemingly resulting in grudging agreement that supporting other
calling conventions was a reasonable thing to do after all (grumble grumble).

After that change, _almost_ all registers -- vector, float, and GPR -- are now
preserved either explicitly in the assembly code, or implicitly via being
callee-save in the C function it calls.

But unfortunately, there are two GPRs which still get clobbered: r10 and r11.
And, there's a calling convention which expects all GPRs except r11 to be
preserved: <https://clang.llvm.org/docs/AttributeReference.html#preserve-most>.
This has caused a bug in a piece of software, where the developer didn't
realize that the "preserve_most" calling convention was incompatible with calls
that might go through a PLT stub.

So -- since lazy PLT resolution is already _so close_ to saving literally
everything, and the cost of additionally saving r10/r11 is so low compared to
everything else it's doing, I'd propose that _dl_runtime_resolve should be
modified to save those final 2 still-clobbered GPRs.

And thus, finally, be transparent to ANY calling convention anyone might want
to use.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug dynamic-link/27279] x86_64 _dl_runtime_resolve should preserve r10/r11
  2021-01-29 19:35 [Bug dynamic-link/27279] New: x86_64 _dl_runtime_resolve should preserve r10/r11 foom at fuhm dot net
@ 2021-02-01  8:45 ` fweimer at redhat dot com
  2021-02-01 22:46 ` martijn.vels at gmail dot com
  2021-03-02  5:06 ` foom at fuhm dot net
  2 siblings, 0 replies; 4+ messages in thread
From: fweimer at redhat dot com @ 2021-02-01  8:45 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=27279

Florian Weimer <fweimer at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2021-02-01
              Flags|                            |security-
     Ever confirmed|0                           |1
                 CC|                            |fweimer at redhat dot com
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from Florian Weimer <fweimer at redhat dot com> ---
For CET support, it is rather convenient to keep the r11 clobber. Avoiding the
r10 clobber should however be easy. r11 is also clobbered by the large code
model calling convention, so I hope it's not much of a problem.

Note that some calling conventions remain unsupported. We still assume that
%rsp points to a stack to which we can save lots of data, for example.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug dynamic-link/27279] x86_64 _dl_runtime_resolve should preserve r10/r11
  2021-01-29 19:35 [Bug dynamic-link/27279] New: x86_64 _dl_runtime_resolve should preserve r10/r11 foom at fuhm dot net
  2021-02-01  8:45 ` [Bug dynamic-link/27279] " fweimer at redhat dot com
@ 2021-02-01 22:46 ` martijn.vels at gmail dot com
  2021-03-02  5:06 ` foom at fuhm dot net
  2 siblings, 0 replies; 4+ messages in thread
From: martijn.vels at gmail dot com @ 2021-02-01 22:46 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=27279

Martijn Vels <martijn.vels at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |martijn.vels at gmail dot com

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug dynamic-link/27279] x86_64 _dl_runtime_resolve should preserve r10/r11
  2021-01-29 19:35 [Bug dynamic-link/27279] New: x86_64 _dl_runtime_resolve should preserve r10/r11 foom at fuhm dot net
  2021-02-01  8:45 ` [Bug dynamic-link/27279] " fweimer at redhat dot com
  2021-02-01 22:46 ` martijn.vels at gmail dot com
@ 2021-03-02  5:06 ` foom at fuhm dot net
  2 siblings, 0 replies; 4+ messages in thread
From: foom at fuhm dot net @ 2021-03-02  5:06 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=27279

--- Comment #2 from James Y Knight <foom at fuhm dot net> ---
As clang's "preserve_most" CC does allow r11 to be clobbered, to fix the actual
issue I observed only r10 needs to be saved. 

I had initially added r11 to the request only in an attempt to stave off any
*future* request that might arise to preserve it. But, I expect that the use of
r11 in the large code model sequences is exactly why it remains clobbered in
preserve_most, and consequently why it's fairly unlikely that there would be a
future request to preserve it.

So, I agree that saving r10, but leaving r11 clobbered would be reasonable.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-03-02  5:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-29 19:35 [Bug dynamic-link/27279] New: x86_64 _dl_runtime_resolve should preserve r10/r11 foom at fuhm dot net
2021-02-01  8:45 ` [Bug dynamic-link/27279] " fweimer at redhat dot com
2021-02-01 22:46 ` martijn.vels at gmail dot com
2021-03-02  5:06 ` foom at fuhm dot net

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).