[gnu.g++.bug] How to use collect2... my conjecture

ngo%tammy@HARVARD.HARVARD.EDU (Tom Ngo) (01/18/90)

Versions:  gcc 1.36; g++ 1.36.3
Machine:   Convex C220

It appears to me that collect creates assembler output, whereas
collect2 makes an object.  The following patches enabled me to compile
"hello, world" on a Convex, which requires collect2.  I hope this is
the right way to go about doing this...

The following patches are to gcc.c, Makefile and config/tm-convex.h.
These patches do not fix the cc1plus crashes that people have been
reporting.

--Tom Ngo

===========================================================================
Patches to gcc.c
===========================================================================
ngo@tammy [72] diff -c gcc.c{.~1~,}
*** gcc.c.~1~	Wed Nov  8 20:20:40 1989
--- gcc.c	Wed Jan 17 16:38:00 1990
***************
*** 297,303
    {0, 0}
  };
  
! #ifdef USE_COLLECT
  /* C++: Here is the spec for collecting global ctor and dtor
     requirements.  */
  char *collect_spec =

--- 297,303 -----
    {0, 0}
  };
  
! #if defined(USE_COLLECT) || defined(USE_COLLECT2)
  /* C++: Here is the spec for collecting global ctor and dtor
     requirements.  */
  #ifdef USE_COLLECT
***************
*** 300,305
  #ifdef USE_COLLECT
  /* C++: Here is the spec for collecting global ctor and dtor
     requirements.  */
  char *collect_spec =
    "%{!c:%{!M*:%{!E:%{!S:collect -o %g.S %g.R\n\
  as %g.S -o %g.O\n\

--- 300,306 -----
  #if defined(USE_COLLECT) || defined(USE_COLLECT2)
  /* C++: Here is the spec for collecting global ctor and dtor
     requirements.  */
+ #ifdef USE_COLLECT
  char *collect_spec =
    "%{!c:%{!M*:%{!E:%{!S:collect -o %g.S %g.R\n\
  as %g.S -o %g.O\n\
***************
*** 305,310
  as %g.S -o %g.O\n\
  ld %{o*} %g.R %g.O\n\
  }}}}";
  
  /* Here is the spec for running the linker, after compiling all files.  */
  char *link_spec = "%{!c:%{!M*:%{!E:%{!S:ld -r -o %g.R %l\

--- 306,316 -----
  as %g.S -o %g.O\n\
  ld %{o*} %g.R %g.O\n\
  }}}}";
+ #else
+ char *collect_spec =
+   "%{!c:%{!M*:%{!E:%{!S:collect2 %{o*} %g.R\n\
+ }}}}";
+ #endif
  
  /* Here is the spec for running the linker, after compiling all files.  */
  char *link_spec = "%{!c:%{!M*:%{!E:%{!S:ld -r -o %g.R %l\
***************
*** 1818,1824
        linker_was_run = (tmp != execution_count);
      }
  
