*BSD News Article 8191


Return to BSD News archive

Newsgroups: comp.unix.bsd
Path: sserve!manuel.anu.edu.au!munnari.oz.au!news.hawaii.edu!ames!haven.umd.edu!uunet!mcsun!Germany.EU.net!rzsun2.informatik.uni-hamburg.de!tech7!lohse
From: lohse@tech7.informatik.uni-hamburg.de (Joerg Lohse)
Subject: Shared Libraries for 386BSD (long, w/source)
Message-ID: <lohse.722861707@tech7>
Sender: news@informatik.uni-hamburg.de (Mr. News)
Organization: University of Hamburg, FRG
Date: 27 Nov 92 10:55:07 GMT
Lines: 1378

This is an experimental implementation of shared libraries for 386BSD. This
implementation has the following properties:

 - No kernel extension is necessary. Just the shared libraries need to be
   installed in order to run programs using them.

 - The shared libraries follow the approach used in System V: Shared libraries
   are linked to fixed addresses and mapped in the address space at this
   fixed address.
   There are no symbols resolved at load-time as in AIX 3.x and SunOS.

 - This package includes makefiles and programs that create shared version of
   the C and X11 libraries and an extended version of the startup file crt0.o

 - It also includes patches for the cc and g++ commands in order to link to
   the shared version of the libc unless started with "-static". The shared
   version of the libX11 must be explicitly specified as "-lX11_s".

I'm leaving for a job in another town. I haven't had time to implement exten-
sions that it would be nice to have. However, it's working as is.
I can't promise that email will reach me or that I can follow this news-group
within the next time, sorry.

Enjoy,
 Joerg

-------------------------------------------------------------------------------
Dr. Joerg Lohse                          lohse@tech7.informatik.uni-hamburg.de
Fachbereich Informatik
Universitaet Hamburg                     I'm joining Siemens Corporate Research
Troplowitzstr. 7                         in Munich on December 1st. Don't know
D-2000 Hamburg 54                        the new internet address yet, sorry.
Germany

-------------------- cut here ------------------ cut here ---------------------
#!/bin/sh
# This is a shell archive (shar 3.32)
# made 11/27/1992 08:46 UTC by lohse@jlhh
# Source directory /usr/home/lohse
#
# existing files WILL be overwritten
#
# This shar contains:
# length  mode       name
# ------ ---------- ------------------------------------------
#    758 -rw-r--r-- shared-libraries/shlib.h
#    283 -rwxr-xr-x shared-libraries/libX11/mkshlib
#    407 -rw-r--r-- shared-libraries/libX11/sharedlibs.c
#    590 -rw-r--r-- shared-libraries/libX11/Makefile
#   4152 -rw-r--r-- shared-libraries/README
#    770 -rw-r--r-- shared-libraries/libc/Makefile
#   5789 -rw-r--r-- shared-libraries/libc/crt0_s.c
#    342 -rw-r--r-- shared-libraries/libc/sharedlibs.c
#     45 -rw-r--r-- shared-libraries/libc/environ.c
#    264 -rwxr-xr-x shared-libraries/libc/mkshlib
#   2812 -rw-r--r-- shared-libraries/mkshlib.inc
#  13819 -rw-r--r-- shared-libraries/convert.c
#    845 -rw-r--r-- shared-libraries/Makefile
#    372 -rw-r--r-- shared-libraries/patches/g++/Makefile
#   2336 -rw-r--r-- shared-libraries/patches/g++/g++.c.diff
#    443 -rw-r--r-- shared-libraries/patches/cc/Makefile
#    917 -rw-r--r-- shared-libraries/patches/cc/cc.c.diff
#
if touch 2>&1 | fgrep 'amc' > /dev/null
 then TOUCH=touch
 else TOUCH=true
fi
# ============= shared-libraries/shlib.h ==============
if test ! -d 'shared-libraries'; then
    echo "x - creating directory shared-libraries"
    mkdir 'shared-libraries'
fi
echo "x - extracting shared-libraries/shlib.h (Text)"
sed 's/^X//' << 'SHAR_EOF' > shared-libraries/shlib.h &&
X#include <sys/types.h>           /* for caddr_t */
X
X#define PAGESIZE      4096	 /* same value as returned by getpagesize() */
X#define SHLIB_MAGIC   0x6772944a /* magic number of sharable library        */
X
Xunion _ShareLibHeader {
X	struct {
X	    unsigned long magic;	/* must be SHLIB_MAGIC   */
X	    unsigned long version;	/* current version       */
X	    unsigned long text_size;    /* multiple of PAGESIZE  */
X	    unsigned long data_size;    /* multiple of PAGESIZE  */
X	    caddr_t       text_addr;    /* PAGESIZE aligned      */
X	    caddr_t       data_addr;    /* PAGESIZE aligned      */
X	} header;
X	unsigned char array[PAGESIZE];
X};
X
Xtypedef union _ShareLibHeader ShareLibHeader;
X
Xstruct SharedLibraryTable {
X				const char *name;
X				int version;
X};
SHAR_EOF
$TOUCH -am 1107193292 shared-libraries/shlib.h &&
chmod 0644 shared-libraries/shlib.h ||
echo "restore of shared-libraries/shlib.h failed"
set `wc -c shared-libraries/shlib.h`;Wc_c=$1
if test "$Wc_c" != "758"; then
	echo original size 758, current size $Wc_c
fi
# ============= shared-libraries/libX11/mkshlib ==============
if test ! -d 'shared-libraries/libX11'; then
    echo "x - creating directory shared-libraries/libX11"
    mkdir 'shared-libraries/libX11'
fi
echo "x - extracting shared-libraries/libX11/mkshlib (Text)"
sed 's/^X//' << 'SHAR_EOF' > shared-libraries/libX11/mkshlib &&
X#!/bin/sh
X#
XLIBRARY="/usr/lib/libX11.a"
XSHLIB="libX11_s"
XSHLIB_A="libX11_s.a"
X#
X# additional modules
XADDMODS=
X#
X# additional shared libraries
XLIBS="`pwd`/../libc/libc_s.a"
X#
X# version and addresses
XVERSION=1
XTEXT_ADDR="80030000"
XDATA_ADDR="8006f000"
X#
XPATH=..:$PATH
X. ../mkshlib.inc
SHAR_EOF
$TOUCH -am 1126003792 shared-libraries/libX11/mkshlib &&
chmod 0755 shared-libraries/libX11/mkshlib ||
echo "restore of shared-libraries/libX11/mkshlib failed"
set `wc -c shared-libraries/libX11/mkshlib`;Wc_c=$1
if test "$Wc_c" != "283"; then
	echo original size 283, current size $Wc_c
