/[cmucl]/src/tools/linker.sh
ViewVC logotype

Contents of /src/tools/linker.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.12 - (show annotations)
Wed Jul 28 01:21:31 2010 UTC (3 years, 8 months ago) by rtoy
Branch: MAIN
Changes since 1.11: +3 -2 lines
File MIME type: application/x-sh
Need to strip off any directory from the path to get the output file
name because we cd to the directory already.
1 #!/bin/sh -x
2
3 # $Id: linker.sh,v 1.12 2010/07/28 01:21:31 rtoy Exp $
4
5 # This file was written by Fred Gilham and is placed in the public domain.
6 # It comes without warranty of any kind.
7
8 if [ $# -ne 4 ]
9 then
10 echo "Usage: `basename $0` <c-compiler> <initial function address> <main> <executable file>"
11 exit 1
12 fi
13
14 CCOMPILER=$1
15 shift;
16
17 if [ $CCOMPILER = "cc" ]; then
18 # Sun C compiler
19
20 # Can't set PATH because we don't really know where the compiler
21 # is. The user has to have it in his path.
22
23 CC=`which cc`
24 if [ -z "$CC" ]; then
25 echo 'Cannot find Sun C. Is it available and in $PATH?'
26 exit 1
27 fi
28 CRTPATH=`dirname $CC`/../prod
29 LIBROOT=$CRTPATH/lib
30
31 else
32 # Gcc
33 PATH=/bin:/usr/bin:/usr/local/bin
34
35 GCC=`which gcc`
36
37 if [ -z "$GCC" ]; then
38 echo 'Cannot find GCC. How did you build lisp?'
39 exit 1
40 fi
41
42 # Uniform method for finding GCC C runtime object files suggested by Ray Toy
43 CRTPATH=`$GCC -print-libgcc-file-name`
44 LIBROOT=`dirname $CRTPATH`
45 fi
46
47 echo "LIBROOT is $LIBROOT"
48
49 OPSYS=`uname`
50 VER=''
51
52 # Default values
53 OUTDIR=`dirname $3`
54 OUTNAME=`basename $3`
55 OUTPUT="-o $OUTNAME"
56 CURDIR=`pwd`
57
58 LINKER=/usr/bin/ld
59 CMUCLLIB=`dirname $0`
60 OBJS="--whole-archive $CMUCLLIB/lisp.a --no-whole-archive"
61 FLAGS='-export-dynamic'
62
63 SCRIPT="-T $CMUCLLIB/$OPSYS$VER-cmucl-linker-script"
64
65 # This is a hack.
66 # These are the default values.
67 #
68 # BIFLAG flags the executable as having a builtin lisp image. It should be
69 # a valid address because it will be dereferenced. It should also not point
70 # to an integer 0 because that would make the flag false. We use the first
71 # address in the process memory image, which should point to the ELF header.
72
73 # XXXX The process image start address can change depending on the OS
74 # (at least).
75 BIFLAG="--defsym builtin_image_flag=$2"
76
77 # IFADDR is the initial function address, needed to start lisp processing.
78 IFADDR="--defsym initial_function_addr=$1"
79
80 # Set OS-specific variables.
81 case "$OPSYS" in
82 Linux )
83 # Handle x86_64 version system. This should be revisited when there's a 64-bit version
84 # of CMUCL on Linux. Note that -m32 won't work in older versions of GCC which we may
85 # still want to support.
86 ARCH=`uname -m`
87 if [ "$ARCH" = "x86_64" ]
88 then
89 CRTPATH=`$GCC -m32 -print-libgcc-file-name`
90 LIBROOT=`dirname $CRTPATH`
91 fi
92 STARTCRT="/usr/lib/crt1.o /usr/lib/crti.o $LIBROOT/crtbegin.o"
93 ENDCRT="$LIBROOT/crtend.o /usr/lib/crtn.o"
94 DLINKER='-dynamic-linker /lib/ld-linux.so.2'
95 LIBS="-L$LIBROOT -ldl -lm -lgcc -lc -lgcc"
96 ;;
97 FreeBSD )
98 DLINKER='-dynamic-linker /usr/libexec/ld-elf.so.1'
99 STARTCRT="$LIBROOT/crt1.o $LIBROOT/crti.o $LIBROOT/crtbegin.o"
100 ENDCRT="$LIBROOT/crtend.o $LIBROOT/crtn.o"
101 LIBS='-lm -lgcc -lc -lgcc'
102 ;;
103 SunOS )
104 if [ $CCOMPILER = "cc" ]; then
105 # These values were obtained by running cc -# hello.c and
106 # looking at the linker command.
107 STARTCRT="$LIBROOT/crti.o $LIBROOT/crt1.o $LIBROOT/misalign.o $LIBROOT/values-xa.o"
108 ENDCRT="$LIBROOT/crtn.o"
109 LIBS="-Y P,$LIBROOT/v8plus:$LIBROOT:/usr/ccs/lib:/lib:/usr/lib -Qy -lm -lc -lsocket -lnsl -ldl"
110 else
111 STARTCRT="$LIBROOT/crt1.o $LIBROOT/crti.o $LIBROOT/crtbegin.o"
112 ENDCRT="$LIBROOT/crtend.o $LIBROOT/crtn.o"
113 LIBS="-L$LIBROOT -lm -lgcc -lc -lgcc -lsocket -lnsl -ldl"
114 fi
115 LINKER="/usr/ccs/bin/ld"
116 OBJS="-z allextract $CMUCLLIB/lisp.a CORRO.o CORSTA.o CORDYN.o -z defaultextract"
117 SCRIPT="$CMUCLLIB/$OPSYS$VER-cmucl-linker-script"
118 # Is this right? I just made this point to &main, and the
119 # first word of main isn't all zeros.
120 BIFLAG=$2
121 IFADDR=$1
122 sed -e "s;@BIFLAG@;$BIFLAG;" -e "s;@IFADDR@;$IFADDR;" $SCRIPT > $OUTDIR/sunos-map-file
123 SCRIPT="-M sunos-map-file"
124 # Remove the sunos-map-file when the script exits.
125 trap 'rm -f $OUTDIR/sunos-map-file' 0
126 echo $PWD
127 FLAGS=
128 BIFLAG=
129 IFADDR=
130 ;;
131 * )
132 echo "$0: unknown operating system $OPSYS."
133 exit 1
134 ;;
135 esac
136
137 cd $OUTDIR
138 $LINKER $SCRIPT $DLINKER $OUTPUT $STARTCRT $FLAGS $BIFLAG $IFADDR $OBJS $LIBS $ENDCRT
139 cd $CURDIR
140
141 exit 0

  ViewVC Help
Powered by ViewVC 1.1.5