[parisc-linux] Re: [glibc] tststatic failues, reduced to simple testcase.

Carlos O'Donell carlos@baldric.uwo.ca
Sat, 30 Aug 2003 11:35:17 -0400


Dave,

> An asm will not cause the restoration of %r19.  The compiler treats
> r19 as a fixed register when generating pic code.  The saving and
> restoring of the pic register across calls is something that the pa
> port does itself in the backend.  Clobbering r19 won't cause it
> to be restored.

I thought that listing it in the clobber would be the solution.

> In the case of syscalls, the compiler has no way of telling that
> you are making a "call".

Yes, glibc has begun using inlined macros rather than incuring the
penalty of a function call to get at the syscall. I _could_ cheat and
make the inlined code call a 'C' function which would force a restore,
but we then have _many_ more insn on the fast path (rather than just a
stw and ldw).
 
> > 0x40008838:     copy r4,r19  <---Restore----- r19 = 0x40020718
> 
> This is a restore after a call.

Correct. This is a delayed restore from a previous call.
 
> > __asm(
> > 0x4000883c:     be,l 100(sr2,r0),%sr0,%r31
> > 0x40008840:     ldi 2,r20                    !! FORK !!
> > );
> > 0x40008844:     ldi -1000,r20 <--Corrupted--- r19 = 0x10106368
> 
> There is no save and restore around the syscall as GCC doesn't know
> the asm does a call.  Clobbering r19 isn't an option in PIC code.
> Thus, either the syscall has to save and restore r19, or the kernel
> has to avoid clobbering r19.

I would vote for having the kernel avoid trashing r19, though that means
that the kernel has to do the stw/ldw, and wouldn't it be more
beneficial to do this in userspace and allow the kernel an extra
register to generate code with?
 
> You should be able to use a register.  The problem is how to do this
> in a nice way so that you don't have to save and restore r19 in non-pic
> code.

Glibc tells me if I'm in PIC code by setting -DPIC on the command line.
I'm planning on using "ifdef PIC" to optimize away the save and restore.
The issue really is that most programs are dynamically linked against
libc, and thus all their syscalls have to save and restore r19.
 
> Ouch, I am surprised that this hasn't had a bigger effect.

Me too. I really see this as a "We should have been doing this anyway"
and we aren't going to get away from this.

c.