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

Contents of /src/tools/linker.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.15 - (hide annotations)
Wed Sep 8 12:06:23 2010 UTC (3 years, 7 months ago) by rtoy
Branch: MAIN
CVS Tags: cross-sol-x86-merged, cross-sol-x86-base, snapshot-2010-12, snapshot-2010-11, cross-sol-x86-2010-12-20, cross-sparc-branch-base
Branch point for: cross-sparc-branch, cross-sol-x86-branch
Changes since 1.14: +112 -125 lines
File MIME type: application/x-sh
Rename linker-x86.sh to linker.sh.

lisp/elf.h:
o Set LINKER_SCRIPT to linker.sh

tools/make-main-dist.sh:
o Don't copy linker-x86.sh to the distribution anymore.

tools/linker.sh:
o Copied contents of linker-x86.sh to here.
1 rtoy 1.15 #!/bin/sh
2 fgilham 1.1
3 rtoy 1.15 # $Id: linker.sh,v 1.15 2010/09/08 12:06:23 rtoy Rel $
4 fgilham 1.1
5 rtoy 1.15 # 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 fgilham 1.1
16 rtoy 1.15 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 fgilham 1.2 exit 1
31     fi
32    
33 rtoy 1.7 CCOMPILER=$1
34 rtoy 1.15 IFADDR=$2
35     EXEC=$3
36 rtoy 1.7
37 rtoy 1.15 # Figure out the directory and file name of the executable.
38     OUTDIR=`dirname $EXEC`
39     OUTNAME=`basename $EXEC`
40 rtoy 1.7
41 rtoy 1.15 # This tells us where the cmu lisp executable is and also the
42     # locations of lisp.a.
43 rtoy 1.5 CMUCLLIB=`dirname $0`
44    
45 rtoy 1.15 # 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)
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 rtoy 1.5
119 fgilham 1.1 esac
120    
121 rtoy 1.15 # 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 fgilham 1.2

  ViewVC Help
Powered by ViewVC 1.1.5