This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFC PATCH] Introduce pt-compat-stubs and use it to replace pt-vfork. (Architecture maintainer feedback wanted.)


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]