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