! #ifdef USE_COLLECT
    /* C++: now collect all the requirements for
       calling global constructors and destructors,
       and write them to a file.  We will link this file

--- 1824,1830 -----
        linker_was_run = (tmp != execution_count);
      }
  
! #if defined(USE_COLLECT) || defined(USE_COLLECT2)
    /* C++: now collect all the requirements for
       calling global constructors and destructors,
       and write them to a file.  We will link this file

===========================================================================
Patches to Makefile
===========================================================================

ngo@tammy [76] diff -c Makefile-orig Makefile
*** Makefile-orig	Wed Jan 17 11:24:40 1990
--- Makefile	Wed Jan 17 16:33:55 1990
***************
*** 37,43
  # use `-dy'.
  
  # On COFF systems, use one of the definitions below. (see collect.c)
! # COFFLAGS = -DUSE_COLLECT -DCOFF
  # COFFLAGS = -DUSE_COLLECT -DEXTENDED_COFF
  
  # On some BSD systems (like Vax, unlike Sun), there is no file

--- 37,43 -----
  # use `-dy'.
  
  # On COFF systems, use one of the definitions below. (see collect.c)
! COFFLAGS = -DUSE_COLLECT2 -DCOFF
  # COFFLAGS = -DUSE_COLLECT -DEXTENDED_COFF
  
  # On some BSD systems (like Vax, unlike Sun), there is no file
***************
*** 43,49
  # On some BSD systems (like Vax, unlike Sun), there is no file
  # /usr/include/unistd.h.  If this is the case for your system
  # uncomment the following line.
! # HAVE_UNISTD_H = -DNO_UNISTD_H
  
  # CFLAGS = -g -DSOS -DESKIT -O
  CFLAGS = -g -DGATHER_STATISTICS -O $(COFFLAGS) -DESKIT

--- 43,49 -----
  # On some BSD systems (like Vax, unlike Sun), there is no file
  # /usr/include/unistd.h.  If this is the case for your system
  # uncomment the following line.
! HAVE_UNISTD_H = -DNO_UNISTD_H
  
  # CFLAGS = -g -DSOS -DESKIT -O
  CFLAGS = -g -DGATHER_STATISTICS -O $(COFFLAGS) -DESKIT
***************
*** 204,210
  
  # gnulib is not a target because a proper installation of GNU CC
  # will place it where g++ can find it.  Same with cpp
! all: crt1+.o g++ cc1plus ld++ g++filt # collect crt0+.o
  # On COFF systems, use the target below.
  # all: g++ cc1plus collect # crt0+.o crt1+.o
  

--- 204,210 -----
  
  # gnulib is not a target because a proper installation of GNU CC
  # will place it where g++ can find it.  Same with cpp
! # all: crt1+.o g++ cc1plus ld++ g++filt # collect crt0+.o
  # On COFF systems, use the target below.
  all: g++ cc1plus collect2 # crt0+.o crt1+.o
  
***************
*** 206,212
  # will place it where g++ can find it.  Same with cpp
  all: crt1+.o g++ cc1plus ld++ g++filt # collect crt0+.o
  # On COFF systems, use the target below.
! # all: g++ cc1plus collect # crt0+.o crt1+.o
  
  doc: $(srcdir)/cpp.info $(srcdir)/g++.info
  

--- 206,212 -----
  # will place it where g++ can find it.  Same with cpp
  # all: crt1+.o g++ cc1plus ld++ g++filt # collect crt0+.o
  # On COFF systems, use the target below.
! all: g++ cc1plus collect2 # crt0+.o crt1+.o
  
  doc: $(srcdir)/cpp.info $(srcdir)/g++.info
  
***************
*** 289,295
  	$(CC) -o collect $(PROFILE) $$COLLECT_OPTIONS $(CFLAGS) $(INCLUDES) $< -lg -lc $$COLLECT_LIBS
  
  collect2: collect2.c config.h
! 	$(CC) -o collect2 $(PROFILE) $$COLLECT_OPTIONS $(CFLAGS) $(INCLUDES) $< -lc
  
  g++filt: g++filt.o cplus-dem.o
  	$(CC) -o g++filt g++filt.o cplus-dem.o

--- 289,295 -----
  	$(CC) -o collect $(PROFILE) $$COLLECT_OPTIONS $(CFLAGS) $(INCLUDES) $< -lg -lc $$COLLECT_LIBS
  
  collect2: collect2.c config.h
! 	$(CC) -o collect2 collect2.c $(PROFILE) $$COLLECT_OPTIONS $(CFLAGS) $(INCLUDES) -lc
  
  g++filt: g++filt.o cplus-dem.o
  	$(CC) -o g++filt g++filt.o cplus-dem.o
***************
*** 596,602
  	-mkdir $(startdir)
  	-if [ -f cc1plus ] ; then $(INSTALL) cc1plus  $(libdir)/gcc-cc1plus ;fi
  	-if [ -f collect ] ; then $(INSTALL) collect  $(libdir)/gcc-collect ;fi
! 	-if [ -f collect2 ] ; then $(INSTALL) collect2  $(libdir)/gcc-collect ;fi
  	$(INSTALL) g++ $(bindir)
  	-if [ -f ld++ ] ; then $(INSTALL) ld++ $(libdir)/gcc-ld ;fi
  #	-if [ -f crt0+.o ] ; then $(INSTALL) crt0+.o $(startdir)/crt0+.o ;fi

--- 596,602 -----
  	-mkdir $(startdir)
  	-if [ -f cc1plus ] ; then $(INSTALL) cc1plus  $(libdir)/gcc-cc1plus ;fi
  	-if [ -f collect ] ; then $(INSTALL) collect  $(libdir)/gcc-collect ;fi
! 	-if [ -f collect2 ] ; then $(INSTALL) collect2  $(libdir)/gcc-collect2 ;fi
  	$(INSTALL) g++ $(bindir)
  	-if [ -f ld++ ] ; then $(INSTALL) ld++ $(libdir)/gcc-ld ;fi
  #	-if [ -f crt0+.o ] ; then $(INSTALL) crt0+.o $(startdir)/crt0+.o ;fi

===========================================================================
Patch to config/tm-convex.h:
Appended the line "#define FASCIST_ASSEMBLER"
(Thanks to gillis@aerospace.aero.org)
===========================================================================