public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Alan Modra <amodra@gmail.com>
To: Zack Weinberg <zackw@panix.com>
Cc: GNU C Library <libc-alpha@sourceware.org>
Subject: Re: [RFC PATCH] Introduce pt-compat-stubs and use it to replace pt-vfork. (Architecture maintainer feedback wanted.)
Date: Fri, 23 Mar 2018 23:46:00 -0000	[thread overview]
Message-ID: <20180323234608.GT3812@bubble.grove.modra.org> (raw)
In-Reply-To: <CAKCAbMiSJwF1ETWBC-gQ6Cfq5XVZQ7zT7rEZMBDHiMSeVNdJBg@mail.gmail.com>

On Fri, Mar 23, 2018 at 03:32:09PM -0400, Zack Weinberg wrote:
> On Thu, Mar 22, 2018 at 7:47 PM, Alan Modra <amodra@gmail.com> wrote:
> > ELFv1 code would look like:
> >
> >  .section .opd,"aw",@progbits
> >  .global __pstub_vfork
> >  .type __pstub_vfork,@function
> > __pstub_vfork:
> >  .quad 0f,.TOC.,0
> >
> >  .text
> > 0:
> >  addis 11,2,1f-0b@ha
> >  addi 11,11,1f-0b@l
> 
> Is this really correct?  1f-0b here is the offset from the beginning
> of the function to the global it wants to reference in .data, but r2
> is the TOC pointer, not the beginning of the function.

No, it's broken, sorry.  Not enough editing when copying the ELFv2
code..

 addis 11,2,1f@toc@ha
 addi 11,11,1f@toc@l
 ld 11,0(11)

or better, since we do have the required relocs in this case

 addis 11,2,1f@toc@ha
 ld 11,1f@toc@l(11)

Hmm, I also missed a ".p2align 3" when emitting the address to .data,
and didn't write a proper OPD entry.  :-(  You could also put the
function pointer in .toc which would be better for relro and huge
ELFv1 shared libraries (not the case here but nicer example code for
others to copy), or in .data.rel.ro.

Revised ELFv1 code

 .section .opd,"aw",@progbits
 .global __pstub_vfork
 .type __pstub_vfork,@function
__pstub_vfork:
 .quad 0f,.TOC.@tocbase,0

 .text
0:
 addis 11,2,1f@toc@ha
 ld 11,1f@toc@l(11)
 ld 12,0(11)
 mtctr 12
 ld 2,8(11)
 bctr
 .size __pstub_vfork,.-0b

 .section .toc,"aw",@progbits
 .p2align 3
1:
 .quad __libc_vfork

ELFv2 code

 .text
 .global __pstub_vfork
 .type __pstub_vfork,@function
__pstub_vfork:
0:
 addis 12,12,1f-0b@ha
 addi 12,12,1f-0b@l
 ld 12,0(12)
 mtctr 12
 bctr
 .size __pstub_vfork,.-0b

 .section .data.rel.ro,"aw",@progbits
 .p2align 3
1:
 .quad __libc_vfork


In reply to your other email, the third load is the static chain and
can be omitted for C.  I also happen to have been working on inline
plt call support for powerpc ld, which will give you the ability to
write stubs that support lazy linking.

-- 
Alan Modra
Australia Development Lab, IBM

      reply	other threads:[~2018-03-23 23:46 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-21  1:05 Zack Weinberg
2018-03-21  8:53 ` Andreas Schwab
2018-03-21 13:25   ` Zack Weinberg
2018-03-21 13:59     ` Andreas Schwab
2018-03-21 14:01       ` Zack Weinberg
2018-03-21 14:27         ` Andreas Schwab
2018-03-22 23:47 ` Alan Modra
2018-03-23 16:11   ` Zack Weinberg
2018-03-23 19:32   ` Zack Weinberg
2018-03-23 23:46     ` Alan Modra [this message]

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

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

  git send-email \
    --in-reply-to=20180323234608.GT3812@bubble.grove.modra.org \
    --to=amodra@gmail.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).