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

Contents of /src/tools/linker.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.9 - (hide annotations)
Mon Jul 26 19:07:56 2010 UTC (3 years, 8 months ago) by rtoy
Branch: MAIN
Changes since 1.8: +4 -3 lines
File MIME type: application/x-sh
The generated linker script was placed in the wrong directory and ld
could not find it.  Put it in the same directory as executable, and
delete it when done.
1 fgilham 1.1 #!/bin/sh -x
2    
3 rtoy 1.9 # $Id: linker.sh,v 1.9 2010/07/26 19:07:56 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.7 if [ $# -ne 3 ]
9 fgilham 1.2 then
10 rtoy 1.7 echo "Usage: `basename $0` <c-compiler> <initial function address> <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     OUTPUT="-o $2"
54 rtoy 1.8 OUTDIR=`dirname $2`
55     CURDIR=`pwd`
56    
57 rtoy 1.5 LINKER=/usr/bin/ld
58     CMUCLLIB=`dirname $0`
59     OBJS="--whole-archive $CMUCLLIB/lisp.a --no-whole-archive"
60     FLAGS='-export-dynamic'
61    
62     SCRIPT="-T $CMUCLLIB/$OPSYS$VER-cmucl-linker-script"
63    
64     # This is a hack.
65     # These are the default values.
66     #
67     # BIFLAG flags the executable as having a builtin lisp image. It should be
68     # a valid address because it will be dereferenced. It should also not point
69     # to an integer 0 because that would make the flag false. We use the first
70     # address in the process memory image, which should point to the ELF header.
71    
72     # XXXX The process image start address can change depending on the OS
73     # (at least).
74     BIFLAG='--defsym builtin_image_flag=0x08048000'
75    
76     # IFADDR is the initial function address, needed to start lisp processing.
77     IFADDR="--defsym initial_function_addr=$1"
78    
79 fgilham 1.2 # Set OS-specific variables.
80 fgilham 1.1 case "$OPSYS" in
81     Linux )
82 fgilham 1.4 # Handle x86_64 version system. This should be revisited when there's a 64-bit version
83     # of CMUCL on Linux. Note that -m32 won't work in older versions of GCC which we may
84     # still want to support.
85     ARCH=`uname -m`
86     if [ "$ARCH" = "x86_64" ]
87     then
88     CRTPATH=`$GCC -m32 -print-libgcc-file-name`
89     LIBROOT=`dirname $CRTPATH`
90     fi
91     STARTCRT="/usr/lib/crt1.o /usr/lib/crti.o $LIBROOT/crtbegin.o"
92     ENDCRT="$LIBROOT/crtend.o /usr/lib/crtn.o"
93 fgilham 1.2 DLINKER='-dynamic-linker /lib/ld-linux.so.2'
94 fgilham 1.1 LIBS="-L$LIBROOT -ldl -lm -lgcc -lc -lgcc"
95     ;;
96     FreeBSD )
97 fgilham 1.2 DLINKER='-dynamic-linker /usr/libexec/ld-elf.so.1'
98 fgilham 1.1 STARTCRT="$LIBROOT/crt1.o $LIBROOT/crti.o $LIBROOT/crtbegin.o"
99     ENDCRT="$LIBROOT/crtend.o $LIBROOT/crtn.o"
100 fgilham 1.2 LIBS='-lm -lgcc -lc -lgcc'
101 fgilham 1.1 ;;
102 rtoy 1.5 SunOS )
103 rtoy 1.7 if [ $CCOMPILER = "cc" ]; then
104     # These values were obtained by running cc -# hello.c and
105     # looking at the linker command.
106     STARTCRT="$LIBROOT/crti.o $LIBROOT/crt1.o $LIBROOT/misalign.o $LIBROOT/values-xa.o"
107     ENDCRT="$LIBROOT/crtn.o"
108     LIBS="-Y P,$LIBROOT/v8plus:$LIBROOT:/usr/ccs/lib:/lib:/usr/lib -Qy -lm -lc -lsocket -lnsl -ldl"
109     else
110     STARTCRT="$LIBROOT/crt1.o $LIBROOT/crti.o $LIBROOT/crtbegin.o"
111     ENDCRT="$LIBROOT/crtend.o $LIBROOT/crtn.o"
112     LIBS="-L$LIBROOT -lm -lgcc -lc -lgcc -lsocket -lnsl -ldl"
113     fi
114 rtoy 1.5 LINKER="/usr/ccs/bin/ld"
115     OBJS="-z allextract $CMUCLLIB/lisp.a CORRO.o CORSTA.o CORDYN.o -z defaultextract"
116     SCRIPT="$CMUCLLIB/$OPSYS$VER-cmucl-linker-script"
117     # Is this right? I just made this point to &main, and the
118     # first word of main isn't all zeros.
119     BIFLAG=0x14120
120     IFADDR=
121 rtoy 1.9 sed -e "s;@BIFLAG@;$BIFLAG;" -e "s;@IFADDR@;$1;" $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     ;;
129 fgilham 1.1 * )
130     echo "$0: unknown operating system $OPSYS."
131     exit 1
132     ;;
133     esac
134    
135 rtoy 1.8 cd $OUTDIR
136 fgilham 1.1 $LINKER $SCRIPT $DLINKER $OUTPUT $STARTCRT $FLAGS $BIFLAG $IFADDR $OBJS $LIBS $ENDCRT
137 rtoy 1.8 cd $CURDIR
138 fgilham 1.2
139     exit 0

  ViewVC Help
Powered by ViewVC 1.1.5