]> git.wh0rd.org Git - elf2flt.git/commitdiff
Clean up the absolute path problems in ld-elf2flt
authorDavid McCullough <davidm@snapgear.com>
Thu, 11 Jul 2002 14:09:32 +0000 (14:09 +0000)
committerDavid McCullough <davidm@snapgear.com>
Thu, 11 Jul 2002 14:09:32 +0000 (14:09 +0000)
Tested with arm-elf toolchain build,  apps build
and run ok for me :-)

Makefile.in
configure
configure.in
ld-elf2flt [deleted file]
ld-elf2flt.in [new file with mode: 0644]

index c7714d833e1d2b9b3606a44143eb5f39914b18a3..e3ac1f927f7d95ccb2e76070c317abaac7d7b2bf 100644 (file)
@@ -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
index 8bfadf43ff21653b3a119efb7281ae1a75774b28..eec133344a8be3fb93484e873605b0f74fdef213 100755 (executable)
--- 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 <<EOF
 
@@ -1662,7 +1662,7 @@ EOF
 
 cat >> $CONFIG_STATUS <<EOF
 
-CONFIG_FILES=\${CONFIG_FILES-"Makefile"}
+CONFIG_FILES=\${CONFIG_FILES-"Makefile ld-elf2flt"}
 EOF
 cat >> $CONFIG_STATUS <<\EOF
 for ac_file in .. $CONFIG_FILES; do if test "x$ac_file" != x..; then
index a8a176296689bb2c99407a8c2658a4e34b655d68..45383a3b94ce7498210a3c5bdb761851d602846a 100644 (file)
@@ -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 (executable)
index 600f4c4..0000000
+++ /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 <davidm@snapgear.com>
-# 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 (file)
index 0000000..6c8f596
--- /dev/null
@@ -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 <davidm@snapgear.com>
+# 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 "$@"