veit@HORNET.MDC.COM ("Stephen Veit") (12/21/88)
I have g++ 1.27 and have been attempting to get it to work on a Silicon Graphics 3030. I compiled g++ with gcc 1.31. Everything compiles fine. However, when I try to make test0 in libg++-1.25.0, I get the following error: g++ -c -g -O -fchar-charconst test.hello.cc -o test.hello.o In function struct ifile &ifile::operator >> (char *): test0.h:36: Segmentation violation g++: Program c++ got fatal signal 11. *** Error code 1 Stop. Do you have any clues? Is there any more information you need? Thanks Stephen Veit veit@hornet.mdc.com Below is the output of the Preprocessor (I executed g++ -E -g -O -fchar-charconst test.hello.cc -o test.hello.o): # 1 "test.hello.cc" # 1 "test0.h" # 1 "/usr/local/lib/g++-include/std.h" overload abs; extern void _exit (int) asm ("_" "_exit") ; extern void abort () asm ("_" "abort") ; extern int abs (int) asm ("_" "abs") ; extern int access (const char*, int) asm ("_" "access") ; extern int acct (const char*) asm ("_" "acct") ; extern unsigned alarm (unsigned) asm ("_" "alarm") ; extern void* alloca (int) asm ("_" "alloca") ; extern double atof (const char*) asm ("_" "atof") ; extern int atoi (const char*) asm ("_" "atoi") ; extern long atol (const char*) asm ("_" "atol") ; extern int bcmp (const void*, const void*, int) asm ("_" "bcmp") ; extern int bcopy (const void*, void*, int) asm ("_" "bcopy") ; extern void* brk (void*) asm ("_" "brk") ; extern int bzero (void*, int) asm ("_" "bzero") ; extern void* calloc (unsigned, unsigned) asm ("_" "calloc") ; extern void cfree (void*) asm ("_" "cfree") ; extern int chdir (const char*) asm ("_" "chdir") ; extern int chmod (const char*, int) asm ("_" "chmod") ; extern int chown (const char*, int, int) asm ("_" "chown") ; extern long clock () asm ("_" "clock") ; extern int close (int) asm ("_" "close") ; extern int creat (const char*, int) asm ("_" "creat") ; extern char* crypt (const char*, const char*) asm ("_" "crypt") ; extern char* ctermid (char*) asm ("_" "ctermid") ; extern char* cuserid (char*) asm ("_" "cuserid") ; extern double drand48 () asm ("_" "drand48") ; extern int dup (int) asm ("_" "dup") ; extern int dup2 (int, int) asm ("_" "dup2") ; extern int dysize (int) asm ("_" "dysize") ; extern char* ecvt (double, int, int*, int*) asm ("_" "ecvt") ; extern char* encrypt (char*, int) asm ("_" "encrypt") ; extern double erand (short*) asm ("_" "erand") ; extern int execl (const char*, const char *, ...) asm ("_" "execl") ; extern int execle (const char*, const char *, ...) asm ("_" "execle") ; extern int execlp (const char*, const char*, ...) asm ("_" "execlp") ; extern int exect (const char*, const char**, char**) asm ("_" "exect") ; extern int execv (const char*, const char**) asm ("_" "execv") ; extern int execve (const char*, const char**, char**) asm ("_" "execve") ; extern int execvp (const char*, const char**) asm ("_" "execvp") ; extern void exit (int) asm ("_" "exit") ; extern int fchmod (int, int) asm ("_" "fchmod") ; extern int fchown (int, int, int) asm ("_" "fchown") ; extern int fcntl (int, int, int) asm ("_" "fcntl") ; extern char* fcvt (double, int, int*, int*) asm ("_" "fcvt") ; extern int ffs (int) asm ("_" "ffs") ; extern int flock (int, int) asm ("_" "flock") ; extern int fork () asm ("_" "fork") ; extern void free (void*) asm ("_" "free") ; extern int fsync (int) asm ("_" "fsync") ; extern long ftok (const char*, int) asm ("_" "ftok") ; extern int ftruncate (int, unsigned long) asm ("_" "ftruncate") ; extern char* gcvt (double, int, char*) asm ("_" "gcvt") ; extern char* getcwd (char*, int) asm ("_" "getcwd") ; extern int getdomainname (char*, int) asm ("_" "getdomainname") ; extern int getdtablesize () asm ("_" "getdtablesize") ; extern int getegid () asm ("_" "getegid") ; extern char* getenv (const char*) asm ("_" "getenv") ; extern int geteuid () asm ("_" "geteuid") ; extern int getgid () asm ("_" "getgid") ; extern int getgroups (int, int*) asm ("_" "getgroups") ; extern long gethostid () asm ("_" "gethostid") ; extern int gethostname (char*, int) asm ("_" "gethostname") ; extern char* getlogin () asm ("_" "getlogin") ; extern int getopt (int, char**, char*) asm ("_" "getopt") ; extern int getpagesize () asm ("_" "getpagesize") ; extern char* getpass (const char*) asm ("_" "getpass") ; extern int getpgrp () asm ("_" "getpgrp") ; extern int getpid () asm ("_" "getpid") ; extern int getppid () asm ("_" "getppid") ; extern int getpriority (int, int) asm ("_" "getpriority") ; extern int getpw (int, char*) asm ("_" "getpw") ; extern unsigned getuid () asm ("_" "getuid") ; extern char* getwd (const char*) asm ("_" "getwd") ; extern char* index (const char*, int) asm ("_" "index") ; extern char* initstate (unsigned, char*, int) asm ("_" "initstate") ; extern int ioctl (int, int, char*) asm ("_" "ioctl") ; extern int isatty (int) asm ("_" "isatty") ; extern long jrand48 (short*) asm ("_" "jrand48") ; extern int kill (int, int) asm ("_" "kill") ; extern int killpg (int, int) asm ("_" "killpg") ; extern void lcong48 (short*) asm ("_" "lcong48") ; extern int link (const char*, const char*) asm ("_" "link") ; extern int lock (int, int, long) asm ("_" "lock") ; extern long lrand48 () asm ("_" "lrand48") ; extern long lseek (int, long, int) asm ("_" "lseek") ; extern void* malloc (unsigned) asm ("_" "malloc") ; extern void* memalign (unsigned, unsigned) asm ("_" "memalign") ; extern void* memccpy (void*, const void*, int, int) asm ("_" "memccpy") ; extern void* memchr (const void*, int, int) asm ("_" "memchr") ; extern int memcmp (const void*, const void*, int) asm ("_" "memcmp") ; extern void* memcpy (void*, const void*, int) asm ("_" "memcpy") ; extern void* memset (void*, int, int) asm ("_" "memset") ; extern int mkdir (const char*, int) asm ("_" "mkdir") ; extern int mknod (const char*, int, int) asm ("_" "mknod") ; extern char* mkstemp (char*) asm ("_" "mkstemp") ; extern char* mktemp (char*) asm ("_" "mktemp") ; extern long mrand48 () asm ("_" "mrand48") ; extern int nice (int) asm ("_" "nice") ; extern long nrand48 (short*) asm ("_" "nrand48") ; extern int open (const char*, int, ...) asm ("_" "open") ; extern void pause () asm ("_" "pause") ; extern void perror (const char*) asm ("_" "perror") ; extern int pipe (int*) asm ("_" "pipe") ; extern void profil (char*, int, int, int) asm ("_" "profil") ; extern int psignal (unsigned, char*) asm ("_" "psignal") ; extern int ptrace (int, int, int, int) asm ("_" "ptrace") ; extern int putenv (const char*) asm ("_" "putenv") ; extern int rand () asm ("_" "rand") ; extern long random () asm ("_" "random") ; extern int read (int, void*, unsigned) asm ("_" "read") ; extern int readlink (const char*, char*, int) asm ("_" "readlink") ; extern void* realloc (void*, unsigned) asm ("_" "realloc") ; extern int rename (const char*, const char*) asm ("_" "rename") ; extern char* rindex (const char*, int) asm ("_" "rindex") ; extern int rmdir (const char*) asm ("_" "rmdir") ; extern void* sbrk (int) asm ("_" "sbrk") ; extern short* seed48 (short*) asm ("_" "seed48") ; extern int send (int, char*, int, int) asm ("_" "send") ; extern int setgid (int) asm ("_" "setgid") ; extern int sethostname (char*, int) asm ("_" "sethostname") ; extern int setkey (const char*) asm ("_" "setkey") ; extern int setpgrp (int, int) asm ("_" "setpgrp") ; extern int setpriority (int, int, int) asm ("_" "setpriority") ; extern int setregid (int, int) asm ("_" "setregid") ; extern int setreuid (int, int) asm ("_" "setreuid") ; extern char* setstate (char*) asm ("_" "setstate") ; extern int setuid (int) asm ("_" "setuid") ; extern int sigblock (int) asm ("_" "sigblock") ; extern int siginterrupt (int, int) asm ("_" "siginterrupt") ; extern int sigpause (int) asm ("_" "sigpause") ; extern int sigsetmask (int) asm ("_" "sigsetmask") ; extern unsigned sleep (unsigned) asm ("_" "sleep") ; extern int srand (int) asm ("_" "srand") ; extern void srand48 (long) asm ("_" "srand48") ; extern void srandom (int) asm ("_" "srandom") ; extern int stime (long*) asm ("_" "stime") ; extern char* strcat (char*, const char*) asm ("_" "strcat") ; extern char* strchr (const char*, int) asm ("_" "strchr") ; extern int strcmp (const char*, const char*) asm ("_" "strcmp") ; extern char* strcpy (char*, const char*) asm ("_" "strcpy") ; extern int strcspn (const char*, const char*) asm ("_" "strcspn") ; extern char* strdup (const char*) asm ("_" "strdup") ; extern int strlen (const char*) asm ("_" "strlen") ; extern char* strncat (char*, const char*, int) asm ("_" "strncat") ; extern int strncmp (const char*, const char*, int) asm ("_" "strncmp") ; extern char* strncpy (char*, const char*, int) asm ("_" "strncpy") ; extern char* strpbrk (const char*, const char*) asm ("_" "strpbrk") ; extern char* strrchr (const char*, int) asm ("_" "strrchr") ; extern int strspn (const char*, const char*) asm ("_" "strspn") ; extern double strtod (const char*, char**) asm ("_" "strtod") ; extern char* strtok (char*, const char*) asm ("_" "strtok") ; extern long strtol (const char*, char**, int) asm ("_" "strtol") ; extern void swab (void*, void*, int) asm ("_" "swab") ; extern int symlink (const char*, const char*) asm ("_" "symlink") ; extern int syscall (int, ...) asm ("_" "syscall") ; extern int system (const char*) asm ("_" "system") ; extern char* tempnam (char*, char*) asm ("_" "tempnam") ; extern long time (long*) asm ("_" "time") ; extern char* tmpnam (char*) asm ("_" "tmpnam") ; extern int truncate (const char*, unsigned long) asm ("_" "truncate") ; extern char* ttyname (int) asm ("_" "ttyname") ; extern int ttyslot () asm ("_" "ttyslot") ; extern unsigned ualarm (unsigned, unsigned) asm ("_" "ualarm") ; extern long ulimit (int, long) asm ("_" "ulimit") ; extern int umask (int) asm ("_" "umask") ; extern int unlink (const char*) asm ("_" "unlink") ; extern unsigned usleep (unsigned) asm ("_" "usleep") ; extern int vadvise (int) asm ("_" "vadvise") ; extern void* valloc (unsigned) asm ("_" "valloc") ; extern int vfork () asm ("_" "vfork") ; extern int vhangup () asm ("_" "vhangup") ; extern int wait (int*) asm ("_" "wait") ; extern int write (int, const void*, unsigned) asm ("_" "write") ; extern char** environ; extern int errno; extern char* sys_errlist[]; extern int sys_nerr; extern char* optarg; extern int opterr; extern int optind; # 1 "test0.h" # 1 "/usr/local/lib/g++-include/stdio.h" extern struct _iobuf { int _cnt; char* _ptr; char* _base; char _flag; char _file; } _iob[]; extern int _doprnt(const char*, void*, struct _iobuf *); extern int _doscan( struct _iobuf *, const char*, void*); extern int _filbuf( struct _iobuf *); extern int _flsbuf(unsigned, struct _iobuf *); extern int fclose( struct _iobuf *); extern struct _iobuf * fdopen(int, const char*); extern int fflush( struct _iobuf *); extern int fgetc( struct _iobuf *); extern char* fgets(char*, int, struct _iobuf *); extern struct _iobuf * fopen(const char*, const char*); extern int fprintf( struct _iobuf *, const char* ...); extern int fputc(int, struct _iobuf *); extern int fputs(const char*, struct _iobuf *); extern int fread(void*, int, int, struct _iobuf *); extern struct _iobuf * freopen(const char*, const char*, struct _iobuf *); extern int fscanf( struct _iobuf *, const char* ...); extern int fseek( struct _iobuf *, long, int); extern long ftell( struct _iobuf *); extern int fwrite(const void*, int, int, struct _iobuf *); extern char* gets(char*); extern int getw( struct _iobuf *); extern int pclose( struct _iobuf *); extern struct _iobuf * popen(const char*, const char*); extern int printf(const char* ...); extern void puts(const char*); extern int putw(int, struct _iobuf *); extern int scanf(const char* ...); extern void setbuf( struct _iobuf *, char*); extern void setbuffer( struct _iobuf *, char*, int); extern void setlinebuf( struct _iobuf *); extern void setvbuf( struct _iobuf *, char*, int, int); extern int sscanf(char*, const char* ...); extern struct _iobuf * tmpfile(); extern int ungetc(int, struct _iobuf *); extern int vfprintf( struct _iobuf *, const char*, void* ap); extern int vprintf(const char*, void* ap); extern int vsprintf(char*, const char*, void* ap); extern int sprintf(char*, const char* ...); # 2 "test0.h" # 1 "/usr/local/lib/g++-include/stddef.h" enum bool { FALSE = 0, TRUE = 1 }; typedef void (*one_arg_error_handler_t)(char*); # 3 "test0.h" class ifile { struct _iobuf *fp; char *name; public: ifile (char *name) { this->name = new char[strlen(name) + 1]; strcpy (this->name, name); if ((fp = fopen (name, "r")) == 0 ) { fprintf ( (&_iob[2]) , "could not open input file `%s'\n", name); exit (1); } } ~ifile () { fclose (fp); if (fp) fprintf ( (&_iob[2]) , "closing input file `%s'\n", name); } ifile& operator>> (int &i) { fscanf (fp, "%d", &i); return *this; } ifile& operator>> (char *p) { fscanf (fp, "%s", p); return *this; } }; class ofile { struct _iobuf *fp; char *name; public: ofile (char *name) { this->name = new char[strlen(name) + 1]; strcpy (this->name, name); if ((fp = fopen (name, "w")) == 0 ) { fprintf ( (&_iob[2]) , "could not open output file `%s'\n", name); exit (1); } } ~ofile () { fclose (fp); if (fp) fprintf ( (&_iob[2]) , "closing output file `%s'\n", name); } ofile& operator<< (int i) { fprintf (fp, "%d", i); fflush (fp); return *this; } ofile& operator<< (char *p) { fprintf (fp, "%s", p); fflush (fp); return *this; } }; # 9 "test.hello.cc" # 1 "/usr/include/a.out.h" struct exec { long a_magic; unsigned long a_text; unsigned long a_data; unsigned long a_bss; unsigned long a_syms; unsigned long a_trsize; unsigned long a_drsize; unsigned long a_entry; }; struct relocation_info { int r_address; unsigned int r_symbolnum:24, r_pcrel:1, r_length:2, r_extern:1, :4; }; struct nlist { union { char *n_name; long n_strx; } n_un; unsigned char n_type; char n_other; short n_desc; unsigned long n_value; }; # 10 "test.hello.cc" # 1 "/usr/include/sys/file.h" struct file { char f_flag; cnt_t f_count; union { struct inode *f_uinode; struct file *f_unext; } f_up; union { off_t f_off; } f_un; }; # 11 "test.hello.cc" void test0_message(); class tfile { char tname[ (sizeof( "/tmp/" ) + 15) ]; static char *orig_name; char *this_name; exec header; public: tfile (char*); ~tfile (); void* load (); }; tfile::tfile (char *p) { int fd; strcpy (tname, "hack.XXXXXX"); mktemp (tname); this_name = new char[strlen (p) + 1]; strcpy (this_name, p); if ((fd = open (this_name, 2, 0)) < 0) { fprintf ( (&_iob[2]) , "Unable to open file %s\n", p); exit (1); } if (read (fd, (void*) &header, sizeof (header)) <= 0) { fprintf ( (&_iob[2]) , "Error in reading file %s\n", p); } close (fd); } tfile::~tfile () { unlink (tname); } void *tfile::load () { int size = header.a_text + header.a_data; int pagsiz = getpagesize(); if (size < (pagsiz)) size = (pagsiz); int init_fn = (int) new short[size]; init_fn += pagsiz-1; init_fn &= ~(pagsiz-1); fprintf ( (&_iob[2]) , "\n ... timing incremental load...\n"); char command[512], *cmd = command; sprintf (cmd, "time %s -C -N -A %s -T %x %s %s -o %s", "/usr/local/lib/gcc-ld++" , orig_name, init_fn, "/usr/local/lib/crt1+.o" , this_name, tname); if (system (cmd)) { fprintf ( (&_iob[2]) , "Error in linking file bye\n"); delete this; exit (1); } int fd = open (tname, 2, 0); if (lseek (fd, sizeof (header), L_SET) < 0) { perror ("Error in temp file seek\n"); delete this; exit (1); } read (fd, (char*) init_fn, size); close (fd); fprintf ( (&_iob[2]) , "load symbol-table at address 0x%x\n", init_fn); return (void *)init_fn; } ifile in ("/dev/tty"); ofile out ("/dev/tty"); main (int, char *argv[]) { char buf[4096]; out << "Enter file to link: (test.bye or test.bye2 or test.shell)\n"; in >> buf; out << "Hello! linking `" << buf << "'...\n"; tfile::orig_name = argv[0]; tfile temp (buf); register void (*init_fn)() = temp.load (); fprintf ( (&_iob[2]) , "\n if execution now aborts, your crt1+.o is bad\n"); (*init_fn) (); out << "Enter another file to link: "; in >> buf; out << "Hello! linking `" << buf << "'...\n"; tfile temp2 (buf); init_fn = temp2.load (); (*init_fn)(); test0_message(); }