Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Sun, 3 Apr 2016 12:10:44 -0500
From: Bobby Bingham <koorogi@...rogi.info>
To: musl@...ts.openwall.com
Subject: Re: [PATCH 2/2] add powerpc64 port

On Sat, Apr 02, 2016 at 10:09:47PM -0400, Rich Felker wrote:
> > > > > > diff --git a/src/signal/powerpc64/sigsetjmp.s b/src/signal/powerpc64/sigsetjmp.s
> > > > > > new file mode 100644
> > > > > > index 0000000..ce59b60
> > > > > > --- /dev/null
> > > > > > +++ b/src/signal/powerpc64/sigsetjmp.s
> > > > > > @@ -0,0 +1,30 @@
> > > > > > +	.global sigsetjmp
> > > > > > +	.global __sigsetjmp
> > > > > > +	.type sigsetjmp,%function
> > > > > > +	.type __sigsetjmp,%function
> > > > > > +	.hidden ___setjmp
> > > > > > +sigsetjmp:
> > > > > > +__sigsetjmp:
> > > > > > +	addis 2, 12, .TOC.-__sigsetjmp@ha
> > > > > > +	addi  2,  2, .TOC.-__sigsetjmp@l
> > > > > > +	.localentry sigsetjmp,.-sigsetjmp
> > > > > > +	.localentry __sigsetjmp,.-__sigsetjmp
> > > > >
> > > > > Again I don't see what the purpose of these insns is; if the resulting
> > > > > value is needed, are you aware of how that interacts with ___setjmp
> > > > > returning twice?
> > > >
> > > > This sets up r2 with the TOC pointer, as is required by the ABI in order
> > > > to call setjmp's local entry point.  Since setjmp is also written in asm,
> > > > we could do away with this here.
> > > >
> > > > I don't think the fact that setjmp returns twice matters for this.
> > >
> > > When setjmp returns the second time, all registers it did not save
> > > have been clobbered (by arbitrary code that ran after the first return
> > > from setjmp). However despite not being a call-saved register
> > > (AFAICT), r2 is saved by setjmp, so it's probably okay.
> >
> > r2 is call-saved when calling to the local entry point, so setjmp needs
> > to save it.
>
> OK, I see how this works for local calls to setjmp. But how does the
> linker PLT magic work for setjmp?
>
> After the first return, the caller's stack slot where r2 was saved
> belongs to the caller, and the compiler can clobber it. Upon the

The ABI is very prescriptive about the layout of a stack frame.  Each
stack frame has several slots where callees are allowed to use part of
their caller's frame.  For example, the link register is saved to the
caller's frame, not the callee's.

For several of these slots, the ABI explicitly documents that they may
be used as temporary storage which should be considered call-clobbered.
For the slot used for saving the toc pointer (r2), the ABI makes no
mention of it being available for temporary storage.  It would be nice
if it were more explicit here, but I believe the intent is that the
compiler may not use this slot for any other purpose.

> second return, it would load junk into r2. Does longjmp have to do
> something special (its own store to this stack slot, matching what a
> PLT thunk would do) so that the caller loads the correct value?
>
> Rich

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.