Port-alpha archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: static link csh/tcsh dumps core



Disclaimer: I know ~nothing about alpha asm nor the ABI.

It looks like a bug in setjmp/longjmp to me, but it is subtle as it clobbers
the "gp" register, which seems to fall neither in the caller-saved nor the
callee-saved group, but required to be stable for local function calls.

Gcc source says:

/* Define this macro if the register defined by `PIC_OFFSET_TABLE_REGNUM'
   is clobbered by calls.  */
/* ??? It is and it isn't.  It's required to be valid for a given
   function when the function returns.  It isn't clobbered by
   current_file functions.  Moreover, we do not expose the ldgp
   until after reload, so we're probably safe.  */
/* #define PIC_OFFSET_TABLE_REG_CALL_CLOBBERED */


Now in our __setjmp14 implementation we do not store gp in the jump buffer.
Worse, in __longjmp14 we create a sigcontext from the jump buffer and
use partially unintialized stack memory for this, including the storage
area for uc.uc_mcontext.__gregs[_REG_GP].

Then we do a setcontext() and *BOOM* end up back here with an unaligned 
(and probably completely bogus) gp:

Program received signal SIGSEGV, Segmentation fault.
process (catch=<optimized out>) at csh.c:1004
1004            justpr = enterhist;     /* execute if not entering history */
(gdb) bt
#0  process (catch=<optimized out>) at csh.c:1004
#1  0x0000000120001f78 in srcunit (unit=<optimized out>, 
    onlyown=<optimized out>, hflg=<optimized out>) at csh.c:749
#2  0x0000000120002090 in srcfile (f=<optimized out>, onlyown=<optimized out>, 
    flag=<optimized out>) at csh.c:658
#3  0x0000000120003658 in main (argc=<optimized out>, argv=<optimized out>)
    at csh.c:525

Sounds like gcc will reload the gp register after non-local function calls
(whatever that exactly is) and so probably hide the effect in the shared
version.

Does this make sense? If yes, it is easy to fix (but I won't mind someone
with alpha knowledge to beat me to it).

Martin


Home | Main Index | Thread Index | Old Index