This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: ld doesn't relocate sysroot if called as tooldir/bin/ld


On Feb 20, 2003, Daniel Jacobowitz <drow at mvista dot com> wrote:

> On Thu, Feb 20, 2003 at 07:10:06AM -0300, Alexandre Oliva wrote:

>> What would people think of arranging for pathnames in linker
>> scripts within the sysroot to have the sysroot pathname prepended
>> to them?  This would solve the main problem of relocating a cross
>> toolchain with a glibc sysroot, because the glibc linker scripts
>> reference full pathnames in the real root.  Comments?

> Oooh.  I love it.  That'd kill one of the last truly gross hacks in my
> cross tool setup.

/me loves killing truly gross hacks :-)

Ok to install?

Index: ld/ChangeLog
from  Alexandre Oliva  <aoliva at redhat dot com>

	* ldfile.h (struct search_dirs): Added sysrooted field.
	* ldlang.h (struct lang_input_statement_struct): Likewise.
	* ldfile.c (ldfile_add_library_path): Mark sysrooted paths.
	(ldfile_open_file_search): Look for sysrooted filename
	starting with / in ld_sysroot first.  Clear sysrooted flag if
	it's found in the current directory.  Set it from the
	search directory's sysrooted flag where it is found otherwise.
	* ldlang.c (ldlang_sysrooted_script): New static variable.
	(new_afile): Mark search_file_enums as sysrooted if
	ldlang_sysrooted_script.
	(load_symbols): Set ldlang_sysrooted_script according to the
	script's sysrooted field while processing it.
	* ld.texinfo: Document INPUT behavior in sysroot.

Index: ld/ld.texinfo
===================================================================
RCS file: /cvs/uberbaum/ld/ld.texinfo,v
retrieving revision 1.87
diff -u -p -r1.87 ld.texinfo
--- ld/ld.texinfo 21 Feb 2003 10:27:06 -0000 1.87
+++ ld/ld.texinfo 26 Feb 2003 06:34:53 -0000
@@ -2305,7 +2305,12 @@ then you can put @samp{INPUT (subr.o)} i
 In fact, if you like, you can list all of your input files in the linker
 script, and then invoke the linker with nothing but a @samp{-T} option.
 
-The linker will first try to open the file in the current directory.  If
+In case a @dfn{sysroot prefix} is configured, and the filename starts
+with the @samp{/} character, and the script being processed was
+located inside the @dfn{sysroot prefix}, the filename will be looked
+for in the @dfn{sysroot prefix}.
+
+Then, the linker will try to open the file in the current directory.  If
 it is not found, the linker will search through the archive library
 search path.  See the description of @samp{-L} in @ref{Options,,Command
 Line Options}.
Index: ld/ldfile.c
===================================================================
RCS file: /cvs/uberbaum/ld/ldfile.c,v
retrieving revision 1.25
diff -u -p -r1.25 ldfile.c
--- ld/ldfile.c 6 Jan 2003 16:13:57 -0000 1.25
+++ ld/ldfile.c 26 Feb 2003 06:34:53 -0000
@@ -92,7 +92,12 @@ ldfile_add_library_path (name, cmdline)
   /* 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);
+    {
+      new->name = concat (ld_sysroot, &new->name[1], NULL);
+      new->sysrooted = TRUE;
+    }
+  else
+    new->sysrooted = FALSE;
 }
 
 /* Try to open a BFD for a lang_input_statement.  */
