[gnu.g++.bug] Problem running libg++/test0 using GNU C++ 1.27.0

montnaro@sprite.steinmetz.ge.com (Skip Montanaro) (10/21/88)

I tried sending the following to Doug Lea, but it bounced. (I think I muffed
the address.) Doug, if you're out there (or anyone else who's got any idea
what's going on):

I'm trying to build libg++ 1.25.0 using GNU C++ 1.27.0 and GCC 1.27.

When run, test0 gets a segmentation fault in fprintf (Environment ==
Sun-3/260 running SunOS 3.4):

----------
sprite% test0
Memory fault - core dumped
sprite% gdbplus test0 core
GDB 2.8.0 (GNU C++ 1.27.0 compatible), Copyright (C) 1988 Free Software
Foundation, Inc.
There is ABSOLUTELY NO WARRANTY for GDB; type "info warranty" for details.
GDB is free software and you are welcome to distribute copies of it
 under certain conditions; type "info copying" to see the conditions.
Reading symbol data from /usr/karnack/u6/montnaro/libg++-1.25.0/test0...done.
Core file is from "test0".
Program terminated with signal 11, Segmentation fault.
Type "help" for a list of commands.
(gdb+) bt
#0  0x4b58 in fprintf ()
#1  0x2200 in op$alshift_expr_PSofile_PQI ($this=(struct ofile *) 0x20034, p=(char *) 0x2652 "Enter file to link: (test.bye or test.bye2 or test.shell)\n") (test0.h line 69)
#2  0x270a in main ((anon)=1, argv=(char **) 0xefff7f8) (test.hello.cc line 107)
(gdb+) 
----------

I also get warnings when compiling test0 :

----------
cd /usr/karnack/u3/montnaro/u6/libg++-1.25.0/
make test0
/usr/karnack/u6/montnaro/g++/bin/g++ -c -v -g -O -fchar-charconst -B/usr/karnack/u6/montnaro/g++/bin/ test.hello.cc -o test.hello.o
g++ version 1.27.0
 /usr/karnack/u6/montnaro/g++/lib/gcc-cpp+ -v -undef -D__GNU__ -D__GNUG__ -Dmc68000 -Dsun -Dunix -D__OPTIMIZE__ test.hello.cc /tmp/cca02915.cpp
GNU CPP version 1.27.0
 /usr/karnack/u6/montnaro/g++/lib/gcc-c++ /tmp/cca02915.cpp -quiet -dumpbase test.hello.cc -fchar-charconst -opt -version -G -o /tmp/cca02915.s
GNU C++ version 1.27.0 (68k, MIT syntax) compiled by GNU C version 1.27.

At top level:
/usr/include/sys/fcntl.h:64: warning: type declaration of flock shadows previous declaration
/usr/include/sys/fcntl.h:64: warning: `flock' was declared `extern' and later `static'

test.hello.cc:114: warning: initialization between incompatible pointer types
test.hello.cc:123: warning: assignment between incompatible pointer types
 as -mc68020 /tmp/cca02915.s -o test.hello.o
install -c dummylibg++.a /usr/karnack/u6/montnaro/g++/lib/libg++.a
ranlib /usr/karnack/u6/montnaro/g++/lib/libg++.a
/usr/karnack/u6/montnaro/g++/bin/g++ -v -g -O -fchar-charconst -B/usr/karnack/u6/montnaro/g++/bin/ test.hello.o -o test0
g++ version 1.27.0
 /usr/karnack/u6/montnaro/g++/lib/gcc-ld++ -C -o test0 /lib/crt0.o /lib/Mcrt1.o test.hello.o -lg++ /usr/karnack/u6/montnaro/g++/lib/gcc-gnulib+ -lg -lc
please run test0 and follow instructions

Compilation finished at Mon Oct 17 16:01:25
----------

As far as I can tell, I've got GNU C++ installed properly. Notice that
bindir and libdir are different than the distribution. This is so I can test
the new version before final installation. I discovered a couple problems.
One, there were some hard-coded references to /usr/local/lib scattered
throughout the code. Two, _test0_message was undefined, because
/usr/local/lib was being searched first and an old version of libg++.a (from
1.21.0) was being used.  I eventually resorted to renaming all G++-related
files in /usr/local/lib to *-1.21.0 to prevent that from occurring, however,
I'm still getting core dumps. I guess my next step will be to actually
install G++ in the production directories before testing, but I'd rather
avoid that if possible.

Further investigation with gdb+ shows that the fp class variable in the
ofile class is apparently not getting initialized (i.e., out.fp == 0), so
when

	out << "...";

