genscripts.sh revision 92237
152939Sjb#!/bin/sh 252939Sjb# genscripts.sh - generate the ld-emulation-target specific files 352939Sjb# 452939Sjb# Usage: genscripts.sh srcdir libdir host target target_alias \ 552939Sjb# default_emulation native_lib_dirs this_emulation 652939Sjb# 752939Sjb# Sample usage: 852939Sjb# genscripts.sh /djm/ld-devo/devo/ld /usr/local/lib sparc-sun-sunos4.1.3 \ 952939Sjb# sparc-sun-sunos4.1.3 sparc-sun-sunos4.1.3 sun4 "" sun3 sparc-sun-sunos4.1.3 1052939Sjb# produces sun3.x sun3.xbn sun3.xn sun3.xr sun3.xu em_sun3.c 1152939Sjb# 1252939Sjb# $FreeBSD: head/gnu/usr.bin/binutils/ld/genscripts.sh 92237 2002-03-13 18:26:59Z obrien $ 1352939Sjb# 1452939Sjb# This is a cut-down version of the GNU script. Instead of jumping through 1552939Sjb# hoops for all possible combinations of paths, just use the libdir 1652939Sjb# argument in place of LIB_PATH. 1752939Sjb# 1852939Sjb# The host, target and target_alias arguments are not used in this version. 1952939Sjb# 2052939Sjb 2152939Sjbsrcdir=$1 2252939Sjblibdir=$2 2352939Sjbhost=$3 2452939Sjbtarget=$4 2552939Sjbtarget_alias=$5 2660777SobrienEMULATION_LIBPATH=$6 2752939SjbNATIVE_LIB_DIRS=$7 2852939SjbEMULATION_NAME=$8 2952939Sjb 3052939Sjb# Include the emulation-specific parameters: 3152939Sjb. ${srcdir}/emulparams/${EMULATION_NAME}.sh 3252939Sjb 3352939Sjbif test -d ldscripts; then 3452939Sjb true 3552939Sjbelse 3652939Sjb mkdir ldscripts 3752939Sjbfi 3852939Sjb 3960777Sobrien# Set the library search path, for libraries named by -lfoo. 4060777Sobrien# If LIB_PATH is defined (e.g., by Makefile) and non-empty, it is used. 4160777Sobrien# Otherwise, the default is set here. 4260777Sobrien# 4360777Sobrien# The format is the usual list of colon-separated directories. 4460777Sobrien# To force a logically empty LIB_PATH, do LIBPATH=":". 4560777Sobrien 4652939SjbLIB_SEARCH_DIRS=`echo ${libdir} | tr ':' ' ' | sed -e 's/\([^ ][^ ]*\)/SEARCH_DIR(\1);/g'` 4752939Sjb 4852939Sjb# Generate 5 or 6 script files from a master script template in 4952939Sjb# ${srcdir}/scripttempl/${SCRIPT_NAME}.sh. Which one of the 5 or 6 5052939Sjb# script files is actually used depends on command line options given 5152939Sjb# to ld. (SCRIPT_NAME was set in the emulparams_file.) 5252939Sjb# 5352939Sjb# A .x script file is the default script. 5452939Sjb# A .xr script is for linking without relocation (-r flag). 5552939Sjb# A .xu script is like .xr, but *do* create constructors (-Ur flag). 5652939Sjb# A .xn script is for linking with -n flag (mix text and data on same page). 5752939Sjb# A .xbn script is for linking with -N flag (mix text and data on same page). 5852939Sjb# A .xs script is for generating a shared library with the --shared 5952939Sjb# flag; it is only generated if $GENERATE_SHLIB_SCRIPT is set by the 6052939Sjb# emulation parameters. 6192237Sobrien# A .xc script is for linking with -z combreloc; it is only generated if 6292237Sobrien# $GENERATE_COMBRELOC_SCRIPT is set by the emulation parameters or 6392237Sobrien# $SCRIPT_NAME is "elf". 6492237Sobrien# A .xsc script is for linking with --shared -z combreloc; it is generated 6592237Sobrien# if $GENERATE_COMBRELOC_SCRIPT is set by the emulation parameters or 6692237Sobrien# $SCRIPT_NAME is "elf" and $GENERATE_SHLIB_SCRIPT is set by the emulation 6792237Sobrien# parameters too. 6852939Sjb 6992237Sobrienif [ "x$SCRIPT_NAME" = "xelf" ]; then 7092237Sobrien GENERATE_COMBRELOC_SCRIPT=yes 7192237Sobrienfi 7292237Sobrien 7352939SjbSEGMENT_SIZE=${SEGMENT_SIZE-${TARGET_PAGE_SIZE}} 7452939Sjb 7552939Sjb# Determine DATA_ALIGNMENT for the 5 variants, using 7652939Sjb# values specified in the emulparams/<emulation>.sh file or default. 7752939Sjb 7852939SjbDATA_ALIGNMENT_="${DATA_ALIGNMENT_-${DATA_ALIGNMENT-ALIGN(${SEGMENT_SIZE})}}" 7952939SjbDATA_ALIGNMENT_n="${DATA_ALIGNMENT_n-${DATA_ALIGNMENT_}}" 8052939SjbDATA_ALIGNMENT_N="${DATA_ALIGNMENT_N-${DATA_ALIGNMENT-.}}" 8152939SjbDATA_ALIGNMENT_r="${DATA_ALIGNMENT_r-${DATA_ALIGNMENT-}}" 8252939SjbDATA_ALIGNMENT_u="${DATA_ALIGNMENT_u-${DATA_ALIGNMENT_r}}" 8352939Sjb 8452939SjbLD_FLAG=r 8552939SjbDATA_ALIGNMENT=${DATA_ALIGNMENT_r} 8652939SjbDEFAULT_DATA_ALIGNMENT="ALIGN(${SEGMENT_SIZE})" 8792237Sobrien( echo "/* Script for ld -r: link without relocation */" 8892237Sobrien . ${srcdir}/emulparams/${EMULATION_NAME}.sh 8992237Sobrien . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc 9092237Sobrien) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xr 9152939Sjb 9252939SjbLD_FLAG=u 9352939SjbDATA_ALIGNMENT=${DATA_ALIGNMENT_u} 9452939SjbCONSTRUCTING=" " 9592237Sobrien( echo "/* Script for ld -Ur: link w/out relocation, do create constructors */" 9692237Sobrien . ${srcdir}/emulparams/${EMULATION_NAME}.sh 9792237Sobrien . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc 9892237Sobrien) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xu 9952939Sjb 10052939SjbLD_FLAG= 10152939SjbDATA_ALIGNMENT=${DATA_ALIGNMENT_} 10252939SjbRELOCATING=" " 10392237Sobrien( echo "/* Default linker script, for normal executables */" 10492237Sobrien . ${srcdir}/emulparams/${EMULATION_NAME}.sh 10592237Sobrien . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc 10692237Sobrien) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.x 10752939Sjb 10852939SjbLD_FLAG=n 10952939SjbDATA_ALIGNMENT=${DATA_ALIGNMENT_n} 11052939SjbTEXT_START_ADDR=${NONPAGED_TEXT_START_ADDR-${TEXT_START_ADDR}} 11192237Sobrien( echo "/* Script for -n: mix text and data on same page */" 11292237Sobrien . ${srcdir}/emulparams/${EMULATION_NAME}.sh 11392237Sobrien . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc 11492237Sobrien) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xn 11552939Sjb 11652939SjbLD_FLAG=N 11752939SjbDATA_ALIGNMENT=${DATA_ALIGNMENT_N} 11892237Sobrien( echo "/* Script for -N: mix text and data on same page; don't align data */" 11992237Sobrien . ${srcdir}/emulparams/${EMULATION_NAME}.sh 12092237Sobrien . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc 12192237Sobrien) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xbn 12252939Sjb 12392237Sobrienif test -n "$GENERATE_COMBRELOC_SCRIPT"; then 12492237Sobrien DATA_ALIGNMENT=${DATA_ALIGNMENT_c-${DATA_ALIGNMENT_}} 12592237Sobrien LD_FLAG=c 12692237Sobrien COMBRELOC=ldscripts/${EMULATION_NAME}.xc.tmp 12792237Sobrien ( echo "/* Script for -z combreloc: combine and sort reloc sections */" 12892237Sobrien . ${srcdir}/emulparams/${EMULATION_NAME}.sh 12992237Sobrien . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc 13092237Sobrien ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xc 13192237Sobrien rm -f ${COMBRELOC} 13292237Sobrien COMBRELOC= 13392237Sobrienfi 13492237Sobrien 13552939Sjbif test -n "$GENERATE_SHLIB_SCRIPT"; then 13652939Sjb LD_FLAG=shared 13752939Sjb DATA_ALIGNMENT=${DATA_ALIGNMENT_s-${DATA_ALIGNMENT_}} 13852939Sjb CREATE_SHLIB=" " 13952939Sjb # Note that TEXT_START_ADDR is set to NONPAGED_TEXT_START_ADDR. 14092237Sobrien ( 14192237Sobrien echo "/* Script for ld --shared: link shared library */" 14292237Sobrien . ${srcdir}/emulparams/${EMULATION_NAME}.sh 14392237Sobrien . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc 14492237Sobrien ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xs 14592237Sobrien if test -n "$GENERATE_COMBRELOC_SCRIPT"; then 14692237Sobrien LD_FLAG=cshared 14792237Sobrien DATA_ALIGNMENT=${DATA_ALIGNMENT_sc-${DATA_ALIGNMENT}} 14892237Sobrien COMBRELOC=ldscripts/${EMULATION_NAME}.xc.tmp 14992237Sobrien ( echo "/* Script for --shared -z combreloc: shared library, combine & sort relocs */" 15092237Sobrien . ${srcdir}/emulparams/${EMULATION_NAME}.sh 15192237Sobrien . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc 15292237Sobrien ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xsc 15392237Sobrien rm -f ${COMBRELOC} 15492237Sobrien COMBRELOC= 15592237Sobrien fi 15652939Sjbfi 15752939Sjb 15860777Sobrienfor i in $EMULATION_LIBPATH ; do 15960777Sobrien test "$i" = "$EMULATION_NAME" && COMPILE_IN=true 16060777Sobriendone 16152939Sjb# Generate e${EMULATION_NAME}.c. 16252939Sjb. ${srcdir}/emultempl/${TEMPLATE_NAME-generic}.em 163