From:	CRDGW2::CRDGW2::MRGATE::"SMTP::PREP.AI.MIT.EDU::HELP-G++-REQUEST" 17-MAR-1991 20:42:04.91
To:	ARISIA::EVERHART
CC:	
Subj:	Re: shared libraries and g++ on SunOS 4.1

From:	help-g++-request@prep.ai.mit.edu@SMTP@CRDGW2
To:	Everhart@Arisia@MRGATE

Received:  by crdgw1.ge.com (5.57/GE 1.91)
	 id AA11403; Sun, 17 Mar 91 20:38:29 EST
Received: by life.ai.mit.edu (4.1/AI-4.10) id AA05294; Sun, 17 Mar 91 20:00:38 EST
Return-Path: <help-g++-request@prep.ai.mit.edu>
Received: from tut.cis.ohio-state.edu by life.ai.mit.edu (4.1/AI-4.10) id AA05274; Sun, 17 Mar 91 20:00:12 EST
Received: by tut.cis.ohio-state.edu (5.61-kk/5.910301)
	id AA08392; Sun, 17 Mar 91 19:57:18 -0500
Received: from USENET by tut.cis.ohio-state.edu with netnews
	for help-g++@prep.ai.mit.edu (help-g++@prep.ai.mit.edu)
	(contact usenet@tut.cis.ohio-state.edu if you have questions)
Date: 15 Mar 91 10:13:13 GMT
From: mcsun!ukc!warwick!cudcv@uunet.uu.net  (Rob McMahon)
Organization: Computing Services, Warwick University, UK
Subject: Re: shared libraries and g++ on SunOS 4.1
Message-Id: <CWJ&B0_@warwick.ac.uk>
References: <1991Mar13.020521.14431@csis.dit.csiro.au>
Sender: help-g++-request@prep.ai.mit.edu
To: help-g++@prep.ai.mit.edu

In article <1991Mar13.020521.14431@csis.dit.csiro.au> ken@csis.dit.csiro.au
writes: 
>I'm getting tired of the long linking times and huge binaries produced by
>ld++. Is there any way to use collect or whatever on g++ objects so that
>/bin/ld and shared libraries can be used instead?

I've been doing this with g++ all along, I've never been willing to do without
shared libraries.  Esentially all you have to do is set

	COFFLAGS = -DUSE_COLLECT

in the Makefile, and change the calls to ld in gcc.c:

*** 1.1	1991/02/03 19:10:36
--- gcc.c	1991/02/04 10:36:45
***************
*** 303,313 ****
  char *collect_spec =
    "%{!c:%{!M*:%{!E:%{!S:collect -o %g.s %g.R\n\
  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\
   %{A} %{d} %{e*} %{N} %{n} %{r} %{s} %{S} %{T*} %{t} %{u*} %{X} %{x} %{z}\
   %{y*} %{!nostdlib:%S} \
   %{L*} %o %{!nostdlib:-lg++ gnulib%s %{g:-lg} %L}\n }}}}";
--- 303,316 ----
  char *collect_spec =
    "%{!c:%{!M*:%{!E:%{!S:collect -o %g.s %g.R\n\
  as %g.s -o %g.O\n\
! ld %{o*} %g.R %g.O %l\
!  %{A} %{d} %{e*} %{N} %{n} %{r} %{s} %{S} %{T*} %{t} %{u*} %{X} %{x} %{z}\
!  %{y*} \
!  %{L*} %{!nostdlib:-lg++ gnulib%s %{g:-lg} %L}\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\
   %{A} %{d} %{e*} %{N} %{n} %{r} %{s} %{S} %{T*} %{t} %{u*} %{X} %{x} %{z}\
   %{y*} %{!nostdlib:%S} \
   %{L*} %o %{!nostdlib:-lg++ gnulib%s %{g:-lg} %L}\n }}}}";

I also had to define ASM_INT_OP (to ".long" for Sun3, ".word" for Sun4) when
compiling collect, and to modify collect.c to leave a bit of space.  There's a
bug fix in here too.

*** 1.1	1991/02/03 18:00:50
--- collect.c	1991/02/03 18:02:07
***************
*** 98,104 ****
  
  #ifndef ASM_OUTPUT_LABELREF_AS_INT
  #define ASM_OUTPUT_LABELREF_AS_INT(FILE,NAME)	\
!   (fprintf(FILE,"\t%s", ASM_INT_OP), \
     ASM_OUTPUT_LABELREF(FILE,NAME), \
     fprintf(FILE,"\n"))
  #endif
--- 98,104 ----
  
  #ifndef ASM_OUTPUT_LABELREF_AS_INT
  #define ASM_OUTPUT_LABELREF_AS_INT(FILE,NAME)	\
!   (fprintf(FILE,"\t%s ", ASM_INT_OP), \
     ASM_OUTPUT_LABELREF(FILE,NAME), \
     fprintf(FILE,"\n"))
  #endif
***************
*** 105,111 ****
  
  #ifndef ASM_OUTPUT_PTR_INT_SUM
  #define ASM_OUTPUT_PTR_INT_SUM(FILE,NAME,VALUE)	\
!   (fprintf(FILE,"\t%s", ASM_INT_OP), \
     ASM_OUTPUT_LABELREF(FILE,NAME), \
     fprintf(FILE,"+%d\n", VALUE))
  #endif
--- 105,111 ----
  
  #ifndef ASM_OUTPUT_PTR_INT_SUM
  #define ASM_OUTPUT_PTR_INT_SUM(FILE,NAME,VALUE)	\
!   (fprintf(FILE,"\t%s ", ASM_INT_OP), \
     ASM_OUTPUT_LABELREF(FILE,NAME), \
     fprintf(FILE,"+%d\n", VALUE))
  #endif
***************
*** 312,318 ****
    
    exists = 0;
    while (p) {
!     if (strcmp( symbol_name, p -> name ) == 0 ) {
        exists = 1;
        break;
      }
--- 312,318 ----
    
    exists = 0;
    while (p) {
!     if (strcmp( symbol_name + CTOR_DTOR_MARKER_OFFSET, p -> name ) == 0 ) {
        exists = 1;
        break;
      }

Cheers,

Rob
-- 
UUCP:   ...!mcsun!ukc!warwick!cudcv	PHONE:  +44 203 523037
JANET:  cudcv@uk.ac.warwick             INET:   cudcv@warwick.ac.uk
Rob McMahon, Computing Services, Warwick University, Coventry CV4 7AL, England
