Topic: varargs & sparc


Author: dj@ctron.com (DJ Delorie)
Date: 26 Sep 91 15:21:13 GMT
Raw View
I have been unsuccessful in getting varargs to work properly with
cfront 2.1.  The Sparc seems to pass parameters in registers, so they
are not in memory to take a pointer to them.

What do I have to do to get it to work?  Can someone send me a program
that *does* work in this system?

DJ
dj@ctron.com

setup:

 cfront 2.1
 Sparc 1+
 SunOS 4.1

program:

 #include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>

 void Fatal(char *fmt, ...)
 {
   va_list v;
   va_start(v, fmt);
   fprintf(stderr, "Fatal: ");
   vfprintf(stderr, fmt, v);
   fprintf(stderr, "!\n");
   va_end(v);
   exit(1);
 }

 main(int argc, char **argv)
 {
   Fatal("%s: %d errors", argv[0], 5);
 }

execution:

 % dbx varargs
 Reading symbolic information...
 Read 112 symbols

 (dbx) r
 Running: varargs
 Fatal: signal SEGV (no mapping at the fault address) in _doprnt at 0xf7735104
 _doprnt+0x22c:  ldsb    [%i0], %i4

 (dbx) p (void *)$i0
 (void *) $i0 = 0x8000

 (dbx) dump
 __1v = 0xf7fff988 ""
 __0fmt = 0x40bb "%s: %d errors"

 (dbx) p &__0fmt
 &__0fmt = 0xf7fff984

 (dbx) 0xf7fff984/8X
 0xf7fff984:  0x000040bb 0x00008000 0x00002000 0x00000000
 0xf7fff994:  0x00000000 0x00000020 0x00000000 0x00000000

 (dbx)




Author: gas@nyquist.cs.nott.ac.uk (Alan Shepherd)
Date: 30 Sep 91 07:15:16 GMT
Raw View
In article <2272@balrog.ctron.com>, dj@ctron.com (DJ Delorie) writes:
|> I have been unsuccessful in getting varargs to work properly with
|> cfront 2.1.  The Sparc seems to pass parameters in registers, so they
|> are not in memory to take a pointer to them.
|>
|> What do I have to do to get it to work?  Can someone send me a program
|> that *does* work in this system?
|>
I can't be sure whether this is the answer to your problem or not, but
we got C++ 2.1 about a year ago and had the same symptoms.  My query
produced the following response from someone at AT&T:

There's a bug in "src/print2.c" around line 1490--



------------------------------
                if (body && Cast==0) {
                        for (nn=at; nn;) {
                                nn->print();
                                if (nn=nn->n_list) puttok(CM); else break;
                        }
#ifdef mips
                        if (nargs_known == ELLIPSIS)
                                putstring(", va_alist");
#endif
                        putch(')');
                }
                else
                        putch(')');
------------------------------

should be--

------------------------------
                if (body && Cast==0) {
                        for (nn=at; nn;) {
                                nn->print();
                                if (nn=nn->n_list) puttok(CM); else break;
                        }
#ifdef mips
                        if (nargs_known == ELLIPSIS)
                                putstring(", va_alist");
#endif
#ifdef sparc
                        if (nargs_known == ELLIPSIS)
                                putstring(", __builtin_va_alist");
#endif
                        putch(')');
                }
                else
                        putch(')');

Hope this helps.  If it is the problem, then I'm surprised AT&T
haven't corrected it yet in their release tapes.....


Alan Shepherd