Subject: bin/2763: gcc does not use scrt0.o when linking static binaries
To: None <gnats-bugs@gnats.netbsd.org>
From: Mike Long <mike.long@analog.com>
List: netbsd-bugs
Date: 09/17/1996 02:46:13
>Number:         2763
>Category:       bin
>Synopsis:       gcc does not use scrt0.o when linking static binaries
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Sep 16 23:50:01 1996
>Last-Modified:
>Originator:     Mike Long <mike.long@analog.com>
>Organization:
	Squish!
>Release:        1.2_BETA
>Environment:
System: NetBSD azathoth 1.2_BETA NetBSD 1.2_BETA (AZATHOTH) #100: Mon Sep 2 21:56:30 EDT 1996 root@azathoth:/usr/src/sys/arch/i386/compile/AZATHOTH i386

>Description:
	gcc links static executables with crt0.o instead of scrt0.o,
incurring a significant size penalty.  Using scrt0.o instead of crt0.o
shrank my /bin directory by 72K, and my /sbin directory by 104K.  If
you're short a page on the install media, then this may help.

	This PR replaces my lib/2758; that change is no longer
necessary nor desirable.

>How-To-Repeat:
	cd /usr/src; make build
>Fix:
	Apply the patches below.  The first is a patch to gcc's
netbsd.h, which tells it to use scrt0.o with -static.  The other two
patches are updates to alpha and MIPS src/lib/csu makefiles to create
links from scrt0.o to crt0.o, which are identical on those
architectures.  (I also semi-gratuitously propagated Christos' make -j
changes from the i386 makefile.)  Thanks to Bill Sommerfeld, who came
up with the STARTFILE_SPEC string.

*** gnu/usr.bin/gcc/arch/netbsd.h.orig	Sat Apr 27 07:14:49 1996
--- gnu/usr.bin/gcc/arch/netbsd.h	Tue Sep 17 00:31:57 1996
***************
*** 61,64 ****
--- 61,71 ----
    "%{!nostdlib:%{!r*:%{!e*:-e start}}} -dc -dp %{R*} %{static:-Bstatic} %{assert*}"
  
+ /* Provide a STARTFILE_SPEC appropriate for NetBSD.  Here we provide
+    support for the special GCC option -static.  */
+ 
+ #undef STARTFILE_SPEC
+ #define STARTFILE_SPEC \
+   "%{!shared:%{pg:gcrt0%O%s}%{!pg:%{p:mcrt0%O%s}%{!p:%{!static:crt0%O%s}%{static:scrt0%O%s}}}}"
+ 
  /* This defines which switch letters take arguments. */
  #undef SWITCH_TAKES_ARG
*** lib/csu/alpha/Makefile.orig	Wed Dec 20 08:52:31 1995
--- lib/csu/alpha/Makefile	Tue Sep 17 02:13:15 1996
***************
*** 3,21 ****
  CFLAGS+=	-DLIBC_SCCS
  OBJS=		crt0.o gcrt0.o
! CLEANFILES+=	core a.out
  
  all: ${OBJS}
  
  crt0.o: crt0.s
! 	${CPP} -DCRT0 ${CFLAGS:M-[ID]*} ${.ALLSRC} | ${AS} -o $@
! 	@${LD} -x -r ${.TARGET}
! 	@mv a.out ${.TARGET}
  
  gcrt0.o: crt0.s
! 	${CPP} -DMCRT0 ${CFLAGS:M-[ID]*} ${.ALLSRC} | ${AS} -o $@
! 	@${LD} -x -r ${.TARGET}
! 	@mv a.out ${.TARGET}
  
! install:
  	install ${COPY} -o ${BINOWN} -g ${BINGRP} -m 444 ${OBJS} \
  		${DESTDIR}/usr/lib
--- 3,22 ----
  CFLAGS+=	-DLIBC_SCCS
  OBJS=		crt0.o gcrt0.o
! LINKS=		${DESTDIR}/usr/lib/crt0.o ${DESTDIR}/usr/lib/scrt0.o
! CLEANFILES+=	core
  
  all: ${OBJS}
  
  crt0.o: crt0.s
! 	${CPP} -DCRT0 ${CFLAGS:M-[ID]*} ${.ALLSRC} | ${AS} -o ${.TARGET}.o
! 	@${LD} -x -r ${.TARGET}.o -o ${.TARGET}
! 	@rm -f ${.TARGET}.o
  
  gcrt0.o: crt0.s
! 	${CPP} -DMCRT0 ${CFLAGS:M-[ID]*} ${.ALLSRC} | ${AS} -o ${.TARGET}.o
! 	@${LD} -x -r ${.TARGET}.o -o ${.TARGET}
! 	@rm -f ${.TARGET}.o
  
! realinstall:
  	install ${COPY} -o ${BINOWN} -g ${BINGRP} -m 444 ${OBJS} \
  		${DESTDIR}/usr/lib
*** lib/csu/mips/Makefile.orig	Tue Dec 12 07:16:37 1995
--- lib/csu/mips/Makefile	Tue Sep 17 02:13:26 1996
***************
*** 1,22 ****
  #	from: @(#)Makefile	8.1 (Berkeley) 6/1/93
! #	$Id: Makefile,v 1.5 1995/12/12 01:53:52 cgd Exp $
  
  CFLAGS+=	-DLIBC_SCCS
  OBJS=		crt0.o gcrt0.o
! CLEANFILES+=	core a.out
  
  all: ${OBJS}
  
  crt0.o: crt0.S
! 	${COMPILE.S} -DCRT0 ${.ALLSRC}
! 	${LD} -x -r ${.TARGET}
! 	mv a.out ${.TARGET}
  
  gcrt0.o: crt0.S
! 	${COMPILE.S} -DMCRT0 ${.ALLSRC} -o ${.TARGET}
! 	${LD} -x -r ${.TARGET}
! 	mv a.out ${.TARGET}
  
! install:
  	install ${COPY} -o ${BINOWN} -g ${BINGRP} -m 444 ${OBJS} \
  	    ${DESTDIR}/usr/lib
--- 1,23 ----
  #	from: @(#)Makefile	8.1 (Berkeley) 6/1/93
! #	$NetBSD: Makefile,v 1.5 1995/12/12 01:53:52 cgd Exp $
  
  CFLAGS+=	-DLIBC_SCCS
  OBJS=		crt0.o gcrt0.o
! LINKS=		${DESTDIR}/usr/lib/crt0.o ${DESTDIR}/usr/lib/scrt0.o
! CLEANFILES+=	core
  
  all: ${OBJS}
  
  crt0.o: crt0.S
! 	${COMPILE.S} -DCRT0 ${.ALLSRC} -o ${.TARGET}.o
! 	${LD} -x -r ${.TARGET}.o -o ${.TARGET}
! 	rm -f ${.TARGET}.o
  
  gcrt0.o: crt0.S
! 	${COMPILE.S} -DMCRT0 ${.ALLSRC} -o ${.TARGET}.o
! 	${LD} -x -r ${.TARGET}.o -o ${.TARGET}
! 	rm -f ${.TARGET}.o
  
! realinstall:
  	install ${COPY} -o ${BINOWN} -g ${BINGRP} -m 444 ${OBJS} \
  	    ${DESTDIR}/usr/lib
>Audit-Trail:
>Unformatted: