From: David McCullough Date: Thu, 11 Jul 2002 14:09:32 +0000 (+0000) Subject: Clean up the absolute path problems in ld-elf2flt X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=c40c64a032264c256a37baa65cbbe4f0222b8ec1;p=elf2flt.git Clean up the absolute path problems in ld-elf2flt Tested with arm-elf toolchain build, apps build and run ok for me :-) --- diff --git a/Makefile.in b/Makefile.in index c7714d8..e3ac1f9 100644 --- a/Makefile.in +++ b/Makefile.in @@ -37,7 +37,7 @@ clean: -rm -f $(PROGS) *.[oa] distclean: clean - -rm -f Makefile config.log config.status config.cache + -rm -f Makefile config.log config.status config.cache ld-elf2flt install: $(INSTALL) -s -m 755 flthdr $(bindir)/$(TARGET)-flthdr diff --git a/configure b/configure index 8bfadf4..eec1333 100755 --- a/configure +++ b/configure @@ -1573,7 +1573,7 @@ done ac_given_srcdir=$srcdir ac_given_INSTALL="$INSTALL" -trap 'rm -fr `echo "Makefile" | sed "s/:[^ ]*//g"` conftest*; exit 1' 1 2 15 +trap 'rm -fr `echo "Makefile ld-elf2flt" | sed "s/:[^ ]*//g"` conftest*; exit 1' 1 2 15 EOF cat >> $CONFIG_STATUS <> $CONFIG_STATUS <> $CONFIG_STATUS <<\EOF for ac_file in .. $CONFIG_FILES; do if test "x$ac_file" != x..; then diff --git a/configure.in b/configure.in index a8a1762..45383a3 100644 --- a/configure.in +++ b/configure.in @@ -89,5 +89,5 @@ AC_SUBST(target_os) AC_SUBST(target_vendor) AC_SUBST(bfd_include_dir) -AC_OUTPUT(Makefile) +AC_OUTPUT(Makefile ld-elf2flt) diff --git a/ld-elf2flt b/ld-elf2flt deleted file mode 100755 index 600f4c4..0000000 --- a/ld-elf2flt +++ /dev/null @@ -1,141 +0,0 @@ -#!/bin/sh -# -# allow us to do flat processing if the flag -Welf2flt (or -elf2flt) to -# the 'C' compiler or linker respectively -# -# uses the env. var FLTFLAGS as extra parameters to pass to elf2flt -# arguments given like -Wl,-elf2flt="-b 10000 -v" are given before FLTFLAGS -# -# Install by renaming all m68k-elf-ld/ld to XXX.real, and put this -# script in their place. -# -# Copyright (C) 2002 David McCullough -# Copyright (C) 2000, Lineo. davidm@lineo.com -# - -LINKER="$0.real" # the original renamed-linker -ELF2FLT="`expr $0 : '\(.*\)ld'`elf2flt" -TOOLDIR="`dirname $0`" # let gcc find the tools for us -SHARED_ID="" -NEWLDSCRIPT="" - -# -# if we have the elf2flt options, run it -# - -if expr "$*" : ".*-elf2flt.*" > /dev/null -then - ARG1= - ARG2= - OFILE= - PIC= - SDIRS= - LDSCRIPT= - FINAL="yes" - MOVDAT= - - while [ $# -ne 0 ] - do - case "$1" in - - -elf2flt) ;; # we already know this - -elf2flt*)FLTFLAGS="`expr \"$1\" : '-elf2flt=\(.*\)'` $FLTFLAGS";; - - -move-rodata) - MOVDAT="y";; # Put rodata in ROM if possible - - -shared-lib-id) - shift; SHARED_ID="$1";; # Shared library ID - - -o) shift; OFILE="$1";; # the final outfile - -o*) OFILE="`expr \"$1\" : '-o\(.*\)'`";; - - -T) shift; LDSCRIPT="$1";; # they have a linker script - -c) shift; LDSCRIPT="$1";; - - -L) ARG1="$ARG1 $1" # remember search dirs - shift; - ARG1="$ARG1 $1" - SDIRS="$SDIRS -L$1" - ;; - -L*) ARG1="$ARG1 $1"; SDIRS="$SDIRS $1";; - - -EB) ARG1="$ARG1 $1"; SDIRS="$SDIRS $1";; # arm big endian - - -r|-Ur) FINAL="" # this is not a final link - ARG1="$ARG1 $1" - ;; - - *) ARG1="$ARG1 $1" - ;; - esac - shift - done - - if [ "$FINAL" = "yes" ] - then - NEWLDSCRIPT=`mktemp /tmp/flt-XXXXXX` - SEDOP=" -e s/^R_RODAT// -e /^W_RODAT/d" - if [ "$MOVDAT" ] - then - $LINKER -r -d -o $OFILE.elf2flt $ARG1 || exit $? - if [ "`m68k-elf-objdump -h $OFILE.elf2flt | \ - egrep -A1 '[.]rodata' | grep RELOC`" ] - then - echo "warning: .rodata section contains relocations" - else - SEDOP="-e /^R_RODAT/d -e s/^W_RODAT//" - fi - fi - if [ "$SHARED_ID" ] - then - # Massage the linker script into something useful. These - # regexps are ugly due to some bizzare shell quoting rules. - # SEDOP="$SEDOP -e \"s/ORIGIN = 0x0,/ORIGIN = 0x${SHARED_ID}000000,/\"" - # SEDOP="$SEDOP -e \"s/.text 0x0 :/.text 0x${SHARED_ID}000000 :/\"" - SEDOP="$SEDOP -e s/\\(ORIGIN.=.0\\)x0,/\\1x${SHARED_ID}000000,/" - SEDOP="$SEDOP -e s/\\([.]text.0\\)x0[^0-9]:/\\1x${SHARED_ID}000000:/" - - if [ "$SHARED_ID" -gt 0 ] - then - # Non application modules enter via main not _start - # SEDOP="$SEDOP -e 's/ENTRY (_start)/ENTRY (main)/'" - SEDOP="$SEDOP -e s/\\(ENTRY.\\)(_start)/\1(lib_main)/" - fi - - # Provide the magic parameter that defines the library data segment pointer offset - ARG1="$ARG1 -defsym _current_shared_library_a5_offset_=`expr ${SHARED_ID} '*' -4 - 4`" - fi - - # Provide a default linker script - [ -z "$LDSCRIPT" ] && LDSCRIPT="elf2flt.ld" - - # Reprocess the linker script as required. - # We do this in a subshell so a relatively pathed script can be found - ( cd /usr/local/m68k-elf/lib - sed $SEDOP < "$LDSCRIPT" > "$NEWLDSCRIPT" - ) - - $LINKER -r -d -o $OFILE.elf2flt $ARG1 || exit $? - $LINKER $SDIRS -T $NEWLDSCRIPT -Ur -o $OFILE.elf $OFILE.elf2flt || exit $? - $LINKER $SDIRS -T $NEWLDSCRIPT -o $OFILE.gdb $OFILE.elf2flt || exit $? - rm -f $OFILE.elf2flt - if grep _GLOBAL_OFFSET_TABLE_ $OFILE.gdb > /dev/null - then - $ELF2FLT $FLTFLAGS -o $OFILE -p $OFILE.gdb $OFILE.elf || exit $? - else - $ELF2FLT $FLTFLAGS -o $OFILE -r $OFILE.elf || exit $? - fi - rm -f $OFILE.elf # not needed for any reason - rm -f "$NEWLDSCRIPT" - exit 0 - fi - - exec $LINKER -o $OFILE $ARG1 -fi - -# -# otherwise pretend we aren't here -# - -exec $LINKER "$@" diff --git a/ld-elf2flt.in b/ld-elf2flt.in new file mode 100644 index 0000000..6c8f596 --- /dev/null +++ b/ld-elf2flt.in @@ -0,0 +1,145 @@ +#!/bin/sh +# +# allow us to do flat processing if the flag -Wl,-elf2flt or -elf2flt to +# the 'C' compiler or linker respectively +# +# uses the env. var FLTFLAGS as extra parameters to pass to elf2flt +# arguments given like -Wl,-elf2flt="-b 10000 -v" are given before FLTFLAGS +# +# Copyright (C) 2002 David McCullough +# Copyright (C) 2000, Lineo. davidm@lineo.com +# + +LINKER="$0.real" # the original renamed-linker +ELF2FLT="`expr $0 : '\(.*\)ld'`elf2flt" +TOOLDIR="`dirname $0`" # let gcc find the tools for us +SHARED_ID="" +NEWLDSCRIPT="" + +# +# if we have the elf2flt options, run it +# + +if expr "$*" : ".*-elf2flt.*" > /dev/null +then + ARG1= + ARG2= + OFILE= + PIC= + SDIRS= + LDSCRIPT= + FINAL="yes" + MOVDAT= + + while [ $# -ne 0 ] + do + case "$1" in + + -elf2flt) ;; # we already know this + -elf2flt*)FLTFLAGS="`expr \"$1\" : '-elf2flt=\(.*\)'` $FLTFLAGS";; + + -move-rodata) + MOVDAT="y";; # Put rodata in ROM if possible + + -shared-lib-id) + shift; SHARED_ID="$1";; # Shared library ID + + -o) shift; OFILE="$1";; # the final outfile + -o*) OFILE="`expr \"$1\" : '-o\(.*\)'`";; + + -T) shift; LDSCRIPT="$1";; # they have a linker script + -c) shift; LDSCRIPT="$1";; + + -L) ARG1="$ARG1 $1" # remember search dirs + shift; + ARG1="$ARG1 $1" + SDIRS="$SDIRS -L$1" + ;; + -L*) ARG1="$ARG1 $1"; SDIRS="$SDIRS $1";; + + -EB) ARG1="$ARG1 $1"; SDIRS="$SDIRS $1";; # arm big endian + + -r|-Ur) FINAL="" # this is not a final link + ARG1="$ARG1 $1" + ;; + + *) ARG1="$ARG1 $1" + ;; + esac + shift + done + + if [ "$FINAL" = "yes" ] + then + NEWLDSCRIPT=`mktemp /tmp/flt-XXXXXX` + SEDOP=" -e s/^R_RODAT// -e /^W_RODAT/d" + if [ "$MOVDAT" ] + then + $LINKER -r -d -o $OFILE.elf2flt $ARG1 || exit $? + if [ "`@target_alias@-objdump -h $OFILE.elf2flt | \ + egrep -A1 '[.]rodata' | grep RELOC`" ] + then + echo "warning: .rodata section contains relocations" + else + SEDOP="-e /^R_RODAT/d -e s/^W_RODAT//" + fi + fi + if [ "$SHARED_ID" ] + then + # Massage the linker script into something useful. These + # regexps are ugly due to some bizzare shell quoting rules. + # SEDOP="$SEDOP -e \"s/ORIGIN = 0x0,/ORIGIN = 0x${SHARED_ID}000000,/\"" + # SEDOP="$SEDOP -e \"s/.text 0x0 :/.text 0x${SHARED_ID}000000 :/\"" + SEDOP="$SEDOP -e s/\\(ORIGIN.=.0\\)x0,/\\1x${SHARED_ID}000000,/" + SEDOP="$SEDOP -e s/\\([.]text.0\\)x0[^0-9]:/\\1x${SHARED_ID}000000:/" + + if [ "$SHARED_ID" -gt 0 ] + then + # Non application modules enter via main not _start + # SEDOP="$SEDOP -e 's/ENTRY (_start)/ENTRY (main)/'" + SEDOP="$SEDOP -e s/\\(ENTRY.\\)(_start)/\1(lib_main)/" + fi + + # Provide the magic parameter that defines the library data segment pointer offset + ARG1="$ARG1 -defsym _current_shared_library_a5_offset_=`expr ${SHARED_ID} '*' -4 - 4`" + fi + + # provide a default linker script, we usually need one + [ -z "$LDSCRIPT" ] && LDSCRIPT="@prefix@/@target_alias@/lib/elf2flt.ld" + + # if we can find the linker script we preprocess it, otherwise + # we assume the user knows what they are doing + if [ -f "$LDSCRIPT" ]; then + sed $SEDOP < "$LDSCRIPT" > "$NEWLDSCRIPT" + LDSCRIPT="$NEWLDSCRIPT" + elif [ -f "@prefix@/@target_alias@/lib/$LDSCRIPT" ]; then + sed $SEDOP < "@prefix@/@target_alias@/lib/$LDSCRIPT" > "$NEWLDSCRIPT" + LDSCRIPT="$NEWLDSCRIPT" + elif [ -f "@prefix@/@target_alias@/lib/ldscripts/$LDSCRIPT" ]; then + sed $SEDOP < "@prefix@/@target_alias@/lib/ldscripts/$LDSCRIPT" > "$NEWLDSCRIPT" + LDSCRIPT="$NEWLDSCRIPT" + fi + + $LINKER -r -d -o $OFILE.elf2flt $ARG1 || exit $? + $LINKER $SDIRS -T $LDSCRIPT -Ur -o $OFILE.elf $OFILE.elf2flt || exit $? + $LINKER $SDIRS -T $LDSCRIPT -o $OFILE.gdb $OFILE.elf2flt || exit $? + rm -f $OFILE.elf2flt + if grep _GLOBAL_OFFSET_TABLE_ $OFILE.gdb > /dev/null + then + $ELF2FLT $FLTFLAGS -o $OFILE -p $OFILE.gdb $OFILE.elf || exit $? + else + $ELF2FLT $FLTFLAGS -o $OFILE -r $OFILE.elf || exit $? + fi + rm -f $OFILE.elf # not needed for any reason + rm -f "$NEWLDSCRIPT" + exit 0 + fi + + exec $LINKER -o $OFILE $ARG1 +fi + +# +# otherwise pretend we aren't here +# + +exec $LINKER "$@"