genscripts.sh revision 204548
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 204548 2010-03-02 05:43:04Z 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 rm -f ldscripts 54 mkdir ldscripts 55fi 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 72LIB_SEARCH_DIRS=`echo ${libdir} | sed -e 's/:/ /g' -e 's/\([^ ][^ ]*\)/SEARCH_DIR(\1);/g'` 73#2.13: LIB_SEARCH_DIRS=`echo ${libdir} | sed -e 's/:/ /g' -e 's/\([^ ][^ ]*\)/SEARCH_DIR(\\"\1\\");/g'` 74 75# Generate 5 or 6 script files from a master script template in 76# ${srcdir}/scripttempl/${SCRIPT_NAME}.sh. Which one of the 5 or 6 77# script files is actually used depends on command line options given 78# to ld. (SCRIPT_NAME was set in the emulparams_file.) 79# 80# A .x script file is the default script. 81# A .xr script is for linking without relocation (-r flag). 82# A .xu script is like .xr, but *do* create constructors (-Ur flag). 83# A .xn script is for linking with -n flag (mix text and data on same page). 84# A .xbn script is for linking with -N flag (mix text and data on same page). 85# A .xs script is for generating a shared library with the --shared 86# flag; it is only generated if $GENERATE_SHLIB_SCRIPT is set by the 87# emulation parameters. 88# A .xc script is for linking with -z combreloc; it is only generated if 89# $GENERATE_COMBRELOC_SCRIPT is set by the emulation parameters or 90# $SCRIPT_NAME is "elf". 91# A .xsc script is for linking with --shared -z combreloc; it is generated 92# if $GENERATE_COMBRELOC_SCRIPT is set by the emulation parameters or 93# $SCRIPT_NAME is "elf" and $GENERATE_SHLIB_SCRIPT is set by the emulation 94# parameters too. 95 96if [ "x$SCRIPT_NAME" = "xelf" ]; then 97 GENERATE_COMBRELOC_SCRIPT=yes 98fi 99 100#2.13: SEGMENT_SIZE=${SEGMENT_SIZE-${TARGET_PAGE_SIZE}} 101SEGMENT_SIZE=${SEGMENT_SIZE-${MAXPAGESIZE-${TARGET_PAGE_SIZE}}} 102 103# Determine DATA_ALIGNMENT for the 5 variants, using 104# values specified in the emulparams/<emulation>.sh file or default. 105 106DATA_ALIGNMENT_="${DATA_ALIGNMENT_-${DATA_ALIGNMENT-ALIGN(${SEGMENT_SIZE})}}" 107DATA_ALIGNMENT_n="${DATA_ALIGNMENT_n-${DATA_ALIGNMENT_}}" 108DATA_ALIGNMENT_N="${DATA_ALIGNMENT_N-${DATA_ALIGNMENT-.}}" 109DATA_ALIGNMENT_r="${DATA_ALIGNMENT_r-${DATA_ALIGNMENT-}}" 110DATA_ALIGNMENT_u="${DATA_ALIGNMENT_u-${DATA_ALIGNMENT_r}}" 111 112LD_FLAG=r 113DATA_ALIGNMENT=${DATA_ALIGNMENT_r} 114DEFAULT_DATA_ALIGNMENT="ALIGN(${SEGMENT_SIZE})" 115( echo "/* Script for ld -r: link without relocation */" 116 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME} 117 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc 118) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xr 119 120LD_FLAG=u 121DATA_ALIGNMENT=${DATA_ALIGNMENT_u} 122CONSTRUCTING=" " 123( echo "/* Script for ld -Ur: link w/out relocation, do create constructors */" 124 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME} 125 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc 126) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xu 127 128LD_FLAG= 129DATA_ALIGNMENT=${DATA_ALIGNMENT_} 130RELOCATING=" " 131( echo "/* Default linker script, for normal executables */" 132 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME} 133 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc 134) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.x 135 136LD_FLAG=n 137DATA_ALIGNMENT=${DATA_ALIGNMENT_n} 138TEXT_START_ADDR=${NONPAGED_TEXT_START_ADDR-${TEXT_START_ADDR}} 139( echo "/* Script for -n: mix text and data on same page */" 140 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME} 141 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc 142) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xn 143 144LD_FLAG=N 145DATA_ALIGNMENT=${DATA_ALIGNMENT_N} 146( echo "/* Script for -N: mix text and data on same page; don't align data */" 147 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME} 148 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc 149) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xbn 150 151if test -n "$GENERATE_COMBRELOC_SCRIPT"; then 152 DATA_ALIGNMENT=${DATA_ALIGNMENT_c-${DATA_ALIGNMENT_}} 153 LD_FLAG=c 154 COMBRELOC=ldscripts/${EMULATION_NAME}.xc.tmp 155 ( echo "/* Script for -z combreloc: combine and sort reloc sections */" 156 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME} 157 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc 158 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xc 159 rm -f ${COMBRELOC} 160 COMBRELOC= 161fi 162 163if test -n "$GENERATE_SHLIB_SCRIPT"; then 164 LD_FLAG=shared 165 DATA_ALIGNMENT=${DATA_ALIGNMENT_s-${DATA_ALIGNMENT_}} 166 CREATE_SHLIB=" " 167 # Note that TEXT_START_ADDR is set to NONPAGED_TEXT_START_ADDR. 168 ( 169 echo "/* Script for ld --shared: link shared library */" 170 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME} 171 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc 172 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xs 173 if test -n "$GENERATE_COMBRELOC_SCRIPT"; then 174 LD_FLAG=cshared 175 DATA_ALIGNMENT=${DATA_ALIGNMENT_sc-${DATA_ALIGNMENT}} 176 COMBRELOC=ldscripts/${EMULATION_NAME}.xc.tmp 177 ( echo "/* Script for --shared -z combreloc: shared library, combine & sort relocs */" 178 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME} 179 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc 180 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xsc 181 rm -f ${COMBRELOC} 182 COMBRELOC= 183 fi 184 unset CREATE_SHLIB 185fi 186 187if test -n "$GENERATE_PIE_SCRIPT"; then 188 LD_FLAG=pie 189 DATA_ALIGNMENT=${DATA_ALIGNMENT_s-${DATA_ALIGNMENT_}} 190 CREATE_PIE=" " 191 # Note that TEXT_START_ADDR is set to NONPAGED_TEXT_START_ADDR. 192 ( 193 echo "/* Script for ld -pie: link position independent executable */" 194 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME} 195 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc 196 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xd 197 if test -n "$GENERATE_COMBRELOC_SCRIPT"; then 198 LD_FLAG=cpie 199 DATA_ALIGNMENT=${DATA_ALIGNMENT_sc-${DATA_ALIGNMENT}} 200 COMBRELOC=ldscripts/${EMULATION_NAME}.xc.tmp 201 ( echo "/* Script for -pie -z combreloc: position independent executable, combine & sort relocs */" 202 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME} 203 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc 204 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xdc 205 rm -f ${COMBRELOC} 206 COMBRELOC= 207 fi 208 unset CREATE_PIE 209fi 210 211case " $EMULATION_LIBPATH " in 212 *" ${EMULATION_NAME} "*) COMPILE_IN=true;; 213esac 214 215# Generate e${EMULATION_NAME}.c. 216. ${srcdir}/emultempl/${TEMPLATE_NAME-generic}.em 217