gets executed, fprintf gets called with a NULL stream arg. Since all the
constructor/destructor stuff is implicit, it looks like there's a bug in GNU
C++. I can't see any call to initialize out's private variables before the
first use of out when I examine test.hello.s.

Any help would be appreciated. Test.hello.cc (after cpp+ and squishing blank
lines) and test.hello.s follow.

test.hello.cc:
-------------

sprite% ../g++/bin/g++ -v -B../g++/lib/ -E test.hello.cc
g++ version 1.27.0
 /usr/karnack/u6/montnaro/g++/lib/gcc-cpp+ -v -undef -D__GNU__ -D__GNUG__ -Dmc68000 -Dsun -Dunix test.hello.cc
GNU CPP version 1.27.0
# 1 "test.hello.cc"
# 1 "test0.h"
# 1 "/usr/karnack/u6/montnaro/g++/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/karnack/u6/montnaro/g++/lib/g++-include/stdio.h"
extern  struct  _iobuf {
    int      _cnt;
    char*    _ptr;
    char*    _base;
    int     _bufsiz;
    short   _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/karnack/u6/montnaro/g++/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"
# 1 "/usr/include/sys/exec.h"
struct exec {
	unsigned short	a_machtype;	 
	unsigned short	a_magic;	 
	unsigned long	a_text;		 
	unsigned long	a_data;		 
	unsigned long	a_bss;		 
	unsigned long	a_syms;		 
	unsigned long	a_entry;	 
	unsigned long	a_trsize;	 
	unsigned long	a_drsize;	 
};
# 3 "/usr/include/a.out.h"
struct relocation_info {
	long	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"
# 1 "/usr/include/sys/fcntl.h"
struct flock {
        short   l_type;		 
        short   l_whence;	 
        long    l_start;	 
        long    l_len;           
        short   l_pid;		 
        short   l_xxx;		 
};
# 9 "/usr/include/sys/file.h"
# 37 "/usr/include/sys/file.h"
# 84 "/usr/include/sys/file.h"
# 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 = 	0x2000 ;
  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/karnack/u6/montnaro/g++/lib/gcc-ld++" , orig_name, init_fn, "/usr/karnack/u6/montnaro/g++/lib/gcc-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), 	0	) < 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();
}

test.hello.s:
-------------

#NO_APP
.text
LC0:
	.ascii "%s\0"
	.even
_op$arshift_expr_PSifile_PQI:
	link a6,#0
	movel d2,sp@-
	movel a6@(12),sp@-
	pea LC0
	movel a6@(8),a0
	movel a0@,sp@-
	jbsr _fscanf
	movel a6@(8),d2
	movel d2,d0
	addw #12,sp
	jra L1
L1:
	movel a6@(-4),d2
	unlk a6
	rts
LC1:
	.ascii "%d\0"
	.even
_op$arshift_expr_PSifile_SI:
	link a6,#0
	movel d2,sp@-
	movel a6@(12),sp@-
	pea LC1
	movel a6@(8),a0
	movel a0@,sp@-
	jbsr _fscanf
	movel a6@(8),d2
	movel d2,d0
	addw #12,sp
	jra L2
L2:
	movel a6@(-4),d2
	unlk a6
	rts
LC2:
	.ascii "r\0"
LC3:
	.ascii "could not open input file `%s'\12\0"
	.even
_ifile_PSifile_PQI:
	link a6,#0
	movel d2,sp@-
	tstl a6@(8)
	jne L5
	pea 8:w
	jbsr ___builtin_new
	movel d0,a6@(8)
	addqw #4,sp
L5:
	movel a6@(12),sp@-
	jbsr _strlen
	movel d0,d0
	addql #1,d0
	movel d0,sp@-
	jbsr ___builtin_new
	movel d0,d0
	movel a6@(8),a0
	movel d0,a0@(4)
	movel a6@(12),sp@-
	movel a6@(8),a0
	movel a0@(4),sp@-
	jbsr _strcpy
	pea LC2
	movel a6@(12),sp@-
	jbsr _fopen
	movel d0,d0
	movel a6@(8),a0
	movel d0,d0
	movel d0,a0@
	addw #24,sp
	tstl d0
	jne L4
	movel a6@(12),sp@-
	pea LC3
	moveq #40,d0
	addl #__iob,d0
	movel d0,sp@-
	jbsr _fprintf
	pea 1:w
	jbsr _exit
	addw #16,sp
L4:
	movel a6@(8),d2
	movel d2,d0
	jra L3
L3:
	movel a6@(-4),d2
	unlk a6
	rts
LC4:
	.ascii "closing input file `%s'\12\0"
	.even
