This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
PR ld/2290, /etc/ld.so.conf search
- From: Alan Modra <amodra at bigpond dot net dot au>
- To: binutils at sourceware dot org
- Cc: ryanarn at us dot ibm dot com
- Date: Wed, 5 Apr 2006 23:50:17 +0930
- Subject: PR ld/2290, /etc/ld.so.conf search
HJ's http://sources.redhat.com/ml/binutils/2006-02/msg00097.html patch
broke one of our (IBM's) toolchain build scripts. Not that there's
anything particularly unusual about this script breaking. It seems to
happen regularly with every gcc/glibc version. :-(
What's unusual is that we are building an entire native toolchain,
binutils+gcc+glibc+gdb, that coexists with rather than replaces the
system binutils+gcc+glibc+gdb. Unfortunately, --with-sysroot doesn't
work when native, and we didn't want to mess around with a chroot.
Instead, we specify --prefix to a new area and hack gcc's specs file to
pass -rpath on linking so that all libraries and executables are built
with DT_RUNPATH pointing at the new lib dirs. With a few other minor
hacks this worked OK, until ld started looking in /etc/ld.so.conf paths
for DT_NEEDED libs before looking in its search path. /etc/ld.so.conf
of course specifies the system lib dirs instead of the new --prefix
rooted libs, and trying to link an old ld.so with a new libc.so results
in disaster.
I think the best solution to this problem is for ld to look in
${prefix}/etc/ld.so.conf, if it exists, before looking in
/etc/ld.so.conf. ${prefix}/etc/ld.so.conf happens to be the default
location of glibc's ld.so configuration file, except for --prefix=/usr
which uses /etc/ld.so.conf by default.
* Makefile.am (GENSCRIPTS): Pass prefix.
* Makefile.in: Regenerate.
* genscripts.sh: Adjust for extra parameter.
* emultempl/elf32.em (parse_ld_so_conf): Return true iff file
exists.
(check_ld_so_conf): Use ${prefix}/etc/ld.so.conf if it exists.
* NEWS: Update.
Index: ld/Makefile.am
===================================================================
RCS file: /cvs/src/src/ld/Makefile.am,v
retrieving revision 1.205
diff -u -p -r1.205 Makefile.am
--- ld/Makefile.am 26 Mar 2006 00:46:13 -0000 1.205
+++ ld/Makefile.am 5 Apr 2006 13:43:27 -0000
@@ -474,7 +474,7 @@ stringify.sed: ${srcdir}/emultempl/$(STR
# These all start with e so 'make clean' can find them.
-GENSCRIPTS = LIB_PATH='${LIB_PATH}' $(SHELL) $(srcdir)/genscripts.sh ${srcdir} ${libdir} "${exec_prefix}" @host@ @target@ @target_alias@ "@EMULATION_LIBPATH@" "@NATIVE_LIB_DIRS@" @use_sysroot@
+GENSCRIPTS = LIB_PATH='${LIB_PATH}' $(SHELL) $(srcdir)/genscripts.sh "${srcdir}" "${libdir}" "${prefix}" "${exec_prefix}" @host@ @target@ @target_alias@ "@EMULATION_LIBPATH@" "@NATIVE_LIB_DIRS@" @use_sysroot@
GEN_DEPENDS = $(srcdir)/genscripts.sh stringify.sed
@TDIRS@
Index: ld/genscripts.sh
===================================================================
RCS file: /cvs/src/src/ld/genscripts.sh,v
retrieving revision 1.20
diff -u -p -r1.20 genscripts.sh
--- ld/genscripts.sh 21 Oct 2004 15:20:35 -0000 1.20
+++ ld/genscripts.sh 5 Apr 2006 13:43:29 -0000
@@ -4,6 +4,7 @@
# Usage: genscripts_extra.sh \
# srcdir \
# libdir \
+# prefix \
# exec_prefix \
# host \
# target \
@@ -22,6 +23,7 @@
# /sources/ld \
# /usr/local/lib \
# /usr/local \
+# /usr/local \
# sparc-sun-sunos4.1.3 \
# sparc-sun-sunos4.1.3 \
# sparc-sun-sunos4.1.3 \
@@ -59,17 +61,18 @@
srcdir=$1
libdir=$2
-exec_prefix=$3
-host=$4
-target=$5
-target_alias=$6
-EMULATION_LIBPATH=$7
-NATIVE_LIB_DIRS=$8
-use_sysroot=$9
+prefix=$3
+exec_prefix=$4
+host=$5
+target=$6
+target_alias=$7
+EMULATION_LIBPATH=$8
+NATIVE_LIB_DIRS=$9
shift 9
-EMULATION_NAME=$1
-TOOL_LIB=$2
-CUSTOMIZER_SCRIPT=$3
+use_sysroot=$1
+EMULATION_NAME=$2
+TOOL_LIB=$3
+CUSTOMIZER_SCRIPT=$4
# Can't use ${TOOL_LIB:-$target_alias} here due to an Ultrix shell bug.
if [ "x${TOOL_LIB}" = "x" ] ; then
Index: ld/emultempl/elf32.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/elf32.em,v
retrieving revision 1.162
diff -u -p -r1.162 elf32.em
--- ld/emultempl/elf32.em 9 Feb 2006 01:05:10 -0000 1.162
+++ ld/emultempl/elf32.em 5 Apr 2006 13:43:33 -0000
@@ -541,7 +541,7 @@ struct gld${EMULATION_NAME}_ld_so_conf
size_t len, alloc;
};
-static void
+static bfd_boolean
gld${EMULATION_NAME}_parse_ld_so_conf
(struct gld${EMULATION_NAME}_ld_so_conf *info, const char *filename);
@@ -584,7 +584,7 @@ gld${EMULATION_NAME}_parse_ld_so_conf_in
free (newp);
}
-static void
+static bfd_boolean
gld${EMULATION_NAME}_parse_ld_so_conf
(struct gld${EMULATION_NAME}_ld_so_conf *info, const char *filename)
{
@@ -593,7 +593,7 @@ gld${EMULATION_NAME}_parse_ld_so_conf
size_t linelen;
if (f == NULL)
- return;
+ return FALSE;
linelen = 256;
line = xmalloc (linelen);
@@ -691,6 +691,7 @@ gld${EMULATION_NAME}_parse_ld_so_conf
while (! feof (f));
free (line);
fclose (f);
+ return TRUE;
}
static bfd_boolean
@@ -705,11 +706,17 @@ gld${EMULATION_NAME}_check_ld_so_conf (c
char *tmppath;
struct gld${EMULATION_NAME}_ld_so_conf info;
- tmppath = concat (ld_sysroot, "/etc/ld.so.conf", NULL);
info.path = NULL;
info.len = info.alloc = 0;
- gld${EMULATION_NAME}_parse_ld_so_conf (&info, tmppath);
+ tmppath = concat (ld_sysroot, "${prefix}/etc/ld.so.conf", NULL);
+ if (!gld${EMULATION_NAME}_parse_ld_so_conf (&info, tmppath))
+ {
+ free (tmppath);
+ tmppath = concat (ld_sysroot, "/etc/ld.so.conf", NULL);
+ gld${EMULATION_NAME}_parse_ld_so_conf (&info, tmppath);
+ }
free (tmppath);
+
if (info.path)
{
char *d = gld${EMULATION_NAME}_add_sysroot (info.path);
Index: ld/NEWS
===================================================================
RCS file: /cvs/src/src/ld/NEWS,v
retrieving revision 1.64
diff -u -p -r1.64 NEWS
--- ld/NEWS 17 Feb 2006 14:36:28 -0000 1.64
+++ ld/NEWS 5 Apr 2006 14:09:15 -0000
@@ -2,8 +2,10 @@
* Support for the Infineon XC16X has been added by KPIT Cummins Infosystems.
-* Modify the Linux linker to seach /etc/ld.so.conf first before
- checking default search directories for DT_NEEDED entries.
+* Modify the Linux linker search order to better match ld.so search order.
+ Look for DT_NEEDED libraries in paths specified by ld.so.conf before
+ searching the default directories, rather than vice versa.
+ Use $prefix/etc/ld.so.conf if it exists, otherwise /etc/ld.so.conf.
* PE-COFF: Forward exports from DLL's can now be specified in .def files
passed directly to ld.
--
Alan Modra
IBM OzLabs - Linux Technology Centre