fi
# ============= shared-libraries/libX11/sharedlibs.c ==============
echo "x - extracting shared-libraries/libX11/sharedlibs.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > shared-libraries/libX11/sharedlibs.c &&
X#include <sys/types.h>
X#include "shlib.h"
X
X#define NULL (void*)0
X
Xstruct SharedLibraryTable
X  _shared_library_table[] = {
X              /* filename      , version */
X              /* ========      , ======= */
X	      { "/shlib/libX11_s", 1     },	/* libX11                */
X	      { "/shlib/libc_s", 1       },	/* libc, always last one */
X	      { NULL           , 0       }	/* end of libraries      */
X};
SHAR_EOF
$TOUCH -am 1124222392 shared-libraries/libX11/sharedlibs.c &&
chmod 0644 shared-libraries/libX11/sharedlibs.c ||
echo "restore of shared-libraries/libX11/sharedlibs.c failed"
set `wc -c shared-libraries/libX11/sharedlibs.c`;Wc_c=$1
if test "$Wc_c" != "407"; then
	echo original size 407, current size $Wc_c
fi
# ============= shared-libraries/libX11/Makefile ==============
echo "x - extracting shared-libraries/libX11/Makefile (Text)"
sed 's/^X//' << 'SHAR_EOF' > shared-libraries/libX11/Makefile &&
XCFLAGS =-O -I..
XLDFLAGS=-s
XOBJECTS=sharedlibs.o
XSHLIBS =libX11_s libX11_s.a
XOLDLIB =/usr/lib/libX11.a
XHEADER =../shlib.h
X
Xall:	libX11_s
X
Xsharedlibs.o:	sharedlibs.c $(HEADER)
X	$(CC) $(CFLAGS) -c sharedlibs.c
X
X$(SHLIBS): $(OLDLIB) ../convert $(OBJECTS) mkshlib
X	./mkshlib
X
Xclean:
X	rm -f $(OBJECTS) $(SHLIBS) a.out core core.* *~
X
Xinstall:	$(SHLIBS)
X	@if [ ! -d /shlib ]; then\
X	   mkdir /shlib; chmod 755 /shlib; chown root:wheel /shlib; fi
X	install -m 444 -o root -g wheel libX11_s /shlib
X	install -m 444 -o root -g wheel libX11_s.a /usr/lib
X
X../convert:	../convert.c
X	(cd ..; make convert)
SHAR_EOF
$TOUCH -am 1126003192 shared-libraries/libX11/Makefile &&
chmod 0644 shared-libraries/libX11/Makefile ||
echo "restore of shared-libraries/libX11/Makefile failed"
set `wc -c shared-libraries/libX11/Makefile`;Wc_c=$1
if test "$Wc_c" != "590"; then
	echo original size 590, current size $Wc_c
fi
# ============= shared-libraries/README ==============
echo "x - extracting shared-libraries/README (Text)"
sed 's/^X//' << 'SHAR_EOF' > shared-libraries/README &&
XThis is an experimental implementation of shared libraries for 386BSD. This
Ximplementation has the following properties:
X
X - No kernel extension is necessary. Just the shared libraries need to be
X   installed in order to run programs using them.
X
X - The shared libraries follow the approach used in System V: Shared libraries
X   are linked to fixed addresses and mapped in the address space at this
X   fixed address.
X   There are no symbols resolved at load-time as in AIX 3.x and SunOS.
X
X - This package includes makefiles and programs that create shared version of
X   the C and X11 libraries and an extended version of the startup file crt0.o
X
X - It also includes patches for the cc and g++ commands in order to link to
X   the shared version of the libc unless started with "-static". The shared
X   version of the libX11 must be explicitly specified as "-lX11_s".
X
X
XThe package is installed like this:
X===================================
X
X   log-in as root and type
X
X	make
X	make install
X	make patch
X
XThe first make creates the shared libraries. The second make creates the direc-
Xtory /shlib and copies the shared libraries in there. It also installs the
Xfiles crt0_s.o, libc_s.a, and libX11_s.a in directory /usr/lib. The third make
Xpatches, recompiles and installs the commands cc and g++. It assumes the source
Xcode for cc and g++ installed in /usr/src/usr.bin/.
X
XIf you don't have X11 installed, you might want to remove "libX11" from the
Xtop-level makefile before starting the installation.
X
X
XDeinstalling the package
X========================
X
XIn order to get rid of this shared library package, log-in as root and type
X
Xeither
X	make deinstall
Xto switch back the the old cc and g++ programs that link statically
X
Xor
X	make remove
Xto switch back as above and to remove the files in /usr/lib needed for linking
Xto shared libraries
X
Xor
X	make remove-all
Xto do all the above and to remove all shared libraries. After make remove-all,
Xall programs linked to shared libraries won't run anymore.
X
X
XLinking to Shared Libraries
X===========================
X
XThe main requirement to keep in mind when using shared libraries is that all
Xreferences in shared libraries must be resolved within the same or another
Xshared library.
X
XPrograms that undump their data segment, notably GNU emacs and MIT scheme, don't
Xrun when linked with shared libraries.
X
X
XCreating a Shared Library
X=========================
X
XA shared library can be created by making a directory, adding the directory
Xname to the top-level makefile and setting up the files
X  Makefile
X  mkshlib
X  sharedlibs.c
Xin the directory.
X
XThere are some topics to decide upon:
X - text and data segment address
X - existing shared libraries used by the new shared library
X - version number of shared library
X
XBoth existing libraries, libc and libX11, can be consulted as examples for
Xthese topics.
X
X
XTODO
X====
X
XA few extensions are highly desirable. The main limitation of the current
Xappoach is that after any change to some functions in a library its sharable
Xlibrary is very likely to differ in some of its exported addresses. Therefore,
Xeither the old shared library has to stay around or all programs using it need
Xto be relinked.
X
XThere are some extensions that make the addresses exported by a shared library
Xless dependent on the library's internals:
X
X - Use a branch table for all globally accessible functions included in the
X   library. The addresses of the branches are exported. They don't change when
X   any function changes size.
X
X - Don't export all symbols, accept a list of symbols to export. Most symbols
X   in the data segment don't need to be exported.
X
XAnyway, it's working as is. Maybe there's any volounteer willing to do the
Xextensions.
X
XEnjoy,
X Joerg
X
X-------------------------------------------------------------------------------
XDr. Joerg Lohse                           lohse@tech7.informatik.uni-hamburg.de
XFachbereich Informatik
XUniversitaet Hamburg                      I'm joining Siemens Corporate Research
XTroplowitzstr. 7                          in Munich on December 1st. Don't know
XD-2000 Hamburg 54                         the new internet address yet, sorry.
XGermany
SHAR_EOF
$TOUCH -am 1126184292 shared-libraries/README &&
chmod 0644 shared-libraries/README ||
echo "restore of shared-libraries/README failed"
set `wc -c shared-libraries/README`;Wc_c=$1
if test "$Wc_c" != "4152"; then
	echo original size 4152, current size $Wc_c
fi
# ============= shared-libraries/libc/Makefile ==============
if test ! -d 'shared-libraries/libc'; then
    echo "x - creating directory shared-libraries/libc"
    mkdir 'shared-libraries/libc'
