]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - gnu/usr.bin/binutils/ld/genscripts.sh
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / gnu / usr.bin / binutils / ld / genscripts.sh
1 #!/bin/sh
2 # genscripts.sh - generate the ld-emulation-target specific files
3 #
4 # Usage: genscripts.sh srcdir libdir host target target_alias \
5 # default_emulation native_lib_dirs this_emulation
6 #
7 # Sample usage:
8 # genscripts.sh /djm/ld-devo/devo/ld /usr/local/lib sparc-sun-sunos4.1.3 \
9 # sparc-sun-sunos4.1.3 sparc-sun-sunos4.1.3 sun4 "" sun3 sparc-sun-sunos4.1.3
10 # produces sun3.x sun3.xbn sun3.xn sun3.xr sun3.xu em_sun3.c
11 #
12 # $FreeBSD$
13 #
14 # This is a cut-down version of the GNU script. Instead of jumping through
15 # hoops for all possible combinations of paths, just use the libdir
16 # argument in place of LIB_PATH.
17 #
18 # The exec_prefix, target_alias, use_sysroot, NATIVE_LIB_DIRS, TOOL_LIB, CUSTOMIZER_SCRIPT
19 # arguments are not used in this version.
20 #
21
22 srcdir=$1
23 libdir=$2
24 exec_prefix=$3
25 host=$4
26 target=$5
27 target_alias=$6
28 EMULATION_LIBPATH=$7
29 NATIVE_LIB_DIRS=$8
30 use_sysroot=$9
31 shift 9
32 EMULATION_NAME=$1
33 TOOL_LIB=$2
34 CUSTOMIZER_SCRIPT=$3
35
36 # Create the 'CUSTOMIZER_SCRIPT' knob to better sync this script with
37 # FSF BU ver 2.15 which allows for a more generic emulparams processing.
38 # To reduce the diff, I also include the ${EMULATION_NAME} parameter in uses
39 # of 'CUSTOMIZER_SCRIPT'.
40
41 # XXX: arm hack : until those file are merged back into the FSF repo, just
42 # use the version in this directory.
43 if !(test -f ${CUSTOMIZER_SCRIPT}"";) then
44 CUSTOMIZER_SCRIPT="${srcdir}/emulparams/${EMULATION_NAME}.sh"
45 fi
46
47 # Include the emulation-specific parameters:
48 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
49
50 if test -d ldscripts; then
51   true
52 else
53   rm -f ldscripts
54   mkdir ldscripts
55 fi
56
57 # Set some flags for the emultempl scripts.  USE_LIBPATH will
58 # be set for any libpath-using emulation; NATIVE will be set for a
59 # emulation to enable 'LD_LIBRARY_PATH=/foo:/bar ld -lfooz'
60     if [ "x${host}" = "x${target}" ] ; then
61       NATIVE=yes
62     fi
63   USE_LIBPATH=yes
64
65 # Set the library search path, for libraries named by -lfoo.
66 # If LIB_PATH is defined (e.g., by Makefile) and non-empty, it is used.
67 # Otherwise, the default is set here.
68 #
69 # The format is the usual list of colon-separated directories.
70 # To force a logically empty LIB_PATH, do LIBPATH=":".
71
72 LIB_SEARCH_DIRS=`echo ${libdir} | sed -e 's/:/ /g' -e 's/\([^ ][^ ]*\)/SEARCH_DIR(\1);/g'`
73
74 # Generate 5 or 6 script files from a master script template in
75 # ${srcdir}/scripttempl/${SCRIPT_NAME}.sh.  Which one of the 5 or 6
76 # script files is actually used depends on command line options given
77 # to ld.  (SCRIPT_NAME was set in the emulparams_file.)
78 #
79 # A .x script file is the default script.
80 # A .xr script is for linking without relocation (-r flag).
81 # A .xu script is like .xr, but *do* create constructors (-Ur flag).
82 # A .xn script is for linking with -n flag (mix text and data on same page).
83 # A .xbn script is for linking with -N flag (mix text and data on same page).
84 # A .xs script is for generating a shared library with the --shared
85 #   flag; it is only generated if $GENERATE_SHLIB_SCRIPT is set by the
86 #   emulation parameters.
87 # A .xc script is for linking with -z combreloc; it is only generated if
88 #   $GENERATE_COMBRELOC_SCRIPT is set by the emulation parameters or
89 #   $SCRIPT_NAME is "elf".
90 # A .xsc script is for linking with --shared -z combreloc; it is generated
91 #   if $GENERATE_COMBRELOC_SCRIPT is set by the emulation parameters or
92 #   $SCRIPT_NAME is "elf" and $GENERATE_SHLIB_SCRIPT is set by the emulation
93 #   parameters too.
94
95 if [ "x$SCRIPT_NAME" = "xelf" ]; then
96   GENERATE_COMBRELOC_SCRIPT=yes
97 fi
98
99 SEGMENT_SIZE=${SEGMENT_SIZE-${MAXPAGESIZE-${TARGET_PAGE_SIZE}}}
100
101 # Determine DATA_ALIGNMENT for the 5 variants, using
102 # values specified in the emulparams/<script_to_run>.sh file or default.
103
104 DATA_ALIGNMENT_="${DATA_ALIGNMENT_-${DATA_ALIGNMENT-ALIGN(${SEGMENT_SIZE})}}"
105 DATA_ALIGNMENT_n="${DATA_ALIGNMENT_n-${DATA_ALIGNMENT_}}"
106 DATA_ALIGNMENT_N="${DATA_ALIGNMENT_N-${DATA_ALIGNMENT-.}}"
107 DATA_ALIGNMENT_r="${DATA_ALIGNMENT_r-${DATA_ALIGNMENT-}}"
108 DATA_ALIGNMENT_u="${DATA_ALIGNMENT_u-${DATA_ALIGNMENT_r}}"
109
110 LD_FLAG=r
111 DATA_ALIGNMENT=${DATA_ALIGNMENT_r}
112 DEFAULT_DATA_ALIGNMENT="ALIGN(${SEGMENT_SIZE})"
113 ( echo "/* Script for ld -r: link without relocation */"
114   . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
115   . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
116 ) | sed -e '/^ *$/d;s/[         ]*$//' > ldscripts/${EMULATION_NAME}.xr
117
118 LD_FLAG=u
119 DATA_ALIGNMENT=${DATA_ALIGNMENT_u}
120 CONSTRUCTING=" "
121 ( echo "/* Script for ld -Ur: link w/out relocation, do create constructors */"
122   . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
123   . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
124 ) | sed -e '/^ *$/d;s/[         ]*$//' > ldscripts/${EMULATION_NAME}.xu
125
126 LD_FLAG=
127 DATA_ALIGNMENT=${DATA_ALIGNMENT_}
128 RELOCATING=" "
129 ( echo "/* Default linker script, for normal executables */"
130   . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
131   . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
132 ) | sed -e '/^ *$/d;s/[         ]*$//' > ldscripts/${EMULATION_NAME}.x
133
134 LD_FLAG=n
135 DATA_ALIGNMENT=${DATA_ALIGNMENT_n}
136 TEXT_START_ADDR=${NONPAGED_TEXT_START_ADDR-${TEXT_START_ADDR}}
137 ( echo "/* Script for -n: mix text and data on same page */"
138   . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
139   . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
140 ) | sed -e '/^ *$/d;s/[         ]*$//' > ldscripts/${EMULATION_NAME}.xn
141
142 LD_FLAG=N
143 DATA_ALIGNMENT=${DATA_ALIGNMENT_N}
144 ( echo "/* Script for -N: mix text and data on same page; don't align data */"
145   . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
146   . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
147 ) | sed -e '/^ *$/d;s/[         ]*$//' > ldscripts/${EMULATION_NAME}.xbn
148
149 if test -n "$GENERATE_COMBRELOC_SCRIPT"; then
150   DATA_ALIGNMENT=${DATA_ALIGNMENT_c-${DATA_ALIGNMENT_}}
151   LD_FLAG=c
152   COMBRELOC=ldscripts/${EMULATION_NAME}.xc.tmp
153   ( echo "/* Script for -z combreloc: combine and sort reloc sections */"
154     . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
155     . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
156   ) | sed -e '/^ *$/d;s/[       ]*$//' > ldscripts/${EMULATION_NAME}.xc
157   rm -f ${COMBRELOC}
158   LD_FLAG=w
159   RELRO_NOW=" "
160   COMBRELOC=ldscripts/${EMULATION_NAME}.xw.tmp
161   ( echo "/* Script for -z combreloc -z now -z relro: combine and sort reloc sections */"
162     . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
163     . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
164   ) | sed -e '/^ *$/d;s/[       ]*$//' > ldscripts/${EMULATION_NAME}.xw
165   rm -f ${COMBRELOC}
166   COMBRELOC=
167   unset RELRO_NOW
168 fi
169
170 if test -n "$GENERATE_SHLIB_SCRIPT"; then
171   LD_FLAG=shared
172   DATA_ALIGNMENT=${DATA_ALIGNMENT_s-${DATA_ALIGNMENT_}}
173   CREATE_SHLIB=" "
174   # Note that TEXT_START_ADDR is set to NONPAGED_TEXT_START_ADDR.
175   (
176     echo "/* Script for ld --shared: link shared library */"
177     . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
178     . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
179   ) | sed -e '/^ *$/d;s/[       ]*$//' > ldscripts/${EMULATION_NAME}.xs
180   if test -n "$GENERATE_COMBRELOC_SCRIPT"; then
181     LD_FLAG=cshared
182     DATA_ALIGNMENT=${DATA_ALIGNMENT_sc-${DATA_ALIGNMENT}}
183     COMBRELOC=ldscripts/${EMULATION_NAME}.xsc.tmp
184     ( echo "/* Script for --shared -z combreloc: shared library, combine & sort relocs */"
185       . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
186       . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
187     ) | sed -e '/^ *$/d;s/[     ]*$//' > ldscripts/${EMULATION_NAME}.xsc
188     rm -f ${COMBRELOC}
189     LD_FLAG=wshared
190     RELRO_NOW=" "
191     COMBRELOC=ldscripts/${EMULATION_NAME}.xsw.tmp
192     ( echo "/* Script for --shared -z combreloc -z now -z relro: shared library, combine & sort relocs */"
193       . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
194       . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
195     ) | sed -e '/^ *$/d;s/[     ]*$//' > ldscripts/${EMULATION_NAME}.xsw
196     rm -f ${COMBRELOC}
197     COMBRELOC=
198     unset RELRO_NOW
199   fi
200   unset CREATE_SHLIB
201 fi
202
203 if test -n "$GENERATE_PIE_SCRIPT"; then
204   LD_FLAG=pie
205   DATA_ALIGNMENT=${DATA_ALIGNMENT_s-${DATA_ALIGNMENT_}}
206   CREATE_PIE=" "
207   # Note that TEXT_START_ADDR is set to NONPAGED_TEXT_START_ADDR.
208   (
209     echo "/* Script for ld -pie: link position independent executable */"
210     . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
211     . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
212   ) | sed -e '/^ *$/d;s/[       ]*$//' > ldscripts/${EMULATION_NAME}.xd
213   if test -n "$GENERATE_COMBRELOC_SCRIPT"; then
214     LD_FLAG=cpie
215     DATA_ALIGNMENT=${DATA_ALIGNMENT_sc-${DATA_ALIGNMENT}}
216     COMBRELOC=ldscripts/${EMULATION_NAME}.xdc.tmp
217     ( echo "/* Script for -pie -z combreloc: position independent executable, combine & sort relocs */"
218       . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
219       . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
220     ) | sed -e '/^ *$/d;s/[     ]*$//' > ldscripts/${EMULATION_NAME}.xdc
221     rm -f ${COMBRELOC}
222     LD_FLAG=wpie
223     RELRO_NOW=" "
224     COMBRELOC=ldscripts/${EMULATION_NAME}.xdw.tmp
225     ( echo "/* Script for -pie -z combreloc -z now -z relro: position independent executable, combine & sort relocs */"
226       . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
227       . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
228     ) | sed -e '/^ *$/d;s/[     ]*$//' > ldscripts/${EMULATION_NAME}.xdw
229     rm -f ${COMBRELOC}
230     COMBRELOC=
231     unset RELRO_NOW
232   fi
233   unset CREATE_PIE
234 fi
235
236 case " $EMULATION_LIBPATH " in
237     *" ${EMULATION_NAME} "*) COMPILE_IN=true;;
238 esac
239
240 # Generate e${EMULATION_NAME}.c.
241 . ${srcdir}/emultempl/${TEMPLATE_NAME-generic}.em