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

Contents of /src/tools/linker.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.10 - (show annotations)
Tue Jul 27 02:35:26 2010 UTC (3 years, 8 months ago) by rtoy
Branch: MAIN
Changes since 1.9: +6 -6 lines
File MIME type: application/x-sh
lisp/elf.c:
o Print out the size of Elf_Ehdr and Elf32_Phdr, for debugging.
o Pass the address of main to the linker script.  We will use the
  first word of main as the address of builtin_image_flag.  It seems
  highly unlikely that this would have have the value 0.

tools/Linux-cmucl-linker-script:
o Hardwire the value of SIZEOF_HEADERS.  This is needed on Debian to
  get the right number of segments.
o Comment out some items and/or fix them so that Debian's linker
  doesn't complain.  Doesn't appear to do any harm on openSuSE 11.2.

tools/linker.sh:
o Update for the additional argument for the address of main to use as
  the address of builtin_image_flag.
1 #!/bin/sh -x
2
3 # $Id: linker.sh,v 1.10 2010/07/27 02:35:26 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 OUTPUT="-o $3"
54 OUTDIR=`dirname $3`
55 CURDIR=`pwd`
56
57 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=$2"
75
76 # IFADDR is the initial function address, needed to start lisp processing.
77 IFADDR="--defsym initial_function_addr=$1"
78
79 # Set OS-specific variables.
80 case "$OPSYS" in
81 Linux )
82 # 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 DLINKER='-dynamic-linker /lib/ld-linux.so.2'
94 LIBS="-L$LIBROOT -ldl -lm -lgcc -lc -lgcc"
95 ;;
96 FreeBSD )
97 DLINKER='-dynamic-linker /usr/libexec/ld-elf.so.1'
98 STARTCRT="$LIBROOT/crt1.o $LIBROOT/crti.o $LIBROOT/crtbegin.o"
99 ENDCRT="$LIBROOT/crtend.o $LIBROOT/crtn.o"
100 LIBS='-lm -lgcc -lc -lgcc'
101 ;;
102 SunOS )
103 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 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 sed -e "s;@BIFLAG@;$BIFLAG;" -e "s;@IFADDR@;$1;" $SCRIPT > $OUTDIR/sunos-map-file
122 SCRIPT="-M sunos-map-file"
123 # Remove the sunos-map-file when the script exits.
124 trap 'rm -f $OUTDIR/sunos-map-file' 0
125 echo $PWD
126 FLAGS=
127 BIFLAG=
128 ;;
129 * )
130 echo "$0: unknown operating system $OPSYS."
131 exit 1
132 ;;
133 esac
134
135 cd $OUTDIR
136 $LINKER $SCRIPT $DLINKER $OUTPUT $STARTCRT $FLAGS $BIFLAG $IFADDR $OBJS $LIBS $ENDCRT
137 cd $CURDIR
138
139 exit 0

  ViewVC Help
Powered by ViewVC 1.1.5