__$_ifile:
	link a6,#0
	tstl a6@(8)
	jeq L9
	movel a6@(8),a0
	movel a0@,sp@-
	jbsr _fclose
	movel a6@(8),a0
	addqw #4,sp
	tstl a0@
	jeq L7
	movel a6@(8),a0
	movel a0@(4),sp@-
	pea LC4
	moveq #40,d0
	addl #__iob,d0
	movel d0,sp@-
	jbsr _fprintf
	addw #12,sp
L7:
	tstl a6@(12)
	jeq L8
L8:
L9:
L6:
	unlk a6
	rts
	.even
_op$alshift_expr_PSofile_PQI:
	link a6,#0
	movel d2,sp@-
	movel a6@(12),sp@-
	pea LC0
	movel a6@(8),a0
	movel a0@,sp@-
	jbsr _fprintf
	movel a6@(8),a0
	movel a0@,sp@-
	jbsr _fflush
	movel a6@(8),d2
	movel d2,d0
	addw #16,sp
	jra L10
L10:
	movel a6@(-4),d2
	unlk a6
	rts
	.even
_op$alshift_expr_PSofile_SI:
	link a6,#0
	movel d2,sp@-
	movel a6@(12),sp@-
	pea LC1
	movel a6@(8),a0
	movel a0@,sp@-
	jbsr _fprintf
	movel a6@(8),a0
	movel a0@,sp@-
	jbsr _fflush
	movel a6@(8),d2
	movel d2,d0
	addw #16,sp
	jra L11
L11:
	movel a6@(-4),d2
	unlk a6
	rts
LC5:
	.ascii "w\0"
LC6:
	.ascii "could not open output file `%s'\12\0"
	.even
_ofile_PSofile_PQI:
	link a6,#0
	movel d2,sp@-
	tstl a6@(8)
	jne L14
	pea 8:w
	jbsr ___builtin_new
	movel d0,a6@(8)
	addqw #4,sp
L14:
	movel a6@(12),sp@-
	jbsr _strlen
	movel d0,d0
	addql #1,d0
	movel d0,sp@-
	jbsr ___builtin_new
	movel d0,d0
	movel a6@(8),a0
	movel d0,a0@(4)
	movel a6@(12),sp@-
	movel a6@(8),a0
	movel a0@(4),sp@-
	jbsr _strcpy
	pea LC5
	movel a6@(12),sp@-
	jbsr _fopen
	movel d0,d0
	movel a6@(8),a0
	movel d0,d0
	movel d0,a0@
	addw #24,sp
	tstl d0
	jne L13
	movel a6@(12),sp@-
	pea LC6
	moveq #40,d0
	addl #__iob,d0
	movel d0,sp@-
	jbsr _fprintf
	pea 1:w
	jbsr _exit
	addw #16,sp
L13:
	movel a6@(8),d2
	movel d2,d0
	jra L12
L12:
	movel a6@(-4),d2
	unlk a6
	rts
LC7:
	.ascii "closing output file `%s'\12\0"
	.even
__$_ofile:
	link a6,#0
	tstl a6@(8)
	jeq L18
	movel a6@(8),a0
	movel a0@,sp@-
	jbsr _fclose
	movel a6@(8),a0
	addqw #4,sp
	tstl a0@
	jeq L16
	movel a6@(8),a0
	movel a0@(4),sp@-
	pea LC7
	moveq #40,d0
	addl #__iob,d0
	movel d0,sp@-
	jbsr _fprintf
	addw #12,sp
L16:
	tstl a6@(12)
	jeq L17
L17:
L18:
L15:
	unlk a6
	rts
LC8:
	.ascii "hack.XXXXXX\0"
LC9:
	.ascii "Unable to open file %s\12\0"
LC10:
	.ascii "Error in reading file %s\12\0"
	.even
.globl _tfile_PStfile_PQI
_tfile_PStfile_PQI:
	link a6,#-4
	movel d2,sp@-
	tstl a6@(8)
	jne L22
	pea 58:w
	jbsr ___builtin_new
	movel d0,a6@(8)
	addqw #4,sp
L22:
	pea LC8
	movel a6@(8),d0
	movel d0,sp@-
	jbsr _strcpy
	movel a6@(8),d0
	movel d0,sp@-
	jbsr _mktemp
	movel a6@(12),sp@-
	jbsr _strlen
	movel d0,d0
	addql #1,d0
	movel d0,sp@-
	jbsr ___builtin_new
	movel d0,d0
	movel a6@(8),a0
	movel d0,a0@(22)
	movel a6@(12),sp@-
	movel a6@(8),a0
	movel a0@(22),sp@-
	jbsr _strcpy
	clrl sp@-
	pea 2:w
	movel a6@(8),a0
	movel a0@(22),sp@-
	jbsr _open
	movel d0,d0
	movel d0,d0
	movel d0,a6@(-4)
	addw #40,sp
	tstl d0
	jge L20
	movel a6@(12),sp@-
	pea LC9
	moveq #40,d0
	addl #__iob,d0
	movel d0,sp@-
	jbsr _fprintf
	pea 1:w
	jbsr _exit
	addw #16,sp