fi
echo "x - extracting shared-libraries/libc/Makefile (Text)"
sed 's/^X//' << 'SHAR_EOF' > shared-libraries/libc/Makefile &&
XCFLAGS =-O -I..
XLDFLAGS=-s
XOBJECTS=sharedlibs.o environ.o
XSHLIBS =libc_s libc_s.a
XOLDLIB =/usr/lib/libc.a
XHEADER =../shlib.h
X
Xall:	libc_s crt0_s.o
X
Xsharedlibs.o:	sharedlibs.c $(HEADER)
X	$(CC) $(CFLAGS) -c sharedlibs.c
X
Xenviron.o:	environ.c
X	$(CC) $(CFLAGS) -c environ.c
X
X$(SHLIBS): $(OLDLIB) ../convert $(OBJECTS) mkshlib
X	./mkshlib
X
Xcrt0_s.o:	../shlib.h
X	$(CC) $(CFLAGS) -c crt0_s.c
X
Xclean:
X	rm -f $(OBJECTS) $(SHLIBS) crt0_s.o a.out core core.* *~
X
Xinstall:	$(SHLIBS) crt0_s.o
X	@if [ ! -d /shlib ]; then\
X	    mkdir /shlib; chmod 755 /shlib; chown root:wheel /shlib; fi
X	install -m 444 -o root -g wheel libc_s /shlib
X	install -m 444 -o root -g wheel crt0_s.o /usr/lib
X	install -m 444 -o root -g wheel libc_s.a /usr/lib
X
X../convert:	../convert.c
X	(cd ..; make convert)
SHAR_EOF
$TOUCH -am 1126003192 shared-libraries/libc/Makefile &&
chmod 0644 shared-libraries/libc/Makefile ||
echo "restore of shared-libraries/libc/Makefile failed"
set `wc -c shared-libraries/libc/Makefile`;Wc_c=$1
if test "$Wc_c" != "770"; then
	echo original size 770, current size $Wc_c
fi
# ============= shared-libraries/libc/crt0_s.c ==============
echo "x - extracting shared-libraries/libc/crt0_s.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > shared-libraries/libc/crt0_s.c &&
X/*-
X * Copyright (c) 1990 The Regents of the University of California.
X * All rights reserved.
X *
X * Redistribution and use in source and binary forms, with or without
X * modification, are permitted provided that the following conditions
X * are met:
X * 1. Redistributions of source code must retain the above copyright
X *    notice, this list of conditions and the following disclaimer.
X * 2. Redistributions in binary form must reproduce the above copyright
X *    notice, this list of conditions and the following disclaimer in the
X *    documentation and/or other materials provided with the distribution.
X * 3. All advertising materials mentioning features or use of this software
X *    must display the following acknowledgement:
X *	This product includes software developed by the University of
X *	California, Berkeley and its contributors.
X * 4. Neither the name of the University nor the names of its contributors
X *    may be used to endorse or promote products derived from this software
X *    without specific prior written permission.
X *
X * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
X * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
X * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
X * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
X * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
X * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
X * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
X * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
X * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
X * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
X * SUCH DAMAGE.
X */
X
X#if defined(LIBC_SCCS) && !defined(lint)
Xstatic char sccsid[] = "@(#)crt0.c	5.7 (Berkeley) 7/3/91";
X#endif /* LIBC_SCCS and not lint */
X
X/*
X *	C start up routine.
X *	Robert Henry, UCB, 20 Oct 81
X *
X *	We make the following (true) assumption:
X *	1) The only register variable that we can trust is the frame pointer,
X *	ebp, which points to the base of the kernel calling frame.
X */
X
Xextern	char	**environ;
Xextern	int	errno;
Xextern	int	end, *minbrk asm("minbrk"), *curbrk asm("curbrk");
X
Xasm(".text");
Xasm(".long 0xc000c000");
X
Xextern	unsigned char	etext;
Xextern	unsigned char	eprol asm ("eprol");
Xextern			start() asm("start");
Xextern			mcount() asm ("mcount");
X
Xstatic void _load_sharable_libraries(const char *);
X
Xstart()
X{
X	struct kframe {
X		int	kargc;
X		char	*kargv[1];	/* size depends on kargc */
X		char	kargstr[1];	/* size varies */
X		char	kenvstr[1];	/* size varies */
X	};
X	/*
X	 *	ALL REGISTER VARIABLES!!!
X	 */
X	register struct kframe *kfp;
X	register char **targv;
X	register char **argv;
X	extern void _mcleanup();
X
X	/* just above the saved frame pointer */
X	asm ("lea 4(%%ebp), %0" : "=r" (kfp) );
X	for (argv = targv = &kfp->kargv[0]; *targv++; /* void */)
X		/* void */ ;
X	if (targv >= (char **)(*argv))
X		--targv;
X
X	_load_sharable_libraries(*argv);
X	environ = targv;
X	minbrk = curbrk = &end;
X
Xasm("eprol:");
X	exit(main(kfp->kargc, argv, environ));
X}
X
X/*
X * null mcount and moncontrol,
X * just in case some routine is compiled for profiling
X */
Xmoncontrol(val)
X	int val;
X{
X
X}
X
Xmcount(void) { }
X
X/*****************************************************************************/
X/*****************************************************************************/
X/*****************************************************************************/
X
X#include <sys/types.h>
X#include <sys/mman.h>
X#include <sys/file.h>
X#include "shlib.h"
X
Xstatic const char *progname;
X
Xextern struct SharedLibraryTable _shared_library_table[];
X
Xasm(".text");
Xasm("__exit: ; lea 1, %eax ; .byte 0x9a ; .long 0; .word 7; ret");
Xasm("2: movl $-1,%eax; ret");
Xasm("_read: ; lea 3,%eax; .byte 0x9a ; .long 0; .word 7; jb 2b; ret");
Xasm("_write: ; lea 4,%eax; .byte 0x9a ; .long 0; .word 7; jb 2b; ret");
Xasm("_open: ; lea 5,%eax; .byte 0x9a ; .long 0; .word 7; jb 2b; ret");
Xasm("_close: ; lea 6,%eax; .byte 0x9a ; .long 0; .word 7; jb 2b; ret");
Xasm("_mmap: ; lea 71,%eax; .byte 0x9a ; .long 0; .word 7; jb 2b; ret");
X
Xstatic void print_string(const char *message) {
X   const char *p = message;
X   int len = 0;
X
X   while (*p++) len++;
X   write(2, message, len);
X}
X
Xstatic void print_message_and_abort(const char *msg, const char *library) {
X
X   print_string(progname);
X   print_string("[");
X   print_string(library);
X   print_string("]: ");
X   print_string(msg);
X   print_string(" Aborted.\n");
X   _exit(1);
X}
X
Xvoid _load_sharable_libraries(const char *program_name) {
X   struct SharedLibraryTable *p = _shared_library_table;
X
X   progname = program_name;
X   for (; p->name; p += 1) {
X      int            fd = open(p->name, O_RDONLY);
X      ShareLibHeader share;
X
X      if (fd < 0 || read(fd, &share, sizeof share) != sizeof share)
X        print_message_and_abort("Can't open shared library.", p->name);
X
X      if (share.header.magic != SHLIB_MAGIC)
X        print_message_and_abort("Not a shared library.", p->name);
X
X      if (share.header.version != p->version)
X        print_message_and_abort("Version mismatch of shared library.", p->name);
X
X      if (mmap(share.header.text_addr, share.header.text_size,
X	       PROT_READ | PROT_EXEC, MAP_FILE | MAP_FIXED, fd,
X	       sizeof share) != share.header.text_addr)
X          print_message_and_abort("Can't map text segment.", p->name);
X
X      if (mmap(share.header.data_addr, share.header.data_size,
X	       PROT_READ | PROT_WRITE, MAP_FILE | MAP_FIXED | MAP_PRIVATE, fd,
X	       share.header.text_size + sizeof share) != share.header.data_addr)
X          print_message_and_abort("Can't map data segment.", p->name);
X
X      close(fd);
X   }
X}
SHAR_EOF
$TOUCH -am 1122232492 shared-libraries/libc/crt0_s.c &&
chmod 0644 shared-libraries/libc/crt0_s.c ||
echo "restore of shared-libraries/libc/crt0_s.c failed"
set `wc -c shared-libraries/libc/crt0_s.c`;Wc_c=$1
if test "$Wc_c" != "5789"; then
	echo original size 5789, current size $Wc_c
