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'.
40 CUSTOMIZER_SCRIPT="${srcdir}/emulparams/${EMULATION_NAME}.sh"
42 # Include the emulation-specific parameters:
43 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
45 if test -d ldscripts; then
51 # Set some flags for the emultempl scripts. USE_LIBPATH will
52 # be set for any libpath-using emulation.
55 # Set the library search path, for libraries named by -lfoo.
56 # If LIB_PATH is defined (e.g., by Makefile) and non-empty, it is used.
57 # Otherwise, the default is set here.
59 # The format is the usual list of colon-separated directories.
60 # To force a logically empty LIB_PATH, do LIBPATH=":".
62 LIB_SEARCH_DIRS=`echo ${libdir} | sed -e 's/:/ /g' -e 's/\([^ ][^ ]*\)/SEARCH_DIR(\1);/g'`
63 #2.13: LIB_SEARCH_DIRS=`echo ${libdir} | sed -e 's/:/ /g' -e 's/\([^ ][^ ]*\)/SEARCH_DIR(\\"\1\\");/g'`
65 # Generate 5 or 6 script files from a master script template in
66 # ${srcdir}/scripttempl/${SCRIPT_NAME}.sh. Which one of the 5 or 6
67 # script files is actually used depends on command line options given
68 # to ld. (SCRIPT_NAME was set in the emulparams_file.)
70 # A .x script file is the default script.
71 # A .xr script is for linking without relocation (-r flag).
72 # A .xu script is like .xr, but *do* create constructors (-Ur flag).
73 # A .xn script is for linking with -n flag (mix text and data on same page).
74 # A .xbn script is for linking with -N flag (mix text and data on same page).
75 # A .xs script is for generating a shared library with the --shared
76 # flag; it is only generated if $GENERATE_SHLIB_SCRIPT is set by the
77 # emulation parameters.
78 # A .xc script is for linking with -z combreloc; it is only generated if
79 # $GENERATE_COMBRELOC_SCRIPT is set by the emulation parameters or
80 # $SCRIPT_NAME is "elf".
81 # A .xsc script is for linking with --shared -z combreloc; it is generated
82 # if $GENERATE_COMBRELOC_SCRIPT is set by the emulation parameters or
83 # $SCRIPT_NAME is "elf" and $GENERATE_SHLIB_SCRIPT is set by the emulation
86 if [ "x$SCRIPT_NAME" = "xelf" ]; then
87 GENERATE_COMBRELOC_SCRIPT=yes
90 #2.13: SEGMENT_SIZE=${SEGMENT_SIZE-${TARGET_PAGE_SIZE}}
91 SEGMENT_SIZE=${SEGMENT_SIZE-${MAXPAGESIZE-${TARGET_PAGE_SIZE}}}
93 # Determine DATA_ALIGNMENT for the 5 variants, using
94 # values specified in the emulparams/<emulation>.sh file or default.
96 DATA_ALIGNMENT_="${DATA_ALIGNMENT_-${DATA_ALIGNMENT-ALIGN(${SEGMENT_SIZE})}}"
97 DATA_ALIGNMENT_n="${DATA_ALIGNMENT_n-${DATA_ALIGNMENT_}}"
98 DATA_ALIGNMENT_N="${DATA_ALIGNMENT_N-${DATA_ALIGNMENT-.}}"
99 DATA_ALIGNMENT_r="${DATA_ALIGNMENT_r-${DATA_ALIGNMENT-}}"
100 DATA_ALIGNMENT_u="${DATA_ALIGNMENT_u-${DATA_ALIGNMENT_r}}"
103 DATA_ALIGNMENT=${DATA_ALIGNMENT_r}
104 DEFAULT_DATA_ALIGNMENT="ALIGN(${SEGMENT_SIZE})"
105 ( echo "/* Script for ld -r: link without relocation */"
106 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
107 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
108 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xr
111 DATA_ALIGNMENT=${DATA_ALIGNMENT_u}
113 ( echo "/* Script for ld -Ur: link w/out relocation, do create constructors */"
114 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
115 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
116 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xu
119 DATA_ALIGNMENT=${DATA_ALIGNMENT_}
121 ( echo "/* Default linker script, for normal executables */"
122 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
123 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
124 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.x
127 DATA_ALIGNMENT=${DATA_ALIGNMENT_n}
128 TEXT_START_ADDR=${NONPAGED_TEXT_START_ADDR-${TEXT_START_ADDR}}
129 ( echo "/* Script for -n: mix text and data on same page */"
130 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
131 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
132 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xn
135 DATA_ALIGNMENT=${DATA_ALIGNMENT_N}
136 ( echo "/* Script for -N: mix text and data on same page; don't align data */"
137 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
138 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
139 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xbn
141 if test -n "$GENERATE_COMBRELOC_SCRIPT"; then
142 DATA_ALIGNMENT=${DATA_ALIGNMENT_c-${DATA_ALIGNMENT_}}
144 COMBRELOC=ldscripts/${EMULATION_NAME}.xc.tmp
145 ( echo "/* Script for -z combreloc: combine and sort reloc sections */"
146 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
147 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
148 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xc
153 if test -n "$GENERATE_SHLIB_SCRIPT"; then
155 DATA_ALIGNMENT=${DATA_ALIGNMENT_s-${DATA_ALIGNMENT_}}
157 # Note that TEXT_START_ADDR is set to NONPAGED_TEXT_START_ADDR.
159 echo "/* Script for ld --shared: link shared library */"
160 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
161 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
162 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xs
163 if test -n "$GENERATE_COMBRELOC_SCRIPT"; then
165 DATA_ALIGNMENT=${DATA_ALIGNMENT_sc-${DATA_ALIGNMENT}}
166 COMBRELOC=ldscripts/${EMULATION_NAME}.xc.tmp
167 ( echo "/* Script for --shared -z combreloc: shared library, combine & sort relocs */"
168 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
169 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
170 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xsc
177 if test -n "$GENERATE_PIE_SCRIPT"; then
179 DATA_ALIGNMENT=${DATA_ALIGNMENT_s-${DATA_ALIGNMENT_}}
181 # Note that TEXT_START_ADDR is set to NONPAGED_TEXT_START_ADDR.
183 echo "/* Script for ld -pie: link position independent executable */"
184 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
185 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
186 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xd
187 if test -n "$GENERATE_COMBRELOC_SCRIPT"; then
189 DATA_ALIGNMENT=${DATA_ALIGNMENT_sc-${DATA_ALIGNMENT}}
190 COMBRELOC=ldscripts/${EMULATION_NAME}.xc.tmp
191 ( echo "/* Script for -pie -z combreloc: position independent executable, combine & sort relocs */"
192 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
193 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
194 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xdc
201 case " $EMULATION_LIBPATH " in
202 *" ${EMULATION_NAME} "*) COMPILE_IN=true;;
205 # Generate e${EMULATION_NAME}.c.
206 . ${srcdir}/emultempl/${TEMPLATE_NAME-generic}.em