L20:
	pea 32:w
	moveq #26,d0
	addl a6@(8),d0
	movel d0,sp@-
	movel a6@(-4),sp@-
	jbsr _read
	movel d0,d0
	addw #12,sp
	tstl d0
	jgt L21
	movel a6@(12),sp@-
	pea LC10
	moveq #40,d0
	addl #__iob,d0
	movel d0,sp@-
	jbsr _fprintf
	addw #12,sp
L21:
	movel a6@(-4),sp@-
	jbsr _close
	addqw #4,sp
	movel a6@(8),d2
	movel d2,d0
	jra L19
L19:
	movel a6@(-8),d2
	unlk a6
	rts
	.even
.globl __$_tfile
__$_tfile:
	link a6,#0
	tstl a6@(8)
	jeq L25
	movel a6@(8),d0
	movel d0,sp@-
	jbsr _unlink
	addqw #4,sp
	tstl a6@(12)
	jeq L24
L24:
L25:
L23:
	unlk a6
	rts
LC11:
	.ascii "\12 ... timing incremental load...\12\0"
LC12:
	.ascii "/usr/karnack/u6/montnaro/g++/lib/gcc-crt1+.o\0"
LC13:
	.ascii "/usr/karnack/u6/montnaro/g++/lib/gcc-ld++\0"
LC14:
	.ascii "time %s -C -N -A %s -T %x %s %s -o %s\0"
LC15:
	.ascii "Error in linking file bye\12\0"
LC16:
	.ascii "Error in temp file seek\12\0"
LC17:
	.ascii "load symbol-table at address 0x%x\12\0"
	.even
.globl _load_PStfile
_load_PStfile:
	link a6,#-532
	movel d2,sp@-
	movel a6@(8),a0
	movel a6@(8),a1
	movel a0@(30),d1
	addl a1@(34),d1
	movel d1,a6@(-4)
	movel #8192,a6@(-8)
	movel a6@(-4),d1
	cmpl a6@(-8),d1
	jge L27
	movel a6@(-8),a6@(-4)
L27:
	movel a6@(-4),d0
	asll #1,d0
	movel d0,sp@-
	jbsr ___builtin_new
	movel d0,a6@(-12)
	movel d0,d0
	subql #1,d0
	movel d0,d1
	addl a6@(-8),d1
	movel d1,a6@(-12)
	movel a6@(-8),d0
	subql #1,d0
	notl d0
	andl d0,a6@(-12)
	pea LC11
	moveq #40,d0
	addl #__iob,d0
	movel d0,sp@-
	jbsr _fprintf
	movel a6,d1
	addl #-524,d1
	movel d1,a6@(-528)
	movel a6@(8),d0
	movel d0,sp@-
	movel a6@(8),a0
	movel a0@(22),sp@-
	pea LC12
	movel a6@(-12),sp@-
	movel __tfile$orig_name,sp@-
	pea LC13
	pea LC14
	movel a6@(-528),sp@-
	jbsr _sprintf
	addw #44,sp
	movel a6@(-528),sp@-
	jbsr _system
	movel d0,d0
	addqw #4,sp
	tstl d0
	jeq L28
	pea LC15
	moveq #40,d0
	addl #__iob,d0
	movel d0,sp@-
	jbsr _fprintf
	pea 1:w
	movel a6@(8),sp@-
	jbsr __$_tfile
	pea 1:w
	jbsr _exit
	addw #20,sp
L28:
	clrl sp@-
	pea 2:w
	movel a6@(8),d0
	movel d0,sp@-
	jbsr _open
	movel d0,a6@(-532)
	clrl sp@-
	pea 32:w
	movel a6@(-532),sp@-
	jbsr _lseek
	movel d0,d0
	addw #24,sp
	tstl d0
	jge L29
	pea LC16
	jbsr _perror
	pea 1:w
	movel a6@(8),sp@-
	jbsr __$_tfile
	pea 1:w
	jbsr _exit
	addw #16,sp