fi
# ============= shared-libraries/libc/sharedlibs.c ==============
echo "x - extracting shared-libraries/libc/sharedlibs.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > shared-libraries/libc/sharedlibs.c &&
X#include <sys/types.h>
X#include "shlib.h"
X
X#define NULL (void*)0
X
Xstruct SharedLibraryTable
X  _shared_library_table[] = {
X              /* filename      , version */
X              /* ========      , ======= */
X	      { "/shlib/libc_s", 1       },	/* libc, always last one */
X	      { NULL           , 0       }	/* end of libraries      */
X};
SHAR_EOF
$TOUCH -am 1107202992 shared-libraries/libc/sharedlibs.c &&
chmod 0644 shared-libraries/libc/sharedlibs.c ||
echo "restore of shared-libraries/libc/sharedlibs.c failed"
set `wc -c shared-libraries/libc/sharedlibs.c`;Wc_c=$1
if test "$Wc_c" != "342"; then
	echo original size 342, current size $Wc_c
fi
# ============= shared-libraries/libc/environ.c ==============
echo "x - extracting shared-libraries/libc/environ.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > shared-libraries/libc/environ.c &&
Xchar **environ = (char **)0;
Xint  errno = 0;
SHAR_EOF
$TOUCH -am 1105201592 shared-libraries/libc/environ.c &&
chmod 0644 shared-libraries/libc/environ.c ||
echo "restore of shared-libraries/libc/environ.c failed"
set `wc -c shared-libraries/libc/environ.c`;Wc_c=$1
if test "$Wc_c" != "45"; then
	echo original size 45, current size $Wc_c
fi
# ============= shared-libraries/libc/mkshlib ==============
echo "x - extracting shared-libraries/libc/mkshlib (Text)"
sed 's/^X//' << 'SHAR_EOF' > shared-libraries/libc/mkshlib &&
X#!/bin/sh
X#
XLIBRARY="/usr/lib/libc.a"
XSHLIB="libc_s"
XSHLIB_A="libc_s.a"
X#
X# additional modules
XADDMODS="environ.o"
X#
X# additional shared libraries
XLIBS=
X#
X# version and addresses
XVERSION=1
XTEXT_ADDR="80000000"
XDATA_ADDR="80020000"
X#
XPATH=..:$PATH
X. ../mkshlib.inc
SHAR_EOF
$TOUCH -am 1124221992 shared-libraries/libc/mkshlib &&
chmod 0755 shared-libraries/libc/mkshlib ||
echo "restore of shared-libraries/libc/mkshlib failed"
set `wc -c shared-libraries/libc/mkshlib`;Wc_c=$1
if test "$Wc_c" != "264"; then
	echo original size 264, current size $Wc_c
