This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Re: linker SEARCH_DIR order
- From: Alan Modra <amodra at bigpond dot net dot au>
- To: David O'Brien <obrien at FreeBSD dot org>
- Cc: binutils at sources dot redhat dot com
- Date: Wed, 22 May 2002 18:11:53 +0930
- Subject: Re: linker SEARCH_DIR order
- References: <20020430220340.A46148@dragon.nuxi.com>
On Tue, Apr 30, 2002 at 10:03:40PM -0700, David O'Brien wrote:
> On Wed, May 01, 2002 at 12:48:03PM +0930, Alan Modra wrote:
> > On Mon, Apr 29, 2002 at 12:17:56PM -0700, David O'Brien wrote:
> > > I am very iffy on /usr/local/lib being anywhere but at the end of the
> > > search list.
> >
> > Why? Isn't /usr/local where people are supposed to install new
> > binaries, libs etc., to override those in / and /usr ?
>
> I am of the school that there should be no overlap between /usr/lib and
> /usr/local/lib -- any overlap is due to a poorly written 3rd party
> application. If one really wants /usr/local to take precedence, it
> should be explicitly specified.
>
> With the 6000+ 3rd party packages in the FreeBSD Ports Collection, you
> would be amazed how many times we see things in /usr/local that we really
> don't want to be used over the system bits.
This moves everything but $libdir and $tool_dir to NATIVE_LIB_DIRS,
set in configure.host, instead of adding /lib,/usr/lib,/usr/local/lib
in genscripts.sh. I've changed the search order to $tool_dir,
$libdir, /usr/local/lib, /lib, /usr/lib for most targets because
that most closely matches gcc. FreeBSD gets to search /usr/local/lib
last. We can accommodate any particular search order desired. :)
ld/ChangeLog
* genscripts.sh (LIB_PATH): For native targets, concatenate $libdir
and $NATIVE_LIB_DIRS. Add $tool_lib before other libs.
(LIB_SEARCH_DIRS): No need to use "tr".
(COMPILE_IN): Only set for native targets.
* configure.host (NATIVE_LIB_DIRS): Specify all native search dirs
here, rather than adding lib:/usr/lib:/usr/local/lib in genscripts.sh.
* configure.tgt (powerpc*): Set tdir_*.
(powerpcle*): Correct targ_extra_emuls.
* emulparams/elf32ppc.sh (LIB_PATH): Set up native 64 bit dirs.
* emulparams/elf64ppc.sh (LIB_PATH): Likewise.
Index: ld/genscripts.sh
===================================================================
RCS file: /cvs/src/src/ld/genscripts.sh,v
retrieving revision 1.8
diff -u -p -r1.8 genscripts.sh
--- ld/genscripts.sh 21 Mar 2002 05:35:39 -0000 1.8
+++ ld/genscripts.sh 22 May 2002 07:56:21 -0000
@@ -45,31 +45,25 @@ fi
# To force a logically empty LIB_PATH, do LIBPATH=":".
if [ "x${LIB_PATH}" = "x" ] ; then
- # Cross, or native non-default emulation not requesting LIB_PATH.
- LIB_PATH=
-
if [ "x${host}" = "x${target}" ] ; then
case " $EMULATION_LIBPATH " in
*" ${EMULATION_NAME} "*)
# Native, and default or emulation requesting LIB_PATH.
- LIB_PATH=/lib:/usr/lib
- if [ -n "${NATIVE_LIB_DIRS}" ]; then
- LIB_PATH=${LIB_PATH}:${NATIVE_LIB_DIRS}
- fi
- if [ "${libdir}" != /usr/lib ]; then
- LIB_PATH=${LIB_PATH}:${libdir}
- fi
- if [ "${libdir}" != /usr/local/lib ] ; then
- LIB_PATH=${LIB_PATH}:/usr/local/lib
- fi
+ LIB_PATH=${libdir}
+ for lib in ${NATIVE_LIB_DIRS}; do
+ case :${LIB_PATH}: in
+ *:${lib}:*) ;;
+ *) LIB_PATH=${LIB_PATH}:${lib} ;;
+ esac
+ done
esac
fi
fi
# Always search $(tooldir)/lib, aka /usr/local/TARGET/lib.
-LIB_PATH=${LIB_PATH}:${tool_lib}
+LIB_PATH=${tool_lib}:${LIB_PATH}
-LIB_SEARCH_DIRS=`echo ${LIB_PATH} | tr ':' ' ' | sed -e 's/\([^ ][^ ]*\)/SEARCH_DIR(\\"\1\\");/g'`
+LIB_SEARCH_DIRS=`echo ${LIB_PATH} | sed -e 's/:/ /g' -e 's/\([^ ][^ ]*\)/SEARCH_DIR(\\"\1\\");/g'`
# Generate 5 or 6 script files from a master script template in
# ${srcdir}/scripttempl/${SCRIPT_NAME}.sh. Which one of the 5 or 6
@@ -181,9 +175,9 @@ if test -n "$GENERATE_SHLIB_SCRIPT"; the
fi
fi
-for i in $EMULATION_LIBPATH ; do
- test "$i" = "$EMULATION_NAME" && COMPILE_IN=true
-done
+case " $EMULATION_LIBPATH " in
+ *" ${EMULATION_NAME} "*) COMPILE_IN=true;;
+esac
# Generate e${EMULATION_NAME}.c.
. ${srcdir}/emultempl/${TEMPLATE_NAME-generic}.em
Index: ld/configure.host
===================================================================
RCS file: /cvs/src/src/ld/configure.host,v
retrieving revision 1.20
diff -u -p -r1.20 configure.host
--- ld/configure.host 7 Apr 2002 13:57:53 -0000 1.20
+++ ld/configure.host 22 May 2002 08:05:04 -0000
@@ -12,7 +12,7 @@
HDEFINES=
HOSTING_CRT0=/lib/crt0.o
HOSTING_LIBS='`if [ -f ../gcc/libgcc.a ]; then libgcc=../gcc/libgcc.a; else libgcc=\`${CC} -print-libgcc-file-name\`; fi; if [ -f ../gcc/libgcc_eh.a ]; then libgcc="$libgcc ../gcc/libgcc_eh.a"; else libgcc_eh=\`${CC} -print-file-name=libgcc_eh.a\`; if [ x"$libgcc_eh" != xlibgcc_eh.a ]; then libgcc="$libgcc $libgcc_eh"; fi; fi; echo $libgcc -lc $libgcc`'
-NATIVE_LIB_DIRS=
+NATIVE_LIB_DIRS='/usr/local/lib /lib /usr/lib'
#
# Generic configurations:
@@ -21,7 +21,7 @@ NATIVE_LIB_DIRS=
case "${host}" in
*-*-freebsd*)
- NATIVE_LIB_DIRS=/usr/lib
+ NATIVE_LIB_DIRS='/lib /usr/lib /usr/local/lib'
# Older versions of gcc do not use a specs file. In those cases,
# gcc -print-file-name=specs will simply print specs. We create a
# dummy specs files to handle this.
@@ -57,11 +57,6 @@ case "${host}" in
;;
alpha*-*-netbsd*)
- # The new BSD `make' has a bug: it doesn't pass empty arguments in
- # shell commands. So we need to make this value non-empty in order
- # for the genscripts.sh call to work. There's nothing magic about
- # the value `/lib'; it's just a dummy.
- NATIVE_LIB_DIRS=/lib
HOSTING_CRT0=/usr/lib/crt0.o
;;
@@ -70,18 +65,13 @@ arm*-*-linux-gnu*)
;;
i[3456]86-*-bsd* | i[34567]86-*-freebsd[12] | i[34567]86-*-freebsd[12]\.* | i[34567]86-*-freebsd*aout* | i[3456]86-*-netbsd*)
- # The new BSD `make' has a bug: it doesn't pass empty arguments in
- # shell commands. So we need to make this value non-empty in order
- # for the genscripts.sh call to work. There's nothing magic about
- # the value `/lib'; it's just a dummy.
- NATIVE_LIB_DIRS=/lib
HOSTING_CRT0=/usr/lib/crt0.o
;;
i[3456]86-*-sysv4*)
HOSTING_CRT0='/usr/ccs/lib/crt1.o /usr/ccs/lib/crti.o /usr/ccs/lib/values-Xa.o `if [ -f ../gcc/crtbegin.o ]; then echo ../gcc/crtbegin.o; else ${CC} -print-file-name=crtbegin.o; fi`'
HOSTING_LIBS="$HOSTING_LIBS"' `if [ -f ../gcc/crtend.o ]; then echo ../gcc/crtend.o; else ${CC} -print-file-name=crtend.o; fi` /usr/ccs/lib/crtn.o'
- NATIVE_LIB_DIRS=/usr/ccs/lib
+ NATIVE_LIB_DIRS='/usr/local/lib /usr/ccs/lib /lib /usr/lib'
;;
i[3456]86-sequent-ptx* | i[3456]86-sequent-sysv*)
@@ -97,7 +87,7 @@ i[3456]86-*-sysv*)
i[3456]86-*-solaris*)
HOSTING_CRT0='`if [ -f ../gcc/crt1.o ]; then echo ../gcc/crt1.o; else ${CC} -print-file-name=crt1.o; fi` `if [ -f ../gcc/crti.o ]; then echo ../gcc/crti.o; else ${CC} -print-file-name=crti.o; fi` /usr/ccs/lib/values-Xa.o `if [ -f ../gcc/crtbegin.o ]; then echo ../gcc/crtbegin.o; else ${CC} -print-file-name=crtbegin.o; fi`'
HOSTING_LIBS="$HOSTING_LIBS"' `if [ -f ../gcc/crtend.o ]; then echo ../gcc/crtend.o; else ${CC} -print-file-name=crtend.o; fi` `if [ -f ../gcc/crtn.o ]; then echo ../gcc/crtn.o; else ${CC} -print-file-name=crtn.o; fi`'
- NATIVE_LIB_DIRS=/usr/ccs/lib
+ NATIVE_LIB_DIRS='/usr/local/lib /usr/ccs/lib /lib /usr/lib'
;;
i[3456]86-*-sco* | i[3456]86-*-isc*)
@@ -122,7 +112,7 @@ i[3456]86-*-lynxos*)
i[3456]86-pc-interix*)
HOSTING_CRT0='$$INTERIX_ROOT/usr/lib/crt0.o'
- NATIVE_LIB_DIRS='$$INTERIX_ROOT/usr/lib/'
+ NATIVE_LIB_DIRS='/usr/local/lib $$INTERIX_ROOT/usr/lib /lib /usr/lib'
HOSTING_LIBS='-L $$X/local_bin -L $$INTERIX_ROOT/usr/lib '"$HOSTING_LIBS"' -lcpsx -lc -lcpsx $$INTERIX_ROOT/usr/lib/psxdll.a $$INTERIX_ROOT/usr/lib/psxdll2.a'
;;
@@ -137,7 +127,7 @@ ia64-*-linux-gnu*)
ia64-*-aix*)
HOSTING_CRT0='-dynamic-linker `egrep "libc.so" \`${CC} --print-file-name=specs\` | sed -e "s,.*-dynamic-linker[ ][ ]*\(.*/libc.so..\).*,\1,"` `${CC} --print-file-name=crt1.o` `${CC} --print-file-name=crti.o` `if [ -f ../gcc/crtbegin.o ]; then echo ../gcc/crtbegin.o; else ${CC} --print-file-name=crtbegin.o; fi`'
HOSTING_LIBS='-L`dirname \`${CC} --print-file-name=libc.so\`` '"$HOSTING_LIBS"' `if [ -f ../gcc/crtend.o ]; then echo ../gcc/crtend.o; else ${CC} --print-file-name=crtend.o; fi` `${CC} --print-file-name=crtn.o`'
- NATIVE_LIB_DIRS=/usr/lib/ia64l64
+ NATIVE_LIB_DIRS='/usr/local/lib /usr/lib/ia64l64 /lib /usr/lib'
;;
mips*-dec-bsd*)
@@ -202,7 +192,7 @@ s390-*-linux-gnu*)
sparc*-*-solaris2*)
HOSTING_CRT0='`if [ -f ../gcc/crt1.o ]; then echo ../gcc/crt1.o; else ${CC} -print-file-name=crt1.o; fi` `if [ -f ../gcc/crti.o ]; then echo ../gcc/crti.o; else ${CC} -print-file-name=crti.o; fi` /usr/ccs/lib/values-Xa.o `if [ -f ../gcc/crtbegin.o ]; then echo ../gcc/crtbegin.o; else ${CC} -print-file-name=crtbegin.o; fi`'
HOSTING_LIBS="$HOSTING_LIBS"' `if [ -f ../gcc/crtend.o ]; then echo ../gcc/crtend.o; else ${CC} -print-file-name=crtend.o; fi` `if [ -f ../gcc/crtn.o ]; then echo ../gcc/crtn.o; else ${CC} -print-file-name=crtn.o; fi`'
- NATIVE_LIB_DIRS=/usr/ccs/lib
+ NATIVE_LIB_DIRS='/usr/local/lib /usr/ccs/lib /lib /usr/lib'
;;
sparc-*-linux-gnu*)
@@ -224,7 +214,6 @@ x86_64-*-linux-gnu*)
;;
*-*-netbsd*)
- NATIVE_LIB_DIRS=/usr/lib
# NetBSD typically does not use the GCC crtstuff, so ignore it.
HOSTING_CRT0='-dynamic-linker /usr/libexec/ld.elf_so /usr/lib/crt0.o /usr/lib/crtbegin.o'
HOSTING_LIBS='`if [ -f ../gcc/libgcc.a ] ; then echo ../gcc/libgcc.a ; else ${CC} -print-libgcc-file-name; fi` -lc `if [ -f ../gcc/libgcc.a ] ; then echo ../gcc/libgcc.a ; else ${CC} -print-libgcc-file-name; fi` /usr/lib/crtend.o'
@@ -232,7 +221,7 @@ x86_64-*-linux-gnu*)
alpha*-*-*)
HOSTING_CRT0=/usr/ccs/lib/crt0.o
- NATIVE_LIB_DIRS=/usr/ccs/lib
+ NATIVE_LIB_DIRS='/usr/local/lib /usr/ccs/lib /lib /usr/lib'
;;
romp-*-*)
Index: ld/configure.tgt
===================================================================
RCS file: /cvs/src/src/ld/configure.tgt,v
retrieving revision 1.87
diff -u -p -r1.87 configure.tgt
--- ld/configure.tgt 21 May 2002 15:11:00 -0000 1.87
+++ ld/configure.tgt 22 May 2002 07:56:21 -0000
@@ -396,7 +396,11 @@ powerpc-*-freebsd*) targ_emul=elf32ppc_f
powerpc*-*-linux*)
case "${targ}" in
*64*) targ_emul=elf64ppc
- targ_extra_emuls="elf32ppclinux elf32ppc elf32ppcsim" ;;
+ targ_extra_emuls="elf32ppclinux elf32ppc elf32ppcsim"
+ targ_extra_libpath=elf32ppclinux
+ tdir_elf32ppc=`echo "${targ_alias}" | sed -e 's/64//'`
+ tdir_elf32ppclinux=$tdir_elf32ppc
+ tdir_elf32ppcsim=$tdir_elf32ppc ;;
*) targ_emul=elf32ppclinux
targ_extra_emuls="elf32ppc elf32ppcsim"
targ_extra_libpath=elf32ppc ;;
@@ -405,7 +409,9 @@ powerpc*le-*-elf* | powerpc*le-*-eabi* |
| powerpc*le-*-sysv* | powerpc*le-*-vxworks*)
case "${targ}" in
*64*) targ_emul=elf64lppc
- targ_extra_emuls="elf32lppc elf32ppcsim" ;;
+ targ_extra_emuls="elf32lppc elf32lppcsim"
+ tdir_elf32lppc=`echo "${targ_alias}" | sed -e 's/64//'`
+ tdir_elf32lppcsim=$tdir_elf32lppc ;;
*) targ_emul=elf32lppc
targ_extra_emuls="elf32ppcsim" ;;
esac ;;
@@ -413,7 +419,10 @@ powerpc*-*-elf* | powerpc*-*-eabi* | pow
| powerpc*-*-netbsd* | powerpc*-*-vxworks*)
case "${targ}" in
*64*) targ_emul=elf64ppc
- targ_extra_emuls="elf32ppc elf32ppclinux elf32ppcsim" ;;
+ targ_extra_emuls="elf32ppc elf32ppclinux elf32ppcsim"
+ tdir_elf32ppc=`echo "${targ_alias}" | sed -e 's/64//'`
+ tdir_elf32ppclinux=$tdir_elf32ppc
+ tdir_elf32ppcsim=$tdir_elf32ppc ;;
*) targ_emul=elf32ppc
targ_extra_emuls="elf32ppclinux elf32ppcsim" ;;
esac ;;
Index: ld/emulparams/elf32ppc.sh
===================================================================
RCS file: /cvs/src/src/ld/emulparams/elf32ppc.sh,v
retrieving revision 1.5
diff -u -p -r1.5 elf32ppc.sh
--- ld/emulparams/elf32ppc.sh 22 Nov 2001 09:08:04 -0000 1.5
+++ ld/emulparams/elf32ppc.sh 22 May 2002 07:56:26 -0000
@@ -17,3 +17,22 @@ OTHER_READWRITE_SECTIONS="
.got1 ${RELOCATING-0} : { *(.got1) }
.got2 ${RELOCATING-0} : { *(.got2) }
"
+
+# Treat a host that matches the target with the possible exception of "64"
+# in the name as if it were native.
+if test `echo "$host" | sed -e s/64//` = `echo "$target" | sed -e s/64//`; then
+ case " $EMULATION_LIBPATH " in
+ *" ${EMULATION_NAME} "*)
+ LIB_PATH=${libdir}
+ for lib in ${NATIVE_LIB_DIRS}; do
+ case :${LIB_PATH}: in
+ *:${lib}:*) ;;
+ *) LIB_PATH=${LIB_PATH}:${lib} ;;
+ esac
+ done
+ # Look for 64 bit target libraries in /lib64, /usr/lib64 etc., first.
+ case "$EMULATION_NAME" in
+ *64*) LIB_PATH=`echo ${LIB_PATH}: | sed -e s,:,64:,g`$LIB_PATH
+ esac
+ esac
+fi
Index: ld/emulparams/elf64ppc.sh
===================================================================
RCS file: /cvs/src/src/ld/emulparams/elf64ppc.sh,v
retrieving revision 1.3
diff -u -p -r1.3 elf64ppc.sh
--- ld/emulparams/elf64ppc.sh 18 Feb 2002 12:40:28 -0000 1.3
+++ ld/emulparams/elf64ppc.sh 22 May 2002 07:56:26 -0000
@@ -28,3 +28,22 @@ OTHER_GOT_RELOC_SECTIONS="
OTHER_READWRITE_SECTIONS="
.toc1 ${RELOCATING-0}${RELOCATING+ALIGN(8)} : { *(.toc1) }
.opd ${RELOCATING-0}${RELOCATING+ALIGN(8)} : { *(.opd) }"
+
+# Treat a host that matches the target with the possible exception of "64"
+# in the name as if it were native.
+if test `echo "$host" | sed -e s/64//` = `echo "$target" | sed -e s/64//`; then
+ case " $EMULATION_LIBPATH " in
+ *" ${EMULATION_NAME} "*)
+ LIB_PATH=${libdir}
+ for lib in ${NATIVE_LIB_DIRS}; do
+ case :${LIB_PATH}: in
+ *:${lib}:*) ;;
+ *) LIB_PATH=${LIB_PATH}:${lib} ;;
+ esac
+ done
+ # Look for 64 bit target libraries in /lib64, /usr/lib64 etc., first.
+ case "$EMULATION_NAME" in
+ *64*) LIB_PATH=`echo ${LIB_PATH}: | sed -e s,:,64:,g`$LIB_PATH
+ esac
+ esac
+fi
--
Alan Modra
IBM OzLabs - Linux Technology Centre