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

Contents of /src/tools/linker.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.14 - (hide annotations)
Thu Jul 29 04:34:10 2010 UTC (3 years, 8 months ago) by rtoy
Branch: MAIN
CVS Tags: release-20b-pre1, release-20b-pre2, snapshot-2010-08
Branch point for: RELEASE-20B-BRANCH
Changes since 1.13: +2 -2 lines
File MIME type: application/x-sh
Change how we build executables for Linux.  We no longer need the
hairy and fragile linker script.  Instead, we can use regular old gcc
to do what we need.

(Should also work for FreeBSD, but not yet implemented.)

lisp/elf.c:
o Include validate.h so we can get the starting addresses of the
  read-only, static, and dynamic spaces.
o Add special case for linux to run the linker script correctly.

lisp/elf.h:
o There's a separate linker script for Linux.

lisp/save.c:
o Temporarily don't run elf_cleanup so we can have easier
  testing/debugging.

tools/linker.sh:
o Don't need BIFLAG anymore.

tools/make-main-dist.sh:
o Install linker-x86.sh.
1 fgilham 1.1 #!/bin/sh -x
2    
3 rtoy 1.14 # $Id: linker.sh,v 1.14 2010/07/29 04:34:10 rtoy Exp $
4 fgilham 1.1
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 rtoy 1.10 if [ $# -ne 4 ]
9 fgilham 1.2 then
10 rtoy 1.10 echo "Usage: `basename $0` <c-compiler> <initial function address> <main> <executable file>"
11 fgilham 1.2 exit 1
12     fi
13    
14 rtoy 1.7 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 fgilham 1.2
42 rtoy 1.7 # 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 fgilham 1.1 fi
46    
47 rtoy 1.7 echo "LIBROOT is $LIBROOT"
48    
49 fgilham 1.1 OPSYS=`uname`
50 fgilham 1.2 VER=''
51 fgilham 1.1
52 rtoy 1.5 # Default values
53 rtoy 1.10 OUTDIR=`dirname $3`
54 rtoy 1.12 OUTNAME=`basename $3`
55     OUTPUT="-o $OUTNAME"
56 rtoy 1.8 CURDIR=`pwd`
57    
58 rtoy 1.5 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 rtoy 1.14 #BIFLAG="--defsym builtin_image_flag=$2"
76 rtoy 1.5
77     # IFADDR is the initial function address, needed to start lisp processing.
78     IFADDR="--defsym initial_function_addr=$1"
79    
80 fgilham 1.2 # Set OS-specific variables.
81 fgilham 1.1 case "$OPSYS" in
82     Linux )
83 fgilham 1.4 # 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 fgilham 1.2 DLINKER='-dynamic-linker /lib/ld-linux.so.2'
95 fgilham 1.1 LIBS="-L$LIBROOT -ldl -lm -lgcc -lc -lgcc"
96     ;;
97     FreeBSD )
98 fgilham 1.2 DLINKER='-dynamic-linker /usr/libexec/ld-elf.so.1'
99 fgilham 1.1 STARTCRT="$LIBROOT/crt1.o $LIBROOT/crti.o $LIBROOT/crtbegin.o"
100     ENDCRT="$LIBROOT/crtend.o $LIBROOT/crtn.o"
101 fgilham 1.2 LIBS='-lm -lgcc -lc -lgcc'
102 fgilham 1.1 ;;
103 rtoy 1.5 SunOS )
104 rtoy 1.7 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 rtoy 1.5 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 rtoy 1.13 # Don't need BIFLAG on Solaris. The lisp.a archive has the
119     # correct value for it.
120 rtoy 1.11 IFADDR=$1
121 rtoy 1.13 sed -e "s;@IFADDR@;$IFADDR;" $SCRIPT > $OUTDIR/sunos-map-file
122 rtoy 1.5 SCRIPT="-M sunos-map-file"
123 rtoy 1.6 # Remove the sunos-map-file when the script exits.
124 rtoy 1.9 trap 'rm -f $OUTDIR/sunos-map-file' 0
125     echo $PWD
126 rtoy 1.5 FLAGS=
127     BIFLAG=
128 rtoy 1.11 IFADDR=
129 rtoy 1.5 ;;
130 fgilham 1.1 * )
131     echo "$0: unknown operating system $OPSYS."
132     exit 1
133     ;;
134     esac
135    
136 rtoy 1.8 cd $OUTDIR
137 fgilham 1.1 $LINKER $SCRIPT $DLINKER $OUTPUT $STARTCRT $FLAGS $BIFLAG $IFADDR $OBJS $LIBS $ENDCRT
138 rtoy 1.8 cd $CURDIR
139 fgilham 1.2
140     exit 0

  ViewVC Help
Powered by ViewVC 1.1.5