fi
# ============= shared-libraries/mkshlib.inc ==============
echo "x - extracting shared-libraries/mkshlib.inc (Text)"
sed 's/^X//' << 'SHAR_EOF' > shared-libraries/mkshlib.inc &&
X#!/bin/sh
X#*-
X#* Copyright (c) 1990 The Regents of the University of California.
X#* All rights reserved.
X#*
X#* Redistribution and use in source and binary forms, with or without
X#* modification, are permitted provided that the following conditions
X#* are met:
X#* 1. Redistributions of source code must retain the above copyright
X#*    notice, this list of conditions and the following disclaimer.
X#* 2. Redistributions in binary form must reproduce the above copyright
X#*    notice, this list of conditions and the following disclaimer in the
X#*    documentation and/or other materials provided with the distribution.
X#* 3. All advertising materials mentioning features or use of this software
X#*    must display the following acknowledgement:
X#*	This product includes software developed by the University of
X#*	California, Berkeley and its contributors.
X#* 4. Neither the name of the University nor the names of its contributors
X#*    may be used to endorse or promote products derived from this software
X#*    without specific prior written permission.
X#*
X#* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
X#* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
X#* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
X#* ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
X#* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
X#* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
X#* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
X#* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
X#* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
X#* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
X#* SUCH DAMAGE.
X#*/
X#
X#
XSHLIB_TABLE="sharedlibs.o"
XDIRECTORY=/tmp/$$
XTMPLIB="temp.o"
X#
X# create temporary directory
X#
Xif [ -d $DIRECTORY ]
Xthen
X  echo "Deleting files in temporary directory $DIRECTORY ..."
X  rm -f $DIRECTORY/*
Xelse
X  echo "Creating new temporary directory $DIRECTORY ..."
X  mkdir $DIRECTORY
Xfi
X#
X# extract library modules
X#
Xecho "Extracting library $LIBRARY ..."
X#
XDIR=`pwd`
X#
Xif [ -n "$ADDMODS" ]
Xthen
X  cp -p $ADDMODS $DIRECTORY
Xfi
X#
Xcd $DIRECTORY
XMODULES=`ar xv $LIBRARY | grep -v __.SYMDEF | cut -f3 -d\ `
X#
X# link sharable library at given absolute addresses
X#
Xecho "Linking absolute module $TMPLIB ..."
Xld -o $DIR/$TMPLIB -S -T $TEXT_ADDR -Tdata $DATA_ADDR $ADDMODS $MODULES $LIBS
X#
Xcd $DIR
Xecho "Converting $TMPLIB to $SHLIB and $SHLIB_A ..."
Xconvert $TMPLIB $SHLIB $SHLIB_A $DIRECTORY $VERSION 0x$TEXT_ADDR 0x$DATA_ADDR
X#
Xecho "Cleaning up ..."
Xrm -rf $DIRECTORY $TMPLIB
X#
Xecho "Finishing $SHLIB_A ..."
Xar r $SHLIB_A $SHLIB_TABLE
Xranlib $SHLIB_A
X#
Xecho "... done."
Xexit 0
SHAR_EOF
$TOUCH -am 1124234592 shared-libraries/mkshlib.inc &&
chmod 0644 shared-libraries/mkshlib.inc ||
echo "restore of shared-libraries/mkshlib.inc failed"
set `wc -c shared-libraries/mkshlib.inc`;Wc_c=$1
if test "$Wc_c" != "2812"; then
	echo original size 2812, current size $Wc_c
fi
# ============= shared-libraries/convert.c ==============
echo "x - extracting shared-libraries/convert.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > shared-libraries/convert.c &&
X/*-
X * Copyright (c) 1990 The Regents of the University of California.
X * All rights reserved.
X *
X * Redistribution and use in source and binary forms, with or without
X * modification, are permitted provided that the following conditions
X * are met:
X * 1. Redistributions of source code must retain the above copyright
X *    notice, this list of conditions and the following disclaimer.
X * 2. Redistributions in binary form must reproduce the above copyright
X *    notice, this list of conditions and the following disclaimer in the
X *    documentation and/or other materials provided with the distribution.
X * 3. All advertising materials mentioning features or use of this software
X *    must display the following acknowledgement:
X *	This product includes software developed by the University of
X *	California, Berkeley and its contributors.
X * 4. Neither the name of the University nor the names of its contributors
X *    may be used to endorse or promote products derived from this software
X *    without specific prior written permission.
X *
X * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
X * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
X * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
X * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
X * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
X * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
X * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
X * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
X * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
X * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
X * SUCH DAMAGE.
X */
X
X#include <stdio.h>
X#include <errno.h>
X#include <a.out.h>
X#include <unistd.h>
X#include <stdlib.h>
X#include <ar.h>
X#include <string.h>
X#include "shlib.h"
X
X#define MAX_FILENAME 1024
X#define PAGE_ALIGN(x) ((((x) + PAGESIZE - 1) / PAGESIZE) * PAGESIZE)
X
Xstatic FILE *in;
Xstatic struct exec in_header;
X
Xstatic const char *program_name;
X
X/* command line arguments */
X
Xstatic const char *input_module,
X                  *shared_library,
X                  *linker_library,
X                  *module_directory;
X
Xstatic int        version;
X
Xstatic caddr_t    text_address,
X                  data_address;
X
X/*****************************************************************************/
X/**************************** Error Messages *********************************/
X/*****************************************************************************/
X
Xstatic void out_of_memory(void) {
X   fprintf(stderr, "%s: ", program_name);
X   perror("Out of memory");
X   exit (errno);
X}
X
Xstatic void open_error(const char *name) {
X   char message[MAX_FILENAME];
X
X   fprintf(stderr, "%s: ", program_name);
X   sprintf(message, "Can't open file \"%s\"", name);
X   perror(message);
X   exit(errno);
X}
X
Xstatic void create_error(const char *name) {
X   char message[MAX_FILENAME];
X
X   sprintf(message, "Can't create file \"%s\"", name);
X   fprintf(stderr, "%s: ", program_name);
X   perror(message);
X   exit(errno);
X}
X
Xstatic void read_error(void) {
X   fprintf(stderr, "%s: ", program_name);
X   perror("Read error");
X   exit (errno);
X}
X
Xstatic void write_error(void) {
X   fprintf(stderr, "%s: ", program_name);
X   perror("Write error");
X   exit (errno);
X}
X
Xstatic void usage(void) {
X   fprintf(stderr, "usage: %s input-module shared-library link-library "
X	           "module-directory\\\n\t\tversion text-address "
X	           "data-address\n"
X	   "input-module, shared-library, link-library: file names\n"
X	   "module-directory: directory names\n"
X	   "version, text-address, data-address: numbers (use 0x for hex)\n",
X	   program_name);
X   exit (1);
X}
X
X
X/*****************************************************************************/
X/**************************** Initialization *********************************/
X/*****************************************************************************/
X
Xstatic void initialize(void) {
X
X   if (getpagesize() != PAGESIZE) {
X      fprintf(stderr, "%s: Internal error: please adjust constant PAGESIZE. "
X	      "Aborted.\n", program_name);
X      exit(1);
X   }
X
X   printf("Loading absolutely linked `%s' ...\n", input_module);
X
X   if (!(in = fopen(input_module, "r"))) open_error(input_module);
X
X   if (fread(&in_header, sizeof in_header, 1, in) != 1) read_error();
X
X   if (N_BADMAG(in_header)) {
X      fprintf(stderr, "%s: Not an executable file. Aborted.\n", program_name);
X      exit(1);
X   }
X
X   if (in_header.a_trsize || in_header.a_drsize) {
X      fprintf(stderr, "%s: File contains relocation information. Aborted.\n",
X	      program_name);
X      exit(1);
X   }
X
X   if ((caddr_t) in_header.a_entry != text_address) {
X      fprintf(stderr, "%s: Text address mismatch. 0x%8.8x vs 0x%8.8x.\n",
X	      program_name, in_header.a_text, text_address);
X      exit(1);
X   }
X}
X
X/*****************************************************************************/
X/**************************** Shared Library *********************************/
X/*****************************************************************************/
X
Xvoid create_shared_library(void) {
X   ShareLibHeader shlib;
X   FILE *out;
X   int  i;
X
X   /* create shared library */
X
X   printf("Creating shared library `%s' ...\n", shared_library);
X
X   if (!(out = fopen(shared_library, "w"))) create_error(shared_library);
X   
X   /* write header */
X
X   bzero(&shlib, sizeof shlib);
X   shlib.header.magic = SHLIB_MAGIC;
X   shlib.header.version = version;
X   shlib.header.text_size = PAGE_ALIGN(in_header.a_text);
X   shlib.header.data_size = PAGE_ALIGN(in_header.a_data + in_header.a_bss);
X   shlib.header.text_addr = text_address;
X   shlib.header.data_addr = data_address;
X   if (fwrite(&shlib, sizeof shlib, 1, out) != 1) write_error();
X
X   printf("%s: text %8.8x-%8.8x, data %8.8x-%8.8x\n", shared_library,
X	  text_address, text_address + shlib.header.text_size - 1,
X	  data_address, data_address + shlib.header.data_size - 1);
X
X   /* write text */
X
X   fseek(in, N_TXTOFF(in_header), SEEK_SET);
X   for (i = in_header.a_text; i--;) fputc(fgetc(in), out);
X   for (i = shlib.header.text_size - in_header.a_text; i--;) putc(0, out);
X
X   /* write data */
X
X   fseek(in, N_DATOFF(in_header), SEEK_SET);
X   for (i = in_header.a_data; i--;) fputc(fgetc(in), out);
X   for (i = shlib.header.data_size - in_header.a_data; i--;) putc(0, out);
X
X   fclose(out);
X}
X
X/*****************************************************************************/
X/************************* Copy Member to Library ****************************/
X/*****************************************************************************/
X
Xstatic int write_object_file(const char *full_name,
X			     int absolute_symbols,
X			     struct nlist *absolute_symtab,
X			     FILE *library) {
X   int offset = ftell(library);
X   FILE *object;
X   struct exec header;
X   int symbols, string_size, new_string_size, i;
X   struct nlist *symtab;
X   char *strings, *new_strings;
X
X   if (!(object = fopen(full_name, "r"))) open_error(full_name);
X
X   if (fread(&header, sizeof header, 1, object) != 1) read_error();
X
X   if (N_BADMAG(header)) {
X      fprintf(stderr, "%s: Not an executable file. Aborted.\n", program_name);
X      exit(1);
X   }
X
X   /* load symbol table */
X
X   if (!(symtab = malloc(header.a_syms))) out_of_memory();
X   symbols = header.a_syms / sizeof (struct nlist);
X   if (fseek(object, N_SYMOFF(header), SEEK_SET)) read_error();
X   if (fread(symtab, sizeof (struct nlist), symbols, object) != symbols)
X      read_error();
X
X   /* load string table */
X
X   if (fseek(object, 0, SEEK_END)) read_error();
X   i = ftell(object);
X   if (fseek(object, N_STROFF(header), SEEK_SET)) read_error();
X   string_size = i - ftell(object);
X   strings = malloc(string_size);
X   new_strings = malloc(string_size);
X   if (!strings || !new_strings) out_of_memory();
X   if (fread(strings, 1, string_size, object) != string_size) read_error();
X   fclose(object);
X
X   /* make references absolute, add library object */
X
X   header.a_text = header.a_data = header.a_bss = header.a_syms = 0;
X   header.a_entry = header.a_trsize = header.a_drsize = 0;
X   if (fwrite(&header, sizeof header, 1, library) != 1) write_error();
X
X   new_string_size = sizeof (long);
X   if (fseek(library, offset + N_SYMOFF(header), SEEK_SET)) read_error();
X   for (i = 0; i < symbols; ++i) {
X      struct nlist *p = symtab + i;
X      if (p->n_type & N_EXT) {
X	 int type = p->n_type & N_TYPE;
X
X	 if (type == N_TEXT || type == N_DATA || type == N_BSS ||
X	     type == N_COMM || type == N_ABS) {
X	    char *name = strings + p->n_un.n_strx;
X	    char *s = new_strings + new_string_size;
X	    int  i;
X
X	    /* lookup symbol in absolute table */
X	    for (i = 0; i < absolute_symbols; ++i) {
X	       struct nlist *q = absolute_symtab + i;
X
X	       if (!strcmp(q->n_un.n_name, name)) {
X		  p->n_value = q->n_value;
X		  p->n_type = N_ABS | N_EXT;
X		  break;
X	       }
X	    }
X
X	    /* copy string in new string table */
X	    p->n_un.n_strx = new_string_size;
X	    new_string_size += strlen(name) + 1;
X	    while (*s++ = *name++);
X
X	    /* write symbol */
X	    if (fwrite(p, sizeof (struct nlist), 1, library) != 1)
X	       write_error();
X
X	    header.a_syms += sizeof (struct nlist);
X	 }
X      }
X   }
X
X   /* write new string table */
X   *((long *) new_strings) = new_string_size;
X   if (fseek(library, offset + N_STROFF(header), SEEK_SET)) read_error();
X   if (fwrite(new_strings, 1, new_string_size, library) != new_string_size)
X      write_error();
X
X   /* update header */
X   if (fseek(library, offset, SEEK_SET)) read_error();
X   if (fwrite(&header, sizeof header, 1, library) != 1) write_error();
X
X   free(symtab);
X   free(strings);
X   free(new_strings);
X
X   return N_STROFF(header) + new_string_size;
X}
X
Xstatic void copy_string(char *target, const char *source, int size) {
X   while (size--) *target++ = *source ? *source++ : ' ';
X}
X
Xstatic void copy_number(char *target, int src, int size) {
X   char source[15];
X
X   sprintf(source, "%d", src);
X   copy_string(target, source, size);
X}
X
X/*****************************************************************************/
X/**************** Library with References to Shared Library ******************/
X/*****************************************************************************/
X
Xstatic void write_linker_library(void) {
X   int          symbols, string_size, i;
X   struct nlist *symtab;
X   char         *strings;
X   FILE         *library;
X
X   /* load symbol table */
X
X   if (!(symtab = malloc(in_header.a_syms))) out_of_memory();
X   symbols = in_header.a_syms / sizeof (struct nlist);
X   if (fseek(in, N_SYMOFF(in_header), SEEK_SET)) read_error();
X   if (fread(symtab, sizeof (struct nlist), symbols, in) != symbols)
X      read_error();
X
X   /* load string table */
X
X   if (fseek(in, 0, SEEK_END)) read_error();
X   i = ftell(in);
X   if (fseek(in, N_STROFF(in_header), SEEK_SET)) read_error();
X   string_size = i - ftell(in);
X   strings = malloc(string_size);
X   if (!strings) out_of_memory();
X   if (fread(strings, 1, string_size, in) != string_size) read_error();
X
X   /* change strings to memory references */
X
X   for (i = 0; i < symbols; ++i) {
X      struct nlist *p = symtab + i;
X
X      p->n_un.n_name = strings + p->n_un.n_strx;
X   }
X
X   /* create archive file */
X
X   printf("Creating references to shared library `%s' ...\n", linker_library);
X
X   library = fopen(linker_library, "w");
X   if (!library) create_error(linker_library);
X
X   if (fwrite(ARMAG, 1, SARMAG, library) != SARMAG) write_error();
X
X   /* process all object files */
X
X   for (i = 0; i < symbols; ++i) {
X      struct nlist *p = symtab + i;
X
X      if ((p->n_type & N_TYPE) == N_FN) {
X	 char full_name[1024];
X
X	 sprintf(full_name, "%s/%s", module_directory, p->n_un.n_name);
X	 if (!access(full_name, R_OK)) {
X	    struct ar_hdr hdr;
X	    int size, start = ftell(library);
X
X	    copy_string(hdr.ar_name, p->n_un.n_name, 16);
X	    copy_number(hdr.ar_date, time(NULL), 12);
X	    copy_number(hdr.ar_uid, getuid(), 6);
X	    copy_number(hdr.ar_gid, getgid(), 6);
X	    copy_string(hdr.ar_mode, "444", 8);
X	    copy_string(hdr.ar_size, " ", 10);
X	    copy_string(hdr.ar_fmag, ARFMAG, 2);
X	    if (fwrite(&hdr, sizeof hdr, 1, library) != 1) write_error();
X
X	    size = write_object_file(full_name, symbols, symtab, library);
X
X	    copy_number(hdr.ar_size, size, 10);
X	    if (fseek(library, start, SEEK_SET)) read_error();
X	    if (fwrite(&hdr, sizeof hdr, 1, library) != 1) write_error();
X
X	    if (fseek(library, start + sizeof hdr + size, SEEK_SET))
X	       read_error();
X
X	    if (size & 1) fputc('\n', library);
X	 }
X      }
X   }
X   fclose(library);
X   free(strings);
X   free(symtab);
X}
X
X/*****************************************************************************/
X/****************************** Main Program *********************************/
X/*****************************************************************************/
X
Xint main(int argc, char *argv[]) {
X   char *s;
X
X   for (program_name = s = *argv; *s;)
X      if (*s++ == '/') program_name = s;
X
X   if (argc != 8) usage();
X
X   input_module = argv[1];
X   shared_library = argv[2];
X   linker_library = argv[3];
X   module_directory = argv[4];
X
X   errno = 0;
X   version = strtol(argv[5], &s, 0);
X   if (errno || *s) usage();
X
X   text_address = (caddr_t) strtoul(argv[6], &s, 0);
X   if (errno || *s) usage();
X
X   data_address = (caddr_t) strtoul(argv[7], &s, 0);
X   if (errno || *s) usage();
X
X   /* open linker's output module (e.g. libc_s.o) */
X   initialize();
X
X   /* create shared library (e.g. libs_s) */
X   create_shared_library();
X
X   /* create library with references to shared library (e.g. libc_s.a) */
X   write_linker_library();
X
X   fclose(in);
X
X   return 0;
X}
SHAR_EOF
$TOUCH -am 1126010392 shared-libraries/convert.c &&
chmod 0644 shared-libraries/convert.c ||
echo "restore of shared-libraries/convert.c failed"
set `wc -c shared-libraries/convert.c`;Wc_c=$1
if test "$Wc_c" != "13819"; then
	echo original size 13819, current size $Wc_c