@@ -265,8 +270,23 @@ ldfile_open_file_search (arch, entry, li
      directory first.  */
   if (! entry->is_archive)
     {
+      if (entry->sysrooted && entry->filename[0] == '/')
+	{
+	  char *name = concat (ld_sysroot, entry->filename,
+			       (const char *) NULL);
+	  if (ldfile_try_open_bfd (name, entry))
+	    {
+	      entry->filename = name;
+	      return TRUE;
+	    }
+	  free (name);
+	}
+
       if (ldfile_try_open_bfd (entry->filename, entry))
-	return TRUE;
+	{
+	  entry->sysrooted = FALSE;
+	  return TRUE;
+	}
     }
 
   for (search = search_head;
@@ -278,7 +298,10 @@ ldfile_open_file_search (arch, entry, li
       if (entry->dynamic && ! link_info.relocateable)
 	{
 	  if (ldemul_open_dynamic_archive (arch, search, entry))
-	    return TRUE;
+	    {
+	      entry->sysrooted = search->sysrooted;
+	      return TRUE;
+	    }
 	}
 
       string = (char *) xmalloc (strlen (search->name)
@@ -306,6 +329,7 @@ ldfile_open_file_search (arch, entry, li
       if (ldfile_try_open_bfd (string, entry))
 	{
 	  entry->filename = string;
+	  entry->sysrooted = search->sysrooted;
 	  return TRUE;
 	}
 
Index: ld/ldfile.h
===================================================================
RCS file: /cvs/uberbaum/ld/ldfile.h,v
retrieving revision 1.10
diff -u -p -r1.10 ldfile.h
--- ld/ldfile.h 30 Nov 2002 08:39:45 -0000 1.10
+++ ld/ldfile.h 26 Feb 2003 06:34:53 -0000
@@ -1,12 +1,12 @@
 /* ldfile.h -
-   Copyright 1991, 1992, 1993, 1994, 1995, 2000, 2002
+   Copyright 1991, 1992, 1993, 1994, 1995, 2000, 2002, 2003
    Free Software Foundation, Inc.
 
    This file is part of GLD, the Gnu Linker.
 
    GLD is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 1, or (at your option)
+   the Free Software Foundation; either version 2, or (at your option)
    any later version.
 
    GLD is distributed in the hope that it will be useful,
@@ -37,6 +37,8 @@ typedef struct search_dirs {
   const char *name;
   /* TRUE if this is from the command line.  */
   bfd_boolean cmdline;
+  /* true if this is from within the sys-root.  */
+  bfd_boolean sysrooted;
 } search_dirs_type;
 
 extern search_dirs_type *search_head;
Index: ld/ldlang.c
===================================================================
RCS file: /cvs/uberbaum/ld/ldlang.c,v
retrieving revision 1.109
diff -u -p -r1.109 ldlang.c
--- ld/ldlang.c 21 Feb 2003 10:51:24 -0000 1.109
+++ ld/ldlang.c 26 Feb 2003 06:34:56 -0000
@@ -240,6 +240,7 @@ bfd_boolean lang_float_flag = FALSE;
 bfd_boolean delete_output_file_on_failure = FALSE;
 struct lang_nocrossrefs *nocrossref_list;
 struct unique_sections *unique_section_list;
+static bfd_boolean ldlang_sysrooted_script = FALSE;
 
 etree_type *base; /* Relocation base - or null */
 
@@ -547,6 +548,7 @@ new_afile (name, file_type, target, add_
 
   lang_has_input_file = TRUE;
   p->target = target;
+  p->sysrooted = FALSE;
   switch (file_type)
     {
     case lang_input_file_is_symbols_only_enum:
@@ -582,6 +584,7 @@ new_afile (name, file_type, target, add_
       p->search_dirs_flag = TRUE;
       break;
     case lang_input_file_is_search_file_enum:
+      p->sysrooted = ldlang_sysrooted_script;
       p->filename = name;
       p->is_archive = FALSE;
       p->real = TRUE;
@@ -1539,6 +1542,7 @@ load_symbols (entry, place)
       bfd_error_type err;
       lang_statement_list_type *hold;
       bfd_boolean bad_load = TRUE;
+      bfd_boolean save_ldlang_sysrooted_script;
 
       err = bfd_get_error ();
 
@@ -1570,12 +1574,15 @@ load_symbols (entry, place)
 
       hold = stat_ptr;
       stat_ptr = place;
+      save_ldlang_sysrooted_script = ldlang_sysrooted_script;
+      ldlang_sysrooted_script = entry->sysrooted;
 
       ldfile_assumed_script = TRUE;
       parser_input = input_script;
       yyparse ();
       ldfile_assumed_script = FALSE;
 
+      ldlang_sysrooted_script = save_ldlang_sysrooted_script;
       stat_ptr = hold;
 
       return ! bad_load;
Index: ld/ldlang.h
===================================================================
RCS file: /cvs/uberbaum/ld/ldlang.h,v
retrieving revision 1.26
diff -u -p -r1.26 ldlang.h
--- ld/ldlang.h 21 Feb 2003 10:51:24 -0000 1.26
+++ ld/ldlang.h 26 Feb 2003 06:34:56 -0000
@@ -230,6 +230,12 @@ typedef struct lang_input_statement_stru
   /* 1 means search a set of directories for this file.  */
   bfd_boolean search_dirs_flag;
 
+  /* 1 means this was found in a search directory marked as sysrooted,
+     if search_dirs_flag is false, otherwise, that it should be
+     searched in ld_sysroot before any other location, as long as it
+     starts with a slash.  */
+  bfd_boolean sysrooted;
+
   /* 1 means this is base file of incremental load.
      Do not load this file's text or data.
      Also default text_start to after this file's bss.  */
-- 
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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]