This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Relocatable binutils installs [2/2] (sysroot)
- From: Daniel Jacobowitz <drow at mvista dot com>
- To: binutils at sources dot redhat dot com
- Date: Tue, 31 Dec 2002 12:22:34 -0500
- Subject: Relocatable binutils installs [2/2] (sysroot)
GCC recently acquired the option --with-sysroot, which allows a
cross-compiler to work as a native compiler would for a filesystem mount.
By that I mean the cross-compiler searches the same directories (with the
prefix) that a native compiler for that configuration would search, for
headers, startfiles, libraries, et cetera. For the increasingly common
GNU/Linux cross-compilers, this is vastly more convenient than a
--with-headers/--with-libs setup.
Well, here's the same thing for the linker. Highlights:
- -L/SEARCH_DIR gain a new feature; a directory prefixed with
"=" will have that replaced by the sysroot prefix, or "" if there
isn't one.
- NATIVE_LIB_DIRS will be honored for cross-sysrooted linkers.
- Environment variables (LD_RUN_PATH) won't be honored for cross-linkers,
but the rest of elf32.em's native linker magic will be. For instance,
this patch correctly loads $sysroot/etc/ld.so.conf.
- As with GCC, if the sysroot is within $exec_prefix it is assumed to be
relative to the location of the binary, if you move the install tree.
Tested extensively, and no unpleasant surprises; it could definitely use a
second pair of eyes, though.
Is this OK to commit? The diff also includes my previous patch, since
they're a bit tangled up now.
--
Daniel Jacobowitz
MontaVista Software Debian GNU/Linux Developer
2002-12-31 Daniel Jacobowitz <drow@mvista.com>
* Makefile.am (ldmain.o): Add @TARGET_SYSTEM_ROOT_DEFINE@.
(GENSCRIPTS): Add @use_sysroot@.
* configure.host: Move setting of NATIVE_LIB_DIRS to...
* configure.tgt: ... here. Use ${target} instead of ${host}
for NATIVE_LIB_DIRS.
* configure.in: Add --with-sysroot.
* genscripts.sh: Accept use_sysroot option. Set new variables
NATIVE and USE_LIBPATH. Prepend "=" to directory names if
$use_sysroot. Don't search $tool_lib if $use_sysroot.
* ldfile.c (ldfile_add_library_path): Handle leading '='.
* ldmain.c (TARGET_SYSTEM_ROOT): Define if not defined.
(ld_sysroot): New variable.
(main): Initialize ld_sysroot.
* ldmain.h (ld_sysroot): New extern.
* emultempl/elf32.em: Use NATIVE and USE_LIBPATH instead of
searching $EMULATION_LIBPATH.
(gld${EMULATION_NAME}_add_sysroot): New function.
(gld${EMULATION_NAME}_check_ld_so_conf): Use it. Honor ld_sysroot.
(gld${EMULATION_NAME}_after_open): Likewise. Only search
environment variables if $NATIVE.
* ld.texinfo (Options): Mention "=" prefix in the description of -L.
* NEWS: Mention --with-sysroot.
* emulparams/elf32bmipn32-defs.sh: Set NATIVE and LIBPATH_SUFFIX
instead of setting LIB_PATH.
* emulparams/elf32ppc.sh: Likewise.
* emulparams/elf64_s390.sh: Likewise.
* emulparams/elf64_sparc.sh: Likewise.
* emulparams/elf64ppc.sh: Likewise.
* emulparams/elf_x86_64.sh: Likewise.
* emulparams/elf64_aix.sh: Add "=" prefixes to LIB_PATH.
* emulparams/elf64hppa.sh: Add "=" prefixes to LIB_PATH.
2002-12-30 Daniel Jacobowitz <drow@mvista.com>
* Makefile.am (ldmain.o): Pass BINDIR.
* Makefile.in: Regenerated.
* ldmain.c (set_scripts_dir): Use make_relative_prefix for the first
search path.
Index: Makefile.am
===================================================================
RCS file: /cvs/src/src/ld/Makefile.am,v
retrieving revision 1.116
diff -u -p -r1.116 Makefile.am
--- Makefile.am 30 Dec 2002 19:25:04 -0000 1.116
+++ Makefile.am 31 Dec 2002 03:02:34 -0000
@@ -391,7 +391,10 @@ po/POTFILES.in: @MAINT@ Makefile
&& mv tmp $(srcdir)/po/POTFILES.in
ldmain.o: ldmain.c config.status
- $(COMPILE) -c -DDEFAULT_EMULATION='"$(EMUL)"' -DSCRIPTDIR='"$(scriptdir)"' -DTARGET='"@target@"' $(srcdir)/ldmain.c
+ $(COMPILE) -c -DDEFAULT_EMULATION='"$(EMUL)"' \
+ -DSCRIPTDIR='"$(scriptdir)"' -DBINDIR='"$(bindir)"' \
+ -DTARGET='"@target@"' @TARGET_SYSTEM_ROOT_DEFINE@ \
+ $(srcdir)/ldmain.c
ldemul-list.h: Makefile
(echo "/* This file is automatically generated. DO NOT EDIT! */";\
@@ -413,7 +416,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@"
+GENSCRIPTS = LIB_PATH='${LIB_PATH}' $(SHELL) $(srcdir)/genscripts.sh ${srcdir} ${libdir} "${exec_prefix}" @host@ @target@ @target_alias@ "@EMULATION_LIBPATH@" "@NATIVE_LIB_DIRS@" @use_sysroot@
GEN_DEPENDS = $(srcdir)/genscripts.sh stringify.sed
@TDIRS@
Index: configure.host
===================================================================
RCS file: /cvs/src/src/ld/configure.host,v
retrieving revision 1.26
diff -u -p -r1.26 configure.host
--- configure.host 18 Dec 2002 16:56:19 -0000 1.26
+++ configure.host 31 Dec 2002 03:02:35 -0000
@@ -7,12 +7,10 @@
# HDEFINES host specific compiler flags
# HOSTING_CRT0 crt0.o file used for bootstrapping
# HOSTING_LIBS libraries used for bootstrapping
-# NATIVE_LIB_DIRS library directories to search on this host
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='/usr/local/lib /lib /usr/lib'
#
# Generic configurations:
@@ -21,7 +19,6 @@ NATIVE_LIB_DIRS='/usr/local/lib /lib /us
case "${host}" in
*-*-freebsd*)
- 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.
@@ -65,7 +62,6 @@ arm*-*-linux-gnu*)
;;
hppa*64*-*-hpux11*)
- NATIVE_LIB_DIRS=/usr/lib/pa20_64
HOSTING_CRT0=/usr/ccs/lib/pa20_64/crt0.o
# Even if CC is not gcc, the tests use gcc.
HOSTING_LIBS='`if [ -f ../gcc/libgcc.a ] ; then echo ../gcc/libgcc.a ; else if test "$GCC" = yes; then ${CC} --print-libgcc-file-name; else gcc --print-libgcc-file-name; fi fi` -lc /usr/lib/pa20_64/milli.a'
@@ -78,7 +74,6 @@ i[3456]86-*-bsd* | i[34567]86-*-freebsd[
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/local/lib /usr/ccs/lib /lib /usr/lib'
;;
i[3456]86-sequent-ptx* | i[3456]86-sequent-sysv*)
@@ -94,7 +89,6 @@ 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/local/lib /usr/ccs/lib /lib /usr/lib'
;;
i[3456]86-*-sco* | i[3456]86-*-isc*)
@@ -119,7 +113,6 @@ i[3456]86-*-lynxos*)
i[3456]86-pc-interix*)
HOSTING_CRT0='$$INTERIX_ROOT/usr/lib/crt0.o'
- 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'
;;
@@ -134,7 +127,6 @@ 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/local/lib /usr/lib/ia64l64 /lib /usr/lib'
;;
mips*-dec-bsd*)
@@ -203,7 +195,6 @@ 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/local/lib /usr/ccs/lib /lib /usr/lib'
;;
sparc-*-linux-gnu*)
@@ -232,7 +223,6 @@ x86_64-*-linux-gnu*)
alpha*-*-*)
HOSTING_CRT0=/usr/ccs/lib/crt0.o
- NATIVE_LIB_DIRS='/usr/local/lib /usr/ccs/lib /lib /usr/lib'
;;
esac
Index: configure.in
===================================================================
RCS file: /cvs/src/src/ld/configure.in,v
retrieving revision 1.21
diff -u -p -r1.21 configure.in
--- configure.in 16 Dec 2002 18:02:14 -0000 1.21
+++ configure.in 31 Dec 2002 03:02:35 -0000
@@ -30,6 +30,41 @@ AC_ARG_ENABLE(64-bit-bfd,
*) AC_MSG_ERROR(bad value ${enableval} for 64-bit-bfd option) ;;
esac],[want64=false])dnl
+AC_ARG_WITH(sysroot,
+[ --with-sysroot[=DIR] Search for usr/lib et al within DIR.],
+[
+ case ${with_sysroot} in
+ yes) AC_ERROR(with-sysroot must specify path) ;;
+ *) TARGET_SYSTEM_ROOT=$with_sysroot ;;
+ esac
+
+ TARGET_SYSTEM_ROOT_DEFINE='-DTARGET_SYSTEM_ROOT=\"$(TARGET_SYSTEM_ROOT)\"'
+ use_sysroot=yes
+
+ if test "x$exec_prefix" = xNONE; then
+ if test "x$prefix" = xNONE; then
+ test_prefix=/usr/local
+ else
+ test_prefix=$prefix
+ fi
+ else
+ test_prefix=$exec_prefix
+ fi
+ case ${TARGET_SYSTEM_ROOT} in
+ ${test_prefix}*)
+ t="$TARGET_SYSTEM_ROOT_DEFINE -DTARGET_SYSTEM_ROOT_RELOCATABLE"
+ TARGET_SYSTEM_ROOT_DEFINE="$t"
+ ;;
+ esac
+], [
+ use_sysroot=no
+ TARGET_SYSTEM_ROOT=
+ TARGET_SYSTEM_ROOT_DEFINE='-DTARGET_SYSTEM_ROOT=\"\"'
+])
+AC_SUBST(use_sysroot)
+AC_SUBST(TARGET_SYSTEM_ROOT)
+AC_SUBST(TARGET_SYSTEM_ROOT_DEFINE)
+
build_warnings="-W -Wall -Wstrict-prototypes -Wmissing-prototypes"
AC_ARG_ENABLE(build-warnings,
[ --enable-build-warnings enable build-time compiler warnings if gcc is used],
Index: configure.tgt
===================================================================
RCS file: /cvs/src/src/ld/configure.tgt,v
retrieving revision 1.114
diff -u -p -r1.114 configure.tgt
--- configure.tgt 30 Dec 2002 19:25:04 -0000 1.114
+++ configure.tgt 31 Dec 2002 03:02:35 -0000
@@ -9,6 +9,8 @@
# targ_extra_emuls additional linker emulations to provide
# targ_extra_libpath additional linker emulations using LIB_PATH
# targ_extra_ofiles additional objects needed by the emulation
+# NATIVE_LIB_DIRS library directories to search on this host
+# (if we are a native or sysrooted linker)
targ_extra_emuls=
targ_extra_ofiles=
@@ -538,5 +540,51 @@ ip2k-*-elf) targ_emul=elf32ip2k ;;
echo 2>&1 "*** ld does not support target ${targ}"
echo 2>&1 "*** see ld/configure.tgt for supported targets"
exit 1
+
+esac
+
+NATIVE_LIB_DIRS='/usr/local/lib /lib /usr/lib'
+case "${target}" in
+
+*-*-freebsd*)
+ NATIVE_LIB_DIRS='/lib /usr/lib /usr/local/lib'
+ ;;
+
+hppa*64*-*-hpux11*)
+ NATIVE_LIB_DIRS=/usr/lib/pa20_64
+ ;;
+
+i[3456]86-*-sysv4*)
+ NATIVE_LIB_DIRS='/usr/local/lib /usr/ccs/lib /lib /usr/lib'
+ ;;
+
+i[3456]86-*-solaris*)
+ NATIVE_LIB_DIRS='/usr/local/lib /usr/ccs/lib /lib /usr/lib'
+ ;;
+
+i[3456]86-pc-interix*)
+ NATIVE_LIB_DIRS='/usr/local/lib $$INTERIX_ROOT/usr/lib /lib /usr/lib'
+ ;;
+
+ia64-*-aix*)
+ NATIVE_LIB_DIRS='/usr/local/lib /usr/lib/ia64l64 /lib /usr/lib'
+ ;;
+
+sparc*-*-solaris2*)
+ NATIVE_LIB_DIRS='/usr/local/lib /usr/ccs/lib /lib /usr/lib'
+ ;;
+
+*-*-linux*)
+ ;;
+
+*-*-freebsd*)
+ ;;
+
+*-*-netbsd*)
+ ;;
+
+alpha*-*-*)
+ NATIVE_LIB_DIRS='/usr/local/lib /usr/ccs/lib /lib /usr/lib'
+ ;;
esac
Index: genscripts.sh
===================================================================
RCS file: /cvs/src/src/ld/genscripts.sh,v
retrieving revision 1.10
diff -u -p -r1.10 genscripts.sh
--- genscripts.sh 25 Sep 2002 07:21:07 -0000 1.10
+++ genscripts.sh 31 Dec 2002 03:02:36 -0000
@@ -3,12 +3,12 @@
#
# Usage: genscripts.sh srcdir libdir exec_prefix \
# host target target_alias default_emulation \
-# native_lib_dirs this_emulation tool_dir
+# native_lib_dirs use_sysroot this_emulation tool_dir
#
# Sample usage:
# genscripts.sh /djm/ld-devo/devo/ld /usr/local/lib /usr/local \
# sparc-sun-sunos4.1.3 sparc-sun-sunos4.1.3 sparc-sun-sunos4.1.3 sun4 \
-# "" sun3 sparc-sun-sunos4.1.3
+# "" no sun3 sparc-sun-sunos4.1.3
# produces sun3.x sun3.xbn sun3.xn sun3.xr sun3.xu em_sun3.c
srcdir=$1
@@ -19,8 +19,10 @@ target=$5
target_alias=$6
EMULATION_LIBPATH=$7
NATIVE_LIB_DIRS=$8
-EMULATION_NAME=$9
+use_sysroot=$9
shift 9
+EMULATION_NAME=$1
+shift
# Can't use ${1:-$target_alias} here due to an Ultrix shell bug.
if [ "x$1" = "x" ] ; then
tool_lib=${exec_prefix}/${target_alias}/lib
@@ -37,31 +39,66 @@ else
mkdir ldscripts
fi
+# Set some flags for the emultempl scripts. USE_LIBPATH will
+# be set for any libpath-using emulation; NATIVE will be set for a
+# libpath-using emulation where ${host} = ${target}. NATIVE
+# may already have been set by the emulparams file, but that's OK
+# (it'll just get set to "yes" twice).
+
+case " $EMULATION_LIBPATH " in
+ *" ${EMULATION_NAME} "*)
+ if [ "x${host}" = "x${target}" ] ; then
+ NATIVE=yes
+ USE_LIBPATH=yes
+ elif [ "x${use_sysroot}" = "xyes" ] ; then
+ USE_LIBPATH=yes
+ fi
+ ;;
+esac
+
+# If the emulparams file sets NATIVE, make sure USE_LIBPATH is set also.
+if test "x$NATIVE" = "xyes" ; then
+ USE_LIBPATH=yes
+fi
+
# Set the library search path, for libraries named by -lfoo.
# If LIB_PATH is defined (e.g., by Makefile) and non-empty, it is used.
# Otherwise, the default is set here.
#
# The format is the usual list of colon-separated directories.
# To force a logically empty LIB_PATH, do LIBPATH=":".
+#
+# If we are using a sysroot, prefix library paths with "=" to indicate this.
+#
+# If the emulparams file set LIBPATH_SUFFIX, prepend an extra copy of
+# the library path with the suffix applied.
-if [ "x${LIB_PATH}" = "x" ] ; then
- if [ "x${host}" = "x${target}" ] ; then
- case " $EMULATION_LIBPATH " in
- *" ${EMULATION_NAME} "*)
- # Native, and default or emulation requesting LIB_PATH.
- LIB_PATH=${libdir}
- for lib in ${NATIVE_LIB_DIRS}; do
- case :${LIB_PATH}: in
- *:${lib}:*) ;;
- *) LIB_PATH=${LIB_PATH}:${lib} ;;
- esac
- done
+if [ "x${LIB_PATH}" = "x" ] && [ "x${USE_LIBPATH}" = xyes ] ; then
+ if [ x"$use_sysroot" != xyes ] ; then
+ LIB_PATH=${libdir}
+ fi
+ for lib in ${NATIVE_LIB_DIRS}; do
+ # The "=" is harmless if we aren't using a sysroot, but also needless.
+ if [ "x${use_sysroot}" = "xyes" ] ; then
+ lib="=${lib}"
+ fi
+ case :${LIB_PATH}: in
+ *:${lib}:*) ;;
+ ::) LIB_PATH=${lib} ;;
+ *) LIB_PATH=${LIB_PATH}:${lib} ;;
esac
+ done
+ if test -n "$LIBPATH_SUFFIX" ; then
+ LIB_PATH=`echo ${LIB_PATH}: | sed -e s,:,${LIBPATH_SUFFIX}:,g`$LIB_PATH
fi
fi
-# Always search $(tooldir)/lib, aka /usr/local/TARGET/lib.
-LIB_PATH=${tool_lib}:${LIB_PATH}
+
+# Always search $(tooldir)/lib, aka /usr/local/TARGET/lib, except for
+# sysrooted configurations.
+if [ "x${use_sysroot}" != "xyes" ] ; then
+ LIB_PATH=${tool_lib}:${LIB_PATH}
+fi
LIB_SEARCH_DIRS=`echo ${LIB_PATH} | sed -e 's/:/ /g' -e 's/\([^ ][^ ]*\)/SEARCH_DIR(\\"\1\\");/g'`
Index: ldfile.c
===================================================================
RCS file: /cvs/src/src/ld/ldfile.c,v
retrieving revision 1.23
diff -u -p -r1.23 ldfile.c
--- ldfile.c 23 Dec 2002 10:44:59 -0000 1.23
+++ ldfile.c 31 Dec 2002 03:02:36 -0000
@@ -88,6 +88,11 @@ ldfile_add_library_path (name, cmdline)
new->cmdline = cmdline;
*search_tail_ptr = new;
search_tail_ptr = &new->next;
+
+ /* If a directory is marked as honoring sysroot, prepend the sysroot path
+ now. */
+ if (new->name[0] == '=')
+ new->name = concat (ld_sysroot, &new->name[1], NULL);
}
/* Try to open a BFD for a lang_input_statement. */
Index: ldmain.c
===================================================================
RCS file: /cvs/src/src/ld/ldmain.c,v
retrieving revision 1.57
diff -u -p -r1.57 ldmain.c
--- ldmain.c 23 Dec 2002 12:05:38 -0000 1.57
+++ ldmain.c 31 Dec 2002 03:02:36 -0000
@@ -55,6 +55,10 @@ extern PTR sbrk ();
#endif
#endif
+#ifndef TARGET_SYSTEM_ROOT
+#define TARGET_SYSTEM_ROOT ""
+#endif
+
int main PARAMS ((int, char **));
static char *get_emulation PARAMS ((int, char **));
@@ -68,6 +72,9 @@ const char *output_filename = "a.out";
/* Name this program was invoked by. */
char *program_name;
+/* The prefix for system library directories. */
+char *ld_sysroot;
+
/* The file that we're creating. */
bfd *output_bfd = 0;
@@ -189,6 +196,23 @@ main (argc, argv)
xatexit (remove_output);
+#ifdef TARGET_SYSTEM_ROOT_RELOCATABLE
+ ld_sysroot = make_relative_prefix (program_name, BINDIR,
+ TARGET_SYSTEM_ROOT);
+ if (ld_sysroot)
+ {
+ struct stat s;
+ int res = stat (ld_sysroot, &s) == 0 && S_ISDIR (s.st_mode);
+ if (!res)
+ {
+ free (ld_sysroot);
+ ld_sysroot = TARGET_SYSTEM_ROOT;
+ }
+ }
+#else
+ ld_sysroot = TARGET_SYSTEM_ROOT;
+#endif
+
/* Set the default BFD target based on the configured target. Doing
this permits the linker to be configured for a particular target,
and linked against a shared BFD library which was configured for
@@ -612,14 +636,25 @@ check_for_scripts_dir (dir)
We look for the "ldscripts" directory in:
SCRIPTDIR (passed from Makefile)
+ (adjusted according to the current location of the binary)
+ SCRIPTDIR (passed from Makefile)
the dir where this program is (for using it from the build tree)
- the dir where this program is/../lib (for installing the tool suite elsewhere) */
+ the dir where this program is/../lib
+ (for installing the tool suite elsewhere) */
static void
set_scripts_dir ()
{
char *end, *dir;
size_t dirlen;
+
+ dir = make_relative_prefix (program_name, BINDIR, SCRIPTDIR);
+ if (dir && check_for_scripts_dir (dir))
+ /* Success. Don't free dir. */
+ return;
+
+ if (dir)
+ free (dir);
if (check_for_scripts_dir (SCRIPTDIR))
/* We've been installed normally. */
Index: ldmain.h
===================================================================
RCS file: /cvs/src/src/ld/ldmain.h,v
retrieving revision 1.3
diff -u -p -r1.3 ldmain.h
--- ldmain.h 30 Nov 2002 08:39:45 -0000 1.3
+++ ldmain.h 31 Dec 2002 03:02:36 -0000
@@ -23,6 +23,7 @@
#define LDMAIN_H
extern char *program_name;
+extern char *ld_sysroot;
extern bfd *output_bfd;
extern char *default_target;
extern bfd_boolean trace_files;
Index: emulparams/elf32bmipn32-defs.sh
===================================================================
RCS file: /cvs/src/src/ld/emulparams/elf32bmipn32-defs.sh,v
retrieving revision 1.3
diff -u -p -r1.3 elf32bmipn32-defs.sh
--- emulparams/elf32bmipn32-defs.sh 22 Oct 2002 22:13:26 -0000 1.3
+++ emulparams/elf32bmipn32-defs.sh 31 Dec 2002 03:02:36 -0000
@@ -21,18 +21,13 @@ esac
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.
- LIB_PATH=`echo ${LIB_PATH}: | sed -e s,:,$ELFSIZE:,g`$LIB_PATH
- ;;
+ NATIVE=yes
+ ;;
esac
fi
+
+# Look for 64 bit target libraries in /lib64, /usr/lib64 etc., first.
+LIBPATH_SUFFIX=$ELFSIZE
GENERATE_SHLIB_SCRIPT=yes
Index: emulparams/elf32ppc.sh
===================================================================
RCS file: /cvs/src/src/ld/emulparams/elf32ppc.sh,v
retrieving revision 1.9
diff -u -p -r1.9 elf32ppc.sh
--- emulparams/elf32ppc.sh 22 Oct 2002 22:13:26 -0000 1.9
+++ emulparams/elf32ppc.sh 31 Dec 2002 03:02:36 -0000
@@ -25,19 +25,14 @@ OTHER_GOT_RELOC_SECTIONS="
# 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
+ case " $EMULATION_LIBPATH " in
+ *" ${EMULATION_NAME} "*)
+ NATIVE=yes
+ ;;
+ esac
fi
+
+# Look for 64 bit target libraries in /lib64, /usr/lib64 etc., first.
+case "$EMULATION_NAME" in
+ *64*) LIBPATH_SUFFIX=64 ;;
+esac
Index: emulparams/elf64_aix.sh
===================================================================
RCS file: /cvs/src/src/ld/emulparams/elf64_aix.sh,v
retrieving revision 1.6
diff -u -p -r1.6 elf64_aix.sh
--- emulparams/elf64_aix.sh 24 Sep 2002 04:02:03 -0000 1.6
+++ emulparams/elf64_aix.sh 31 Dec 2002 03:02:36 -0000
@@ -18,4 +18,4 @@ OTHER_READONLY_SECTIONS="
.opd ${RELOCATING-0} : { *(.opd) }
.IA_64.unwind_info ${RELOCATING-0} : { *(.IA_64.unwind_info*${RELOCATING+ .gnu.linkonce.ia64unwi.*}) }
.IA_64.unwind ${RELOCATING-0} : { *(.IA_64.unwind*${RELOCATING+ .gnu.linkonce.ia64unw.*}) }"
-LIB_PATH=/usr/lib/ia64l64:/usr/lib:/usr/local/lib
+LIB_PATH="=/usr/lib/ia64l64:=/usr/lib:=/usr/local/lib"
Index: emulparams/elf64_s390.sh
===================================================================
RCS file: /cvs/src/src/ld/emulparams/elf64_s390.sh,v
retrieving revision 1.4
diff -u -p -r1.4 elf64_s390.sh
--- emulparams/elf64_s390.sh 16 Oct 2002 19:54:54 -0000 1.4
+++ emulparams/elf64_s390.sh 31 Dec 2002 03:02:36 -0000
@@ -16,26 +16,17 @@ if test `echo "$host" | sed -e s/390x/39
= `echo "$target" | sed -e s/390x/390/`; 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
-
- case "$target" in
- s390*-linux*)
- suffix=64 ;;
- esac
-
- # Look for 64 bit target libraries in /lib64, /usr/lib64 etc., first
- # on Linux.
- if [ -n "$suffix" ]; then
- case "$EMULATION_NAME" in
- *64*)
- LIB_PATH=`echo ${LIB_PATH}: | sed -e s,:,$suffix:,g`$LIB_PATH ;;
- esac
- fi ;;
+ NATIVE=yes
esac
fi
+
+# Look for 64 bit target libraries in /lib64, /usr/lib64 etc., first
+# on Linux.
+case "$target" in
+ s390*-linux*)
+ case "$EMULATION_NAME" in
+ *64*)
+ LIBPATH_SUFFIX=$suffix ;;
+ esac
+ ;;
+esac
Index: emulparams/elf64_sparc.sh
===================================================================
RCS file: /cvs/src/src/ld/emulparams/elf64_sparc.sh,v
retrieving revision 1.6
diff -u -p -r1.6 elf64_sparc.sh
--- emulparams/elf64_sparc.sh 16 Oct 2002 19:54:54 -0000 1.6
+++ emulparams/elf64_sparc.sh 31 Dec 2002 03:02:36 -0000
@@ -28,31 +28,23 @@ if test `echo "$host" | sed -e 's/64//;s
= `echo "$target" | sed -e 's/64//;s/v[789]//'`; 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
-
- # Linux and Solaris modify the default library search path
- # to first include a 64-bit specific directory. It's put
- # in slightly different places on the two systems.
- case "$target" in
- sparc*-linux*)
- suffix=64 ;;
- sparc*-solaris*)
- suffix=/sparcv9 ;;
- esac
-
- # Look for 64 bit target libraries in /lib64, /usr/lib64 etc., first
- # on Linux and /lib/sparcv9, /usr/lib/sparcv9 etc. on Solaris.
- if [ -n "$suffix" ]; then
- case "$EMULATION_NAME" in
- *64*)
- LIB_PATH=`echo ${LIB_PATH}: | sed -e s,:,$suffix:,g`$LIB_PATH ;;
- esac
- fi ;;
+ NATIVE=yes
+ ;;
esac
fi
+
+# Linux and Solaris modify the default library search path
+# to first include a 64-bit specific directory. It's put
+# in slightly different places on the two systems.
+# Look for 64 bit target libraries in /lib64, /usr/lib64 etc., first
+# on Linux and /lib/sparcv9, /usr/lib/sparcv9 etc. on Solaris.
+case "$EMULATION_NAME" in
+ *64*)
+ case "$target" in
+ sparc*-linux*)
+ suffix=64 ;;
+ sparc*-solaris*)
+ suffix=/sparcv9 ;;
+ esac
+ ;;
+esac
Index: emulparams/elf64hppa.sh
===================================================================
RCS file: /cvs/src/src/ld/emulparams/elf64hppa.sh,v
retrieving revision 1.16
diff -u -p -r1.16 elf64hppa.sh
--- emulparams/elf64hppa.sh 22 Nov 2001 09:08:04 -0000 1.16
+++ emulparams/elf64hppa.sh 31 Dec 2002 03:02:36 -0000
@@ -1,6 +1,6 @@
. ${srcdir}/emulparams/hppa64linux.sh
OUTPUT_FORMAT="elf64-hppa"
-LIB_PATH=/usr/lib/pa20_64:/opt/langtools/lib/pa20_64
+LIB_PATH="=/usr/lib/pa20_64:=/opt/langtools/lib/pa20_64"
TEXT_START_ADDR=0x4000000000001000
DATA_ADDR=0x8000000000001000
TARGET_PAGE_SIZE=4096
Index: emulparams/elf64ppc.sh
===================================================================
RCS file: /cvs/src/src/ld/emulparams/elf64ppc.sh,v
retrieving revision 1.10
diff -u -p -r1.10 elf64ppc.sh
--- emulparams/elf64ppc.sh 20 Nov 2002 01:02:44 -0000 1.10
+++ emulparams/elf64ppc.sh 31 Dec 2002 03:02:36 -0000
@@ -34,18 +34,14 @@ OTHER_READWRITE_SECTIONS="
# 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
+ case " $EMULATION_LIBPATH " in
+ *" ${EMULATION_NAME} "*)
+ NATIVE=yes
+ ;;
+ esac
fi
+
+# Look for 64 bit target libraries in /lib64, /usr/lib64 etc., first.
+case "$EMULATION_NAME" in
+ *64*) LIBPATH_SUFFIX=64 ;;
+esac
Index: emulparams/elf_x86_64.sh
===================================================================
RCS file: /cvs/src/src/ld/emulparams/elf_x86_64.sh,v
retrieving revision 1.8
diff -u -p -r1.8 elf_x86_64.sh
--- emulparams/elf_x86_64.sh 16 Oct 2002 19:54:54 -0000 1.8
+++ emulparams/elf_x86_64.sh 31 Dec 2002 03:02:36 -0000
@@ -15,27 +15,16 @@ NO_SMALL_DATA=yes
if [ "x${host}" = "x${target}" ]; 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
-
- # Linux modify the default library search path to first include
- # a 64-bit specific directory.
- case "$target" in
- x86_64*-linux*)
- suffix=64 ;;
- esac
-
- # Look for 64 bit target libraries in /lib64, /usr/lib64 etc., first.
- if [ -n "$suffix" ]; then
- case "$EMULATION_NAME" in
- *64*)
- LIB_PATH=`echo ${LIB_PATH}: | sed -e s,:,$suffix:,g`$LIB_PATH ;;
- esac
- fi ;;
+ NATIVE=yes
esac
fi
+
+# Linux modify the default library search path to first include
+# a 64-bit specific directory.
+case "$target" in
+ x86_64*-linux*)
+ case "$EMULATION_NAME" in
+ *64*) LIBPATH_SUFFIX=$suffix ;;
+ esac
+ ;;
+esac
Index: emultempl/elf32.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/elf32.em,v
retrieving revision 1.87
diff -u -p -r1.87 elf32.em
--- emultempl/elf32.em 10 Dec 2002 03:34:43 -0000 1.87
+++ emultempl/elf32.em 31 Dec 2002 03:02:36 -0000
@@ -439,12 +439,48 @@ gld${EMULATION_NAME}_search_needed (path
}
EOF
-if [ "x${host}" = "x${target}" ] ; then
- case " ${EMULATION_LIBPATH} " in
- *" ${EMULATION_NAME} "*)
- case ${target} in
- *-*-linux-gnu*)
- cat >>e${EMULATION_NAME}.c <<EOF
+if [ "x${USE_LIBPATH}" = xyes ] ; then
+ case ${target} in
+ *-*-linux-gnu*)
+ cat >>e${EMULATION_NAME}.c <<EOF
+
+/* Add the sysroot to every entry in a colon-separated path. */
+
+static char *
+gld${EMULATION_NAME}_add_sysroot (path)
+ const char *path;
+{
+ int len, colons, i;
+ char *ret, *p;
+
+ len = strlen (path);
+ colons = 0;
+ i = 0;
+ while (path[i])
+ if (path[i++] == ':')
+ colons++;
+
+ if (path[i])
+ colons++;
+
+ len = len + colons * strlen (ld_sysroot);
+ ret = xmalloc (len + 1);
+ strcpy (ret, ld_sysroot);
+ p = ret + strlen (ret);
+ i = 0;
+ while (path[i])
+ if (path[i] == ':')
+ {
+ strcpy (p, ld_sysroot);
+ p = p + strlen (p);
+ i++;
+ }
+ else
+ *p++ = path[i++];
+
+ *p = 0;
+ return ret;
+}
/* For a native linker, check the file /etc/ld.so.conf for directories
in which we may find shared libraries. /etc/ld.so.conf is really
@@ -464,8 +500,11 @@ gld${EMULATION_NAME}_check_ld_so_conf (n
if (! initialized)
{
FILE *f;
+ char *tmppath;
- f = fopen ("/etc/ld.so.conf", FOPEN_RT);
+ tmppath = concat (ld_sysroot, "/etc/ld.so.conf", NULL);
+ f = fopen (tmppath, FOPEN_RT);
+ free (tmppath);
if (f != NULL)
{
char *b;
@@ -515,6 +554,13 @@ gld${EMULATION_NAME}_check_ld_so_conf (n
fclose (f);
+ if (b)
+ {
+ char *d = gld${EMULATION_NAME}_add_sysroot (b);
+ free (b);
+ b = d;
+ }
+
ld_so_conf = b;
}
@@ -528,9 +574,8 @@ gld${EMULATION_NAME}_check_ld_so_conf (n
}
EOF
- # Linux
- ;;
- esac
+ # Linux
+ ;;
esac
fi
cat >>e${EMULATION_NAME}.c <<EOF
@@ -644,16 +689,12 @@ gld${EMULATION_NAME}_after_open ()
size_t len;
search_dirs_type *search;
EOF
-if [ "x${host}" = "x${target}" ] ; then
- case " ${EMULATION_LIBPATH} " in
- *" ${EMULATION_NAME} "*)
+if [ "x${USE_LIBPATH}" = xyes ] ; then
cat >>e${EMULATION_NAME}.c <<EOF
const char *lib_path;
struct bfd_link_needed_list *rp;
int found;
EOF
- ;;
- esac
fi
cat >>e${EMULATION_NAME}.c <<EOF
@@ -661,13 +702,15 @@ cat >>e${EMULATION_NAME}.c <<EOF
l->name, force))
break;
EOF
-if [ "x${host}" = "x${target}" ] ; then
- case " ${EMULATION_LIBPATH} " in
- *" ${EMULATION_NAME} "*)
+if [ "x${USE_LIBPATH}" = xyes ] ; then
cat >>e${EMULATION_NAME}.c <<EOF
if (gld${EMULATION_NAME}_search_needed (command_line.rpath,
l->name, force))
break;
+EOF
+fi
+if [ "x${NATIVE}" = xyes ] ; then
+cat >>e${EMULATION_NAME}.c <<EOF
if (command_line.rpath_link == NULL
&& command_line.rpath == NULL)
{
@@ -679,22 +722,25 @@ cat >>e${EMULATION_NAME}.c <<EOF
lib_path = (const char *) getenv ("LD_LIBRARY_PATH");
if (gld${EMULATION_NAME}_search_needed (lib_path, l->name, force))
break;
-
+EOF
+fi
+if [ "x${USE_LIBPATH}" = xyes ] ; then
+cat >>e${EMULATION_NAME}.c <<EOF
found = 0;
rp = bfd_elf_get_runpath_list (output_bfd, &link_info);
for (; !found && rp != NULL; rp = rp->next)
{
+ char *tmpname = gld${EMULATION_NAME}_add_sysroot (rp->name);
found = (rp->by == l->by
- && gld${EMULATION_NAME}_search_needed (rp->name,
+ && gld${EMULATION_NAME}_search_needed (tmpname,
l->name,
force));
+ free (tmpname);
}
if (found)
break;
EOF
- ;;
- esac
fi
cat >>e${EMULATION_NAME}.c <<EOF
len = strlen (l->name);
@@ -713,19 +759,15 @@ cat >>e${EMULATION_NAME}.c <<EOF
if (search != NULL)
break;
EOF
-if [ "x${host}" = "x${target}" ] ; then
- case " ${EMULATION_LIBPATH} " in
- *" ${EMULATION_NAME} "*)
- case ${target} in
- *-*-linux-gnu*)
- cat >>e${EMULATION_NAME}.c <<EOF
+if [ "x${USE_LIBPATH}" = xyes ] ; then
+ case ${target} in
+ *-*-linux-gnu*)
+ cat >>e${EMULATION_NAME}.c <<EOF
if (gld${EMULATION_NAME}_check_ld_so_conf (l->name, force))
break;
EOF
- # Linux
- ;;
- esac
- ;;
+ # Linux
+ ;;
esac
fi
cat >>e${EMULATION_NAME}.c <<EOF
Index: ld.texinfo
===================================================================
RCS file: /cvs/src/src/ld/ld.texinfo,v
retrieving revision 1.81
diff -u -p -r1.81 ld.texinfo
--- ld.texinfo 30 Dec 2002 19:25:04 -0000 1.81
+++ ld.texinfo 31 Dec 2002 16:57:26 -0000
@@ -609,6 +609,9 @@ on the command line are searched before
@option{-L} options apply to all @option{-l} options, regardless of the
order in which the options appear.
+If @var{searchdir} begins with @code{=}, then the @code{=} will be replaced
+by the @dfn{sysroot prefix}, a path specified when the linker is configured.
+
@ifset UsesEnvVars
The default set of paths searched (without being specified with
@samp{-L}) depends on which emulation mode @command{ld} is using, and in
--- NEWS.orig 2002-12-23 15:31:49.000000000 -0500
+++ NEWS 2002-12-31 12:11:51.000000000 -0500
@@ -1,5 +1,8 @@
-*- text -*-
+* Added --with-sysroot configure switch to specify a target system root, for
+ linking against a target filesystem image.
+
* Added --accept-unknown-linker-format to restore old linker behaviour (pre
2.14) of silently accepting and linking in any files in an unknown binary
file format.