fi
# ============= shared-libraries/Makefile ==============
echo "x - extracting shared-libraries/Makefile (Text)"
sed 's/^X//' << 'SHAR_EOF' > shared-libraries/Makefile &&
XCFLAGS =-O
XLDFLAGS=-s
XLIBRARIES=libc libX11
X
Xshlibs: $(LIBRARIES) convert
X	@for lib in $(LIBRARIES) ; do (set -x; cd $$lib; make); done
X
Xconvert:	convert.c shlib.h
X	$(CC) $(CFLAGS) $(LDFLAGS) -o convert convert.c
X
Xinstall: $(LIBRARIES) convert
X	@for lib in $(LIBRARIES) ; do (set -x; cd $$lib; make install); done
X
Xpatch:	patches/cc/Makefile patches/g++/Makefile
X	cd patches/cc; make
X	cd patches/g++; make
X
Xdeinstall:
X	mv -f /usr/bin/cc.orig /usr/bin/cc
X	mv -f /usr/bin/g++.orig /usr/bin/g++
X	mv -f /usr/src/usr.bin/gcc/cc/cc.c.orig /usr/src/usr.bin/gcc/cc/cc.c
X	mv -f /usr/src/usr.bin/g++/g++/g++.c.orig /usr/src/usr.bin/g++/g++/g++.c
X
Xremove:	deinstall
X	rm -f /usr/lib/lib*_s.a /usr/lib/crt0_s.o
X
Xremove-all: remove
X	rm -rf /shlib
X
Xclean:
X	rm -f convert a.out core core.* *~
X	@for lib in $(LIBRARIES) ; do (set -x; cd $$lib; make clean); done
SHAR_EOF
$TOUCH -am 1127094292 shared-libraries/Makefile &&
chmod 0644 shared-libraries/Makefile ||
echo "restore of shared-libraries/Makefile failed"
set `wc -c shared-libraries/Makefile`;Wc_c=$1
if test "$Wc_c" != "845"; then
	echo original size 845, current size $Wc_c
