This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Re: more sysroot support in the linker
On Mar 24, 2003, Nick Clifton <nickc at redhat dot com> wrote:
> You are adding a new #include to ldfile.c but not updating Makefile.am
> with the new dependency.
Fixed.
> The variable 'len' is used without being initialised.
Eek... I must have somehow got rid of it while merging the patch from
the pre-bfd_boolean branch in which I wrote it. It surely is in the
branch. Ouch! Thanks for catching it. Here's the fixed patch. Ok
to install this time?
Index: ld/ChangeLog
from Alexandre Oliva <aoliva at redhat dot com>
* ldmain.h (ld_canon_sysroot, ld_canon_sysroot_len): Declare.
* ldmain.c (ld_canon_sysroot, ld_canon_sysroot_len): Define.
(main): Initialize them.
* ldfile.c: Include pathnames.h.
(is_sysrooted_pathname): New.
(ldfile_add_library_path): Use it.
(ldfile_open_file_search): Likewise. Use IS_ABSOLUTE_PATH. Don't
search_dirs if given an absolute pathname.
(ldfile_open_file): Issue error message for sysrooted
absolute pathnames.
* Makefile.am: Updated dependencies.
* Makefile.in: Rebuilt.
Index: ld/Makefile.am
===================================================================
RCS file: /cvs/uberbaum/ld/Makefile.am,v
retrieving revision 1.125
diff -u -p -r1.125 Makefile.am
--- ld/Makefile.am 4 Mar 2003 17:02:40 -0000 1.125
+++ ld/Makefile.am 25 Mar 2003 00:24:27 -0000
@@ -1613,7 +1613,7 @@ ldfile.o: ldfile.c ../bfd/bfd.h $(INCDIR
$(INCDIR)/symcat.h sysdep.h config.h $(INCDIR)/fopen-same.h \
$(INCDIR)/bfdlink.h $(INCDIR)/safe-ctype.h ld.h $(INCDIR)/bin-bugs.h \
ldmisc.h ldexp.h ldlang.h ldfile.h ldmain.h ldgram.h \
- ldlex.h ldemul.h $(INCDIR)/libiberty.h
+ ldlex.h ldemul.h $(INCDIR)/libiberty.h $(INCDIR)/filenames.h
ldlang.o: ldlang.c ../bfd/bfd.h $(INCDIR)/ansidecl.h \
$(INCDIR)/symcat.h sysdep.h config.h $(INCDIR)/fopen-same.h \
$(INCDIR)/libiberty.h $(INCDIR)/safe-ctype.h $(INCDIR)/obstack.h \
Index: ld/Makefile.in
===================================================================
RCS file: /cvs/uberbaum/ld/Makefile.in,v
retrieving revision 1.136
diff -u -p -r1.136 Makefile.in
--- ld/Makefile.in 4 Mar 2003 17:02:40 -0000 1.136
+++ ld/Makefile.in 25 Mar 2003 00:24:28 -0000
@@ -1,4 +1,4 @@
-# Makefile.in generated automatically by automake 1.4-p5 from Makefile.am
+# Makefile.in generated automatically by automake 1.4-p6 from Makefile.am
# Copyright (C) 1994, 1995-8, 1999, 2001 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
@@ -1067,7 +1067,7 @@ distclean-generic:
-test -z "$(DISTCLEANFILES)" || rm -f $(DISTCLEANFILES)
maintainer-clean-generic:
- -test -z "ldlexldeffilephdeffilepcldgramhldgramc$(MAINTAINERCLEANFILES)" || rm -f ldlexl deffileph deffilepc ldgramh ldgramc $(MAINTAINERCLEANFILES)
+ -test -z "ldlexcdeffilephdeffilepcldgramhldgramc$(MAINTAINERCLEANFILES)" || rm -f ldlexc deffileph deffilepc ldgramh ldgramc $(MAINTAINERCLEANFILES)
mostlyclean-am: mostlyclean-hdr mostlyclean-noinstPROGRAMS \
mostlyclean-compile mostlyclean-libtool \
mostlyclean-aminfo mostlyclean-tags mostlyclean-generic \
@@ -2313,7 +2313,7 @@ ldfile.o: ldfile.c ../bfd/bfd.h $(INCDIR
$(INCDIR)/symcat.h sysdep.h config.h $(INCDIR)/fopen-same.h \
$(INCDIR)/bfdlink.h $(INCDIR)/safe-ctype.h ld.h $(INCDIR)/bin-bugs.h \
ldmisc.h ldexp.h ldlang.h ldfile.h ldmain.h ldgram.h \
- ldlex.h ldemul.h $(INCDIR)/libiberty.h
+ ldlex.h ldemul.h $(INCDIR)/libiberty.h $(INCDIR)/filenames.h
ldlang.o: ldlang.c ../bfd/bfd.h $(INCDIR)/ansidecl.h \
$(INCDIR)/symcat.h sysdep.h config.h $(INCDIR)/fopen-same.h \
$(INCDIR)/libiberty.h $(INCDIR)/safe-ctype.h $(INCDIR)/obstack.h \
Index: ld/ldfile.c
===================================================================
RCS file: /cvs/uberbaum/ld/ldfile.c,v
retrieving revision 1.27
diff -u -p -r1.27 ldfile.c
--- ld/ldfile.c 19 Mar 2003 09:56:06 -0000 1.27
+++ ld/ldfile.c 25 Mar 2003 00:24:28 -0000
@@ -35,6 +35,7 @@ Software Foundation, 59 Temple Place - S
#include "ldlex.h"
#include "ldemul.h"
#include "libiberty.h"
+#include "filenames.h"
const char *ldfile_input_filename;
bfd_boolean ldfile_assumed_script = FALSE;
@@ -71,6 +72,39 @@ static search_arch_type *search_arch_hea
static search_arch_type **search_arch_tail_ptr = &search_arch_head;
static FILE *try_open PARAMS ((const char *name, const char *exten));
+static bfd_boolean is_sysrooted_pathname
+ PARAMS ((const char *name, bfd_boolean notsame));
+
+/* Test whether a pathname, after canonicalization, is the same or a
+ sub-directory of the sysroot directory. */
+static bfd_boolean
+is_sysrooted_pathname (name, notsame)
+ const char *name;
+ bfd_boolean notsame;
+{
+ char *realname = ld_canon_sysroot ? lrealpath (name) : NULL;
+ int len;
+ bfd_boolean result;
+
+ if (! realname)
+ return FALSE;
+
+ len = strlen (realname);
+
+ if (((! notsame && len == ld_canon_sysroot_len)
+ || (len >= ld_canon_sysroot_len
+ && IS_DIR_SEPARATOR (realname[ld_canon_sysroot_len])
+ && (realname[ld_canon_sysroot_len] = '\0') == '\0'))
+ && FILENAME_CMP (ld_canon_sysroot, realname) == 0)
+ result = TRUE;
+ else
+ result = FALSE;
+
+ if (realname)
+ free (realname);
+
+ return result;
+}
void
ldfile_add_library_path (name, cmdline)
@@ -97,7 +131,7 @@ ldfile_add_library_path (name, cmdline)
new->sysrooted = TRUE;
}
else
- new->sysrooted = FALSE;
+ new->sysrooted = is_sysrooted_pathname (new->name, FALSE);
}
/* Try to open a BFD for a lang_input_statement. */
@@ -271,7 +305,7 @@ ldfile_open_file_search (arch, entry, li
directory first. */
if (! entry->is_archive)
{
- if (entry->sysrooted && entry->filename[0] == '/')
+ if (entry->sysrooted && IS_ABSOLUTE_PATH (entry->filename))
{
char *name = concat (ld_sysroot, entry->filename,
(const char *) NULL);
@@ -284,9 +318,13 @@ ldfile_open_file_search (arch, entry, li
}
else if (ldfile_try_open_bfd (entry->filename, entry))
{
- entry->sysrooted = FALSE;
+ entry->sysrooted = IS_ABSOLUTE_PATH (entry->filename)
+ && is_sysrooted_pathname (entry->filename, TRUE);
return TRUE;
}
+
+ if (IS_ABSOLUTE_PATH (entry->filename))
+ return FALSE;
}
for (search = search_head;
@@ -315,14 +353,6 @@ ldfile_open_file_search (arch, entry, li
if (entry->is_archive)
sprintf (string, "%s%s%s%s%s%s", search->name, slash,
lib, entry->filename, arch, suffix);
- else if (entry->filename[0] == '/' || entry->filename[0] == '.'
-#if defined (__MSDOS__) || defined (_WIN32)
- || entry->filename[0] == '\\'
- || (ISALPHA (entry->filename[0])
- && entry->filename[1] == ':')
-#endif
- )
- strcpy (string, entry->filename);
else
sprintf (string, "%s%s%s", search->name, slash, entry->filename);
@@ -385,6 +415,10 @@ ldfile_open_file (entry)
again. */
if (found)
entry->search_dirs_flag = FALSE;
+ else if (entry->sysrooted && ld_sysroot
+ && IS_ABSOLUTE_PATH (entry->local_sym_name))
+ einfo (_("%F%P: cannot find %s inside %s\n"),
+ entry->local_sym_name, ld_sysroot);
else
einfo (_("%F%P: cannot find %s\n"), entry->local_sym_name);
}
Index: ld/ldmain.c
===================================================================
RCS file: /cvs/uberbaum/ld/ldmain.c,v
retrieving revision 1.64
diff -u -p -r1.64 ldmain.c
--- ld/ldmain.c 3 Mar 2003 20:01:02 -0000 1.64
+++ ld/ldmain.c 25 Mar 2003 00:24:29 -0000
@@ -72,6 +72,10 @@ char *program_name;
/* The prefix for system library directories. */
char *ld_sysroot;
+/* The canonical representation of ld_sysroot. */
+char *ld_canon_sysroot;
+int ld_canon_sysroot_len;
+
/* The file that we're creating. */
bfd *output_bfd = 0;
@@ -233,6 +237,14 @@ main (argc, argv)
if (! ld_sysroot)
#endif
ld_sysroot = TARGET_SYSTEM_ROOT;
+
+ if (ld_sysroot && *ld_sysroot)
+ ld_canon_sysroot = lrealpath (ld_sysroot);
+
+ if (ld_canon_sysroot)
+ ld_canon_sysroot_len = strlen (ld_canon_sysroot);
+ else
+ ld_canon_sysroot_len = -1;
/* Set the default BFD target based on the configured target. Doing
this permits the linker to be configured for a particular target,
Index: ld/ldmain.h
===================================================================
RCS file: /cvs/uberbaum/ld/ldmain.h,v
retrieving revision 1.4
diff -u -p -r1.4 ldmain.h
--- ld/ldmain.h 6 Jan 2003 16:13:57 -0000 1.4
+++ ld/ldmain.h 25 Mar 2003 00:24:29 -0000
@@ -24,6 +24,8 @@
extern char *program_name;
extern char *ld_sysroot;
+extern char *ld_canon_sysroot;
+extern int ld_canon_sysroot_len;
extern bfd *output_bfd;
extern char *default_target;
extern bfd_boolean trace_files;
--
Alexandre Oliva Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer aoliva at {redhat dot com, gcc.gnu.org}
CS PhD student at IC-Unicamp oliva at {lsd dot ic dot unicamp dot br, gnu.org}
Free Software Evangelist Professional serial bug killer