L29:
	movel a6@(-4),sp@-
	movel a6@(-12),sp@-
	movel a6@(-532),sp@-
	jbsr _read
	movel a6@(-532),sp@-
	jbsr _close
	movel a6@(-12),sp@-
	pea LC17
	moveq #40,d0
	addl #__iob,d0
	movel d0,sp@-
	jbsr _fprintf
	movel a6@(-12),d2
	movel d2,d0
	addw #28,sp
	jra L26
L26:
	movel a6@(-536),d2
	unlk a6
	rts
LC18:
	.ascii "Enter file to link: (test.bye or test.bye2 or test.shell)\12\0"
LC19:
	.ascii "'...\12\0"
LC20:
	.ascii "Hello! linking `\0"
LC21:
	.ascii "\12 if execution now aborts, your crt1+.o is bad\12\0"
LC22:
	.ascii "Enter another file to link: \0"
	.even
.globl _main
_main:
	link a6,#-4212
	movel a2,sp@-
	pea LC18
	pea _out
	jbsr _op$alshift_expr_PSofile_PQI
	movel a6,d0
	addl #-4096,d0
	movel d0,sp@-
	pea _in
	jbsr _op$arshift_expr_PSifile_PQI
	pea LC19
	movel a6,d0
	addl #-4096,d0
	movel d0,sp@-
	pea LC20
	pea _out
	jbsr _op$alshift_expr_PSofile_PQI
	addqw #8,sp
	movel d0,d0
	movel d0,sp@-
	jbsr _op$alshift_expr_PSofile_PQI
	addqw #8,sp
	movel d0,d0
	movel d0,sp@-
	jbsr _op$alshift_expr_PSofile_PQI
	movel a6@(12),a0
	movel a0@,__tfile$orig_name
	movel a6,d0
	addl #-4096,d0
	movel d0,sp@-
	movel a6,d0
	addl #-4154,d0
	movel d0,sp@-
	jbsr _tfile_PStfile_PQI
	addw #32,sp
	movel a6,d0
	addl #-4154,d0
	movel d0,sp@-
	jbsr _load_PStfile
	movel d0,a2
	pea LC21
	moveq #40,d0
	addl #__iob,d0
	movel d0,sp@-
	jbsr _fprintf
	jbsr a2@
	pea LC22
	pea _out
	jbsr _op$alshift_expr_PSofile_PQI
	movel a6,d0
	addl #-4096,d0
	movel d0,sp@-
	pea _in
	jbsr _op$arshift_expr_PSifile_PQI
	pea LC19
	movel a6,d0
	addl #-4096,d0
	movel d0,sp@-
	pea LC20
	pea _out
	jbsr _op$alshift_expr_PSofile_PQI
	addqw #8,sp
	movel d0,d0
	movel d0,sp@-
	jbsr _op$alshift_expr_PSofile_PQI
	addqw #8,sp
	movel d0,d0
	movel d0,sp@-
	jbsr _op$alshift_expr_PSofile_PQI
	addw #36,sp
	movel a6,d0
	addl #-4096,d0
	movel d0,sp@-
	movel a6,d0
	addl #-4212,d0
	movel d0,sp@-
	jbsr _tfile_PStfile_PQI
	movel a6,d0
	addl #-4212,d0
	movel d0,sp@-
	jbsr _load_PStfile
	movel d0,a2
	jbsr a2@
	jbsr _test0_message
	clrl sp@-
	movel a6,d0
	addl #-4212,d0
	movel d0,sp@-
	jbsr __$_tfile
	clrl sp@-
	movel a6,d0
	addl #-4154,d0
	movel d0,sp@-
	jbsr __$_tfile
	addw #28,sp
L30:
	movel a6@(-4216),a2
	unlk a6
	rts
	.even
.globl __GLOBAL_$D$test_hello_cc
__GLOBAL_$D$test_hello_cc:
	link a6,#0
	clrl sp@-
	pea _out
	jbsr __$_ofile
	clrl sp@-
	pea _in
	jbsr __$_ifile
	addw #16,sp
L31:
	unlk a6
	rts
LC23:
	.ascii "/dev/tty\0"
	.even
.globl __GLOBAL_$I$test_hello_cc
__GLOBAL_$I$test_hello_cc:
	link a6,#0
	pea LC23
	pea _in
	jbsr _ifile_PSifile_PQI
	pea LC23
	pea _out
	jbsr _ofile_PSofile_PQI
	addw #16,sp
L32:
	unlk a6
	rts
.globl _out
.data
	.even
_out:
	.skip 8
.globl _in
	.even
_in:
	.skip 8
.comm __tfile$orig_name,4
--
Skip Montanaro (montanaro@sprite.steinmetz.ge.com, montanaro@ge-crd.arpa)