genscripts.sh revision 162301
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: head/gnu/usr.bin/binutils/ld/genscripts.sh 162301 2006-09-14 07:46:32Z imp $ 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 22srcdir=$1 23libdir=$2 24exec_prefix=$3 25host=$4 26target=$5 27target_alias=$6 28EMULATION_LIBPATH=$7 29NATIVE_LIB_DIRS=$8 30use_sysroot=$9 31shift 9 32EMULATION_NAME=$1 33TOOL_LIB=$2 34CUSTOMIZER_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. 43if !(test -f ${CUSTOMIZER_SCRIPT}"";) then 44CUSTOMIZER_SCRIPT="${srcdir}/emulparams/${EMULATION_NAME}.sh" 45fi 46 47# Include the emulation-specific parameters: 48. ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME} 49 50if test -d ldscripts; then 51 true 52else 53 mkdir ldscripts 54fi 55 56# Set some flags for the emultempl scripts. USE_LIBPATH will 57# be set for any libpath-using emulation. 58 USE_LIBPATH=yes 59 60# Set the library search path, for libraries named by -lfoo. 61# If LIB_PATH is defined (e.g., by Makefile) and non-empty, it is used. 62# Otherwise, the default is set here. 63# 64# The format is the usual list of colon-separated directories. 65# To force a logically empty LIB_PATH, do LIBPATH=":". 66 67LIB_SEARCH_DIRS=`echo ${libdir} | sed -e 's/:/ /g' -e 's/\([^ ][^ ]*\)/SEARCH_DIR(\1);/g'` 68#2.13: LIB_SEARCH_DIRS=`echo ${libdir} | sed -e 's/:/ /g' -e 's/\([^ ][^ ]*\)/SEARCH_DIR(\\"\1\\");/g'` 69 70# Generate 5 or 6 script files from a master script template in 71# ${srcdir}/scripttempl/${SCRIPT_NAME}.sh. Which one of the 5 or 6 72# script files is actually used depends on command line options given 73# to ld. (SCRIPT_NAME was set in the emulparams_file.) 74# 75# A .x script file is the default script. 76# A .xr script is for linking without relocation (-r flag). 77# A .xu script is like .xr, but *do* create constructors (-Ur flag). 78# A .xn script is for linking with -n flag (mix text and data on same page). 79# A .xbn script is for linking with -N flag (mix text and data on same page). 80# A .xs script is for generating a shared library with the --shared 81# flag; it is only generated if $GENERATE_SHLIB_SCRIPT is set by the 82# emulation parameters. 83# A .xc script is for linking with -z combreloc; it is only generated if 84# $GENERATE_COMBRELOC_SCRIPT is set by the emulation parameters or 85# $SCRIPT_NAME is "elf". 86# A .xsc script is for linking with --shared -z combreloc; it is generated 87# if $GENERATE_COMBRELOC_SCRIPT is set by the emulation parameters or 88# $SCRIPT_NAME is "elf" and $GENERATE_SHLIB_SCRIPT is set by the emulation 89# parameters too. 90 91if [ "x$SCRIPT_NAME" = "xelf" ]; then 92 GENERATE_COMBRELOC_SCRIPT=yes 93fi 94 95#2.13: SEGMENT_SIZE=${SEGMENT_SIZE-${TARGET_PAGE_SIZE}} 96SEGMENT_SIZE=${SEGMENT_SIZE-${MAXPAGESIZE-${TARGET_PAGE_SIZE}}} 97 98# Determine DATA_ALIGNMENT for the 5 variants, using 99# values specified in the emulparams/<emulation>.sh file or default. 100 101DATA_ALIGNMENT_="${DATA_ALIGNMENT_-${DATA_ALIGNMENT-ALIGN(${SEGMENT_SIZE})}}" 102DATA_ALIGNMENT_n="${DATA_ALIGNMENT_n-${DATA_ALIGNMENT_}}" 103DATA_ALIGNMENT_N="${DATA_ALIGNMENT_N-${DATA_ALIGNMENT-.}}" 104DATA_ALIGNMENT_r="${DATA_ALIGNMENT_r-${DATA_ALIGNMENT-}}" 105DATA_ALIGNMENT_u="${DATA_ALIGNMENT_u-${DATA_ALIGNMENT_r}}" 106 107LD_FLAG=r 108DATA_ALIGNMENT=${DATA_ALIGNMENT_r} 109DEFAULT_DATA_ALIGNMENT="ALIGN(${SEGMENT_SIZE})" 110( echo "/* Script for ld -r: link without relocation */" 111 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME} 112 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc 113) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xr 114 115LD_FLAG=u 116DATA_ALIGNMENT=${DATA_ALIGNMENT_u} 117CONSTRUCTING=" " 118( echo "/* Script for ld -Ur: link w/out relocation, do create constructors */" 119 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME} 120 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc 121) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xu 122 123LD_FLAG= 124DATA_ALIGNMENT=${DATA_ALIGNMENT_} 125RELOCATING=" " 126( echo "/* Default linker script, for normal executables */" 127 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME} 128 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc 129) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.x 130 131LD_FLAG=n 132DATA_ALIGNMENT=${DATA_ALIGNMENT_n} 133TEXT_START_ADDR=${NONPAGED_TEXT_START_ADDR-${TEXT_START_ADDR}} 134( echo "/* Script for -n: mix text and data on same page */" 135 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME} 136 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc 137) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xn 138 139LD_FLAG=N 140DATA_ALIGNMENT=${DATA_ALIGNMENT_N} 141( echo "/* Script for -N: mix text and data on same page; don't align data */" 142 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME} 143 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc 144) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xbn 145 146if test -n "$GENERATE_COMBRELOC_SCRIPT"; then 147 DATA_ALIGNMENT=${DATA_ALIGNMENT_c-${DATA_ALIGNMENT_}} 148 LD_FLAG=c 149 COMBRELOC=ldscripts/${EMULATION_NAME}.xc.tmp 150 ( echo "/* Script for -z combreloc: combine and sort reloc sections */" 151 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME} 152 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc 153 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xc 154 rm -f ${COMBRELOC} 155 COMBRELOC= 156fi 157 158if test -n "$GENERATE_SHLIB_SCRIPT"; then 159 LD_FLAG=shared 160 DATA_ALIGNMENT=${DATA_ALIGNMENT_s-${DATA_ALIGNMENT_}} 161 CREATE_SHLIB=" " 162 # Note that TEXT_START_ADDR is set to NONPAGED_TEXT_START_ADDR. 163 ( 164 echo "/* Script for ld --shared: link shared library */" 165 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME} 166 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc 167 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xs 168 if test -n "$GENERATE_COMBRELOC_SCRIPT"; then 169 LD_FLAG=cshared 170 DATA_ALIGNMENT=${DATA_ALIGNMENT_sc-${DATA_ALIGNMENT}} 171 COMBRELOC=ldscripts/${EMULATION_NAME}.xc.tmp 172 ( echo "/* Script for --shared -z combreloc: shared library, combine & sort relocs */" 173 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME} 174 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc 175 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xsc 176 rm -f ${COMBRELOC} 177 COMBRELOC= 178 fi 179 unset CREATE_SHLIB 180fi 181 182if test -n "$GENERATE_PIE_SCRIPT"; then 183 LD_FLAG=pie 184 DATA_ALIGNMENT=${DATA_ALIGNMENT_s-${DATA_ALIGNMENT_}} 185 CREATE_PIE=" " 186 # Note that TEXT_START_ADDR is set to NONPAGED_TEXT_START_ADDR. 187 ( 188 echo "/* Script for ld -pie: link position independent executable */" 189 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME} 190 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc 191 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xd 192 if test -n "$GENERATE_COMBRELOC_SCRIPT"; then 193 LD_FLAG=cpie 194 DATA_ALIGNMENT=${DATA_ALIGNMENT_sc-${DATA_ALIGNMENT}} 195 COMBRELOC=ldscripts/${EMULATION_NAME}.xc.tmp 196 ( echo "/* Script for -pie -z combreloc: position independent executable, combine & sort relocs */" 197 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME} 198 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc 199 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xdc 200 rm -f ${COMBRELOC} 201 COMBRELOC= 202 fi 203 unset CREATE_PIE 204fi 205 206case " $EMULATION_LIBPATH " in 207 *" ${EMULATION_NAME} "*) COMPILE_IN=true;; 208esac 209 210# Generate e${EMULATION_NAME}.c. 211. ${srcdir}/emultempl/${TEMPLATE_NAME-generic}.em 212