fi
# ============= shared-libraries/patches/g++/Makefile ==============
if test ! -d 'shared-libraries/patches'; then
    echo "x - creating directory shared-libraries/patches"
    mkdir 'shared-libraries/patches'
fi
if test ! -d 'shared-libraries/patches/g++'; then
    echo "x - creating directory shared-libraries/patches/g++"
    mkdir 'shared-libraries/patches/g++'
fi
echo "x - extracting shared-libraries/patches/g++/Makefile (Text)"
sed 's/^X//' << 'SHAR_EOF' > shared-libraries/patches/g++/Makefile &&
Xall:	g++.c.diff
X	@here=`pwd`; cd /usr/src/usr.bin/g++/g++; patch g++.c < $$here/g++.c.diff
X	@echo "/usr/src/usr.bin/g++/g++.c patched."
X	@cd /usr/src/usr.bin/g++/g++; make g++;\
X		if [ ! -f /usr/bin/g++.orig ]; then\
X	 		 mv /usr/bin/g++ /usr/bin/g++.orig; fi;\
X		install -s -m 755 -o root -g wheel obj/g++ /usr/bin;\
X		echo "New /usr/bin/g++ installed. Old one renamed."
SHAR_EOF
$TOUCH -am 1126161292 shared-libraries/patches/g++/Makefile &&
chmod 0644 shared-libraries/patches/g++/Makefile ||
echo "restore of shared-libraries/patches/g++/Makefile failed"
set `wc -c shared-libraries/patches/g++/Makefile`;Wc_c=$1
if test "$Wc_c" != "372"; then
	echo original size 372, current size $Wc_c
