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

Contents of /src/tools/linker.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.16 - (show annotations)
Thu Dec 23 03:16:56 2010 UTC (3 years, 3 months ago) by rtoy
Branch: MAIN
CVS Tags: GIT-CONVERSION, snapshot-2011-09, snapshot-2011-06, snapshot-2011-07, snapshot-2011-04, snapshot-2011-02, snapshot-2011-03, snapshot-2011-01, HEAD
Changes since 1.15: +2 -2 lines
File MIME type: application/x-sh
Support NetBSD.
1 #!/bin/sh
2
3 # $Id: linker.sh,v 1.16 2010/12/23 03:16:56 rtoy Exp $
4
5 # This file written by Raymond Toy as part of CMU Common Lisp and is
6 # placed in the public domain.
7 #
8 # This script takes parameters specified by the running lisp to create
9 # an executable image.
10 #
11 # Despite the name, it is used for Linux/x86, Darwin/x86, and
12 # Solaris/sparc, as specified in src/lisp/elf.h.
13
14 OPSYS=`uname`
15
16 if [ "X$CMU_DEBUG_LINKER" != "X" ]; then
17 # Enable debugging if CMU_DEBUG_LINKER is defined and not empty.
18 set -x
19 fi
20
21 # There must be exactly 6 parameters:
22 # - the name of the C compiler (sparc supports both Sun cc and GNU gcc).
23 # - the address of the initial function (in C hex format)
24 # - the path of the executable to be created
25 # - the address of the start of the read-only space
26 # - the address of the start of the static space
27 # - the address of the start of the dynamic space
28 if [ $# -ne 6 ]; then
29 echo "Usage: `basename $0` <c-compiler> <initial-func-addr> <executable> <ro-addr> <static-addr> <dyn-addr>"
30 exit 1
31 fi
32
33 CCOMPILER=$1
34 IFADDR=$2
35 EXEC=$3
36
37 # Figure out the directory and file name of the executable.
38 OUTDIR=`dirname $EXEC`
39 OUTNAME=`basename $EXEC`
40
41 # This tells us where the cmu lisp executable is and also the
42 # locations of lisp.a.
43 CMUCLLIB=`dirname $0`
44
45 # Name of file where we write the actual initial function address.
46 OPT_IFADDR="cmu-ifaddr-$$.c"
47 # Names of the core sections from Lisp.
48 OPT_CORE="CORRO.o CORSTA.o CORDYN.o"
49
50 uname_s=`uname`
51 case $uname_s in
52 Linux|FreeBSD|NetBSD)
53 # How to specify the starting address for each of the sections
54 # These aren't needed for Linux any more. map_core_sections
55 # takes care of getting the addresses.
56
57 #RO_ADDR="-Wl,--section-start=CORRO=$4"
58 #STATIC_ADDR="-Wl,--section-start=CORSTA=$5"
59 #DYN_ADDR="-Wl,--section-start=CORDYN=$6"
60
61 #OPT_IF ADDR="-Wl,--defsym -Wl,initial_function_addr=$IFADDR"
62
63 # Specify how to link the entire lisp.a library
64 OPT_ARCHIVE="-Wl,--whole-archive -Wl,$CMUCLLIB/lisp.a -Wl,--no-whole-archive"
65
66 # Extra stuff.
67
68 OPT_EXTRA="-rdynamic"
69
70 # See Config.x86_${uname_s}
71 case $uname_s in
72 Linux) OS_LIBS=-ldl;;
73 FreeBSD) OS_LIBS=-lutil;;
74 esac
75 ;;
76 Darwin)
77 # How to specify the starting address for each of the sections.
78 # We don't actually need these because map_core_sections sets
79 # the addresses itself instead of from the segment address, but
80 # if we don't set them up correctly, vmmap complains when run on
81 # the resulting executable. There's no harm in specifying them
82 # here, though; the addresses are ignored by map_core_sections.
83 RO_ADDR="-segaddr CORRO $4"
84 STATIC_ADDR="-segaddr CORSTA $5"
85 DYN_ADDR="-segaddr CORDYN $6"
86
87 # Specify how to link the entire lisp.a library
88 OPT_ARCHIVE="-all_load $CMUCLLIB/lisp.a"
89
90 # Extra stuff. For some reason one __LINKEDIT segment is mapped
91 # just past the dynamic space. This messes things up, so we move it
92 # to another address. This seems to be free, at least on 10.5.
93
94 OPT_EXTRA="-segaddr __LINKEDIT 0x99000000 -rdynamic"
95 # See Config.x86_darwin
96 OS_LIBS=
97 ;;
98 SunOS)
99 # A quick test indicates that gcc will accept the following
100 # options too, so this will work whether we have Sun C or gcc.
101 # Note, that this probably only works if gcc uses Sun ld and not
102 # GNU ld. Most (all?) prebuilt versions of gcc for Solaris use
103 # Sun ld.
104
105 # We don't need anything special to set the starting address.
106 # map_core_sections does that for us on sparc.
107
108 # Specify how to link the entire lisp.a library
109 OPT_ARCHIVE="-Xlinker -z -Xlinker allextract -Xlinker $CMUCLLIB/lisp.a -Xlinker -z -Xlinker defaultextract"
110
111 # Extra stuff.
112
113 OPT_EXTRA="-Bdynamic"
114
115 # See Config.sparc_sunc
116 OS_LIBS="-lsocket -lnsl -ldl"
117 ;;
118
119 esac
120
121 # Remove the C file and core section files when we're done.
122 trap 'rm -f $OUTDIR/$OPT_IFADDR $OUTDIR/CORRO.o $OUTDIR/CORSTA.o $OUTDIR/CORDYN.o' 0
123
124 (cd $OUTDIR
125 echo "long initial_function_addr = $IFADDR;" > $OPT_IFADDR
126 $CCOMPILER -m32 -o $OUTNAME $OPT_IFADDR $OPT_ARCHIVE $OPT_CORE $RO_ADDR $STATIC_ADDR $DYN_ADDR $OPT_EXTRA $OS_LIBS -lm)
127

  ViewVC Help
Powered by ViewVC 1.1.5