2 # genscripts.sh - generate the ld-emulation-target specific files
4 # Usage: genscripts.sh srcdir libdir host target target_alias \
5 # default_emulation native_lib_dirs this_emulation
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
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.
18 # The exec_prefix, target_alias, use_sysroot, NATIVE_LIB_DIRS, TOOL_LIB, CUSTOMIZER_SCRIPT
19 # arguments are not used in this version.
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'.
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"
47 # Include the emulation-specific parameters:
48 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
50 if test -d ldscripts; then
56 # Set some flags for the emultempl scripts. USE_LIBPATH will
57 # be set for any libpath-using emulation; NATIVE will be set for a
58 # emulation to enable 'LD_LIBRARY_PATH=/foo:/bar ld -lfooz'
59 if [ "x${host}" = "x${target}" ] ; then
64 # Set the library search path, for libraries named by -lfoo.
65 # If LIB_PATH is defined (e.g., by Makefile) and non-empty, it is used.
66 # Otherwise, the default is set here.
68 # The format is the usual list of colon-separated directories.
69 # To force a logically empty LIB_PATH, do LIBPATH=":".
71 LIB_SEARCH_DIRS=`echo ${libdir} | sed -e 's/:/ /g' -e 's/\([^ ][^ ]*\)/SEARCH_DIR(\1);/g'`
72 #2.13: LIB_SEARCH_DIRS=`echo ${libdir} | sed -e 's/:/ /g' -e 's/\([^ ][^ ]*\)/SEARCH_DIR(\\"\1\\");/g'`
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.)
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
95 if [ "x$SCRIPT_NAME" = "xelf" ]; then
96 GENERATE_COMBRELOC_SCRIPT=yes
99 #2.13: SEGMENT_SIZE=${SEGMENT_SIZE-${TARGET_PAGE_SIZE}}
100 SEGMENT_SIZE=${SEGMENT_SIZE-${MAXPAGESIZE-${TARGET_PAGE_SIZE}}}
102 # Determine DATA_ALIGNMENT for the 5 variants, using
103 # values specified in the emulparams/<emulation>.sh file or default.
105 DATA_ALIGNMENT_="${DATA_ALIGNMENT_-${DATA_ALIGNMENT-ALIGN(${SEGMENT_SIZE})}}"
106 DATA_ALIGNMENT_n="${DATA_ALIGNMENT_n-${DATA_ALIGNMENT_}}"
107 DATA_ALIGNMENT_N="${DATA_ALIGNMENT_N-${DATA_ALIGNMENT-.}}"
108 DATA_ALIGNMENT_r="${DATA_ALIGNMENT_r-${DATA_ALIGNMENT-}}"
109 DATA_ALIGNMENT_u="${DATA_ALIGNMENT_u-${DATA_ALIGNMENT_r}}"
112 DATA_ALIGNMENT=${DATA_ALIGNMENT_r}
113 DEFAULT_DATA_ALIGNMENT="ALIGN(${SEGMENT_SIZE})"
114 ( echo "/* Script for ld -r: link without relocation */"
115 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
116 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
117 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xr
120 DATA_ALIGNMENT=${DATA_ALIGNMENT_u}
122 ( echo "/* Script for ld -Ur: link w/out relocation, do create constructors */"
123 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
124 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
125 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xu
128 DATA_ALIGNMENT=${DATA_ALIGNMENT_}
130 ( echo "/* Default linker script, for normal executables */"
131 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
132 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
133 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.x
136 DATA_ALIGNMENT=${DATA_ALIGNMENT_n}
137 TEXT_START_ADDR=${NONPAGED_TEXT_START_ADDR-${TEXT_START_ADDR}}
138 ( echo "/* Script for -n: mix text and data on same page */"
139 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
140 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
141 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xn
144 DATA_ALIGNMENT=${DATA_ALIGNMENT_N}
145 ( echo "/* Script for -N: mix text and data on same page; don't align data */"
146 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
147 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
148 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xbn
150 if test -n "$GENERATE_COMBRELOC_SCRIPT"; then
151 DATA_ALIGNMENT=${DATA_ALIGNMENT_c-${DATA_ALIGNMENT_}}
153 COMBRELOC=ldscripts/${EMULATION_NAME}.xc.tmp
154 ( echo "/* Script for -z combreloc: combine and sort reloc sections */"
155 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
156 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
157 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xc
162 if test -n "$GENERATE_SHLIB_SCRIPT"; then
164 DATA_ALIGNMENT=${DATA_ALIGNMENT_s-${DATA_ALIGNMENT_}}
166 # Note that TEXT_START_ADDR is set to NONPAGED_TEXT_START_ADDR.
168 echo "/* Script for ld --shared: link shared library */"
169 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
170 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
171 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xs
172 if test -n "$GENERATE_COMBRELOC_SCRIPT"; then
174 DATA_ALIGNMENT=${DATA_ALIGNMENT_sc-${DATA_ALIGNMENT}}
175 COMBRELOC=ldscripts/${EMULATION_NAME}.xc.tmp
176 ( echo "/* Script for --shared -z combreloc: shared library, combine & sort relocs */"
177 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
178 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
179 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xsc
186 if test -n "$GENERATE_PIE_SCRIPT"; then
188 DATA_ALIGNMENT=${DATA_ALIGNMENT_s-${DATA_ALIGNMENT_}}
190 # Note that TEXT_START_ADDR is set to NONPAGED_TEXT_START_ADDR.
192 echo "/* Script for ld -pie: link position independent executable */"
193 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
194 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
195 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xd
196 if test -n "$GENERATE_COMBRELOC_SCRIPT"; then
198 DATA_ALIGNMENT=${DATA_ALIGNMENT_sc-${DATA_ALIGNMENT}}
199 COMBRELOC=ldscripts/${EMULATION_NAME}.xc.tmp
200 ( echo "/* Script for -pie -z combreloc: position independent executable, combine & sort relocs */"
201 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
202 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
203 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xdc
210 case " $EMULATION_LIBPATH " in
211 *" ${EMULATION_NAME} "*) COMPILE_IN=true;;
214 # Generate e${EMULATION_NAME}.c.
215 . ${srcdir}/emultempl/${TEMPLATE_NAME-generic}.em