fi
# ============= shared-libraries/patches/g++/g++.c.diff ==============
echo "x - extracting shared-libraries/patches/g++/g++.c.diff (Text)"
sed 's/^X//' << 'SHAR_EOF' > shared-libraries/patches/g++/g++.c.diff &&
X*** g++.c.orig	Wed May  8 20:27:23 1991
X--- g++.c	Thu Nov 26 16:37:16 1992
X***************
X*** 195,207 ****
X  
X  /* config.h can define LIB_SPEC to override the default libraries.  */
X  #ifndef LIB_SPEC
X! #define LIB_SPEC "%{!p:%{!pg:-lm -lc}}%{p:-lm_p -lc_p}%{pg:-lm_p -lc_p}"
X  #endif
X  
X  /* config.h can define STARTFILE_SPEC to override the default crt0 files.  */
X  #ifndef STARTFILE_SPEC
X  #define STARTFILE_SPEC  \
X!   "%{pg:gcrt0.o%s}%{!pg:%{p:mcrt0.o%s}%{!p:crt0.o%s}}"
X  #endif
X  
X  /* This spec is used for telling cpp whether char is signed or not.  */
X--- 195,207 ----
X  
X  /* config.h can define LIB_SPEC to override the default libraries.  */
X  #ifndef LIB_SPEC
X! #define LIB_SPEC "%{!p:%{!pg:%{!static:-lm -lc_s}%{static:-lm -lc}}}%{p:-lm_p -lc_p}%{pg:-lm_p -lc_p}"
X  #endif
X  
X  /* config.h can define STARTFILE_SPEC to override the default crt0 files.  */
X  #ifndef STARTFILE_SPEC
X  #define STARTFILE_SPEC  \
X!   "%{pg:gcrt0.o%s}%{!pg:%{p:mcrt0.o%s}%{!p:%{static:crt0.o%s}%{!static:crt0_s.o%s}}}"
X  #endif
X  
X  /* This spec is used for telling cpp whether char is signed or not.  */
X***************
X*** 321,333 ****
X  char *link_spec = "%{!c:%{!M*:%{!E:%{!S:ld -r -o %g.R %l\
X   %{A} %{d} %{e*} %{N} %{n} %{r} %{s} %{S} %{T*} %{t} %{u*} %{X} %{x} %{z}\
X   %{y*} %{!nostdlib:%S} \
X!  %{L*} %o %{!nostdlib:-lg++ %L -lgnulib}\n }}}}";
X  #else
X  /* Here is the spec for running the linker, after compiling all files.  */
X  char *link_spec = "%{!c:%{!M*:%{!E:%{!S:ld %{o*} %l\
X   %{A} %{d} %{e*} %{N} %{n} %{r} %{s} %{S} %{T*} %{t} %{u*} %{X} %{x} %{z}\
X   %{y*} %{!nostdlib:%S} \
X!  %{L*} %o %{!nostdlib:-lg++ %L -lgnulib}\n }}}}";
X  #endif
X  
X  /* Accumulate a command (program name and args), and run it.  */
X--- 321,333 ----
X  char *link_spec = "%{!c:%{!M*:%{!E:%{!S:ld -r -o %g.R %l\
X   %{A} %{d} %{e*} %{N} %{n} %{r} %{s} %{S} %{T*} %{t} %{u*} %{X} %{x} %{z}\
X   %{y*} %{!nostdlib:%S} \
X!  %{L*} %o %{!nostdlib:-lg++ -lgnulib %L}\n }}}}";
X  #else
X  /* Here is the spec for running the linker, after compiling all files.  */
X  char *link_spec = "%{!c:%{!M*:%{!E:%{!S:ld %{o*} %l\
X   %{A} %{d} %{e*} %{N} %{n} %{r} %{s} %{S} %{T*} %{t} %{u*} %{X} %{x} %{z}\
X   %{y*} %{!nostdlib:%S} \
X!  %{L*} %o %{!nostdlib:-lg++ -lgnulib %L}\n }}}}";
X  #endif
X  
X  /* Accumulate a command (program name and args), and run it.  */
SHAR_EOF
$TOUCH -am 1126164792 shared-libraries/patches/g++/g++.c.diff &&
chmod 0644 shared-libraries/patches/g++/g++.c.diff ||
echo "restore of shared-libraries/patches/g++/g++.c.diff failed"
set `wc -c shared-libraries/patches/g++/g++.c.diff`;Wc_c=$1
if test "$Wc_c" != "2336"; then
	echo original size 2336, current size $Wc_c
fi
# ============= shared-libraries/patches/cc/Makefile ==============
if test ! -d 'shared-libraries/patches/cc'; then
    echo "x - creating directory shared-libraries/patches/cc"
    mkdir 'shared-libraries/patches/cc'
fi
echo "x - extracting shared-libraries/patches/cc/Makefile (Text)"
sed 's/^X//' << 'SHAR_EOF' > shared-libraries/patches/cc/Makefile &&
Xall:	cc.c.diff
X	@here=`pwd`; cd /usr/src/usr.bin/gcc/cc; patch cc.c < $$here/cc.c.diff
X	@echo "/usr/src/usr.bin/gcc/cc/cc.c patched."
X	@cd /usr/src/usr.bin/gcc/cc; make cc;\
X		if [ ! -f /usr/bin/cc.orig ]; then\
X			 mv /usr/bin/cc /usr/bin/cc.orig; fi;\
X		install -s -m 755 -o root -g wheel obj/cc /usr/bin;\
X		rm -f obj/cc; make cc;\
X		install -s -m 755 -o root -g wheel obj/cc /usr/bin;\
X		echo "New /usr/bin/cc installed. Old one renamed."
SHAR_EOF
$TOUCH -am 1126160892 shared-libraries/patches/cc/Makefile &&
chmod 0644 shared-libraries/patches/cc/Makefile ||
echo "restore of shared-libraries/patches/cc/Makefile failed"
set `wc -c shared-libraries/patches/cc/Makefile`;Wc_c=$1
if test "$Wc_c" != "443"; then
	echo original size 443, current size $Wc_c
fi
# ============= shared-libraries/patches/cc/cc.c.diff ==============
echo "x - extracting shared-libraries/patches/cc/cc.c.diff (Text)"
sed 's/^X//' << 'SHAR_EOF' > shared-libraries/patches/cc/cc.c.diff &&
X*** cc.c.orig	Wed May  8 19:51:22 1991
X--- cc.c	Sat Nov  7 21:53:31 1992
X***************
X*** 202,208 ****
X--- 202,211 ----
X  
X  /* config.h can define LIB_SPEC to override the default libraries.  */
X  #ifndef LIB_SPEC
X+ /*
X  #define LIB_SPEC "%{!p:%{!pg:-lc}}%{p:-lc_p}%{pg:-lc_p}"
X+ */
X+ #define LIB_SPEC "%{!p:%{!pg:%{!static:-lc_s}%{static:-lc}}}%{p:-lc_p}%{pg:-lc_p}"
X  #endif
X  
X  /* config.h can define ENDFILE_SPEC to override the default crtn files.  */
X***************
X*** 212,219 ****
X--- 215,226 ----
X  
X  /* config.h can define STARTFILE_SPEC to override the default crt0 files.  */
X  #ifndef STARTFILE_SPEC
X+ /*
X  #define STARTFILE_SPEC  \
X    "%{pg:gcrt0.o%s}%{!pg:%{p:mcrt0.o%s}%{!p:crt0.o%s}}"
X+ */
X+ #define STARTFILE_SPEC  \
X+   "%{pg:gcrt0.o%s}%{!pg:%{p:mcrt0.o%s}%{!p:%{static:crt0.o%s}%{!static:crt0_s.o%s}}}"
X  #endif
X  
X  /* This spec is used for telling cpp whether char is signed or not.  */
SHAR_EOF
$TOUCH -am 1108225492 shared-libraries/patches/cc/cc.c.diff &&
chmod 0644 shared-libraries/patches/cc/cc.c.diff ||
echo "restore of shared-libraries/patches/cc/cc.c.diff failed"
set `wc -c shared-libraries/patches/cc/cc.c.diff`;Wc_c=$1
if test "$Wc_c" != "917"; then
	echo original size 917, current size $Wc_c
fi
exit 0