Re: [PATCH] gcc-{ar,nm,ranlib}: Find binutils binaries relative to self

2013-06-19 Thread Matthias Klose
Am 27.11.2012 19:14, schrieb Meador Inge:
 On 11/26/2012 09:05 AM, Richard Biener wrote:
 
 On Wed, Nov 7, 2012 at 10:51 PM, Meador Inge mead...@codesourcery.com 
 wrote:
 Ping ^ 4.

 Ok.
 
 Thanks for the review.  Committed to trunk.

This did break gcc-ar and gcc-nm; now a regression on the 4.8 branch.

$ gcc-ar-4.8 -h
gcc-ar-4.8: Cannot find plugin 'liblto_plugin.so'

the plugin is *not* installed with x permission flags (which seems to be the
standard for shared libraries).   You did change the code to use find_a_file
which searches only for files with the x bit set.

Work around is to install the plugin with the x bits set, or use some helper
function which doesn't look for the x bits.  I assume that wasn't catched,
because the plugin then was found in another location?

  Matthias



Re: [PATCH] gcc-{ar,nm,ranlib}: Find binutils binaries relative to self

2013-06-19 Thread Jakub Jelinek
On Wed, Jun 19, 2013 at 02:03:34PM +0200, Matthias Klose wrote:
 Am 27.11.2012 19:14, schrieb Meador Inge:
  On 11/26/2012 09:05 AM, Richard Biener wrote:
  
  On Wed, Nov 7, 2012 at 10:51 PM, Meador Inge mead...@codesourcery.com 
  wrote:
  Ping ^ 4.
 
  Ok.
  
  Thanks for the review.  Committed to trunk.
 
 This did break gcc-ar and gcc-nm; now a regression on the 4.8 branch.
 
 $ gcc-ar-4.8 -h
 gcc-ar-4.8: Cannot find plugin 'liblto_plugin.so'
 
 the plugin is *not* installed with x permission flags (which seems to be the
 standard for shared libraries).   You did change the code to use find_a_file
 which searches only for files with the x bit set.

That actually is the standard for shared libraries, the linker creates
libraries with those permissions and libtool/automake installs them that way
too.  So if you override this, you need to cope with that decision.

Jakub


Re: [PATCH] gcc-{ar,nm,ranlib}: Find binutils binaries relative to self

2013-06-19 Thread Matthias Klose
Am 19.06.2013 14:03, schrieb Matthias Klose:
 $ gcc-ar-4.8 -h
 gcc-ar-4.8: Cannot find plugin 'liblto_plugin.so'
 
 the plugin is *not* installed with x permission flags (which seems to be the
 standard for shared libraries).   You did change the code to use find_a_file
 which searches only for files with the x bit set.
 
 Work around is to install the plugin with the x bits set, or use some helper
 function which doesn't look for the x bits.  I assume that wasn't catched,
 because the plugin then was found in another location?

openend 57651 for that.

now, working around the permission bit, I get:

$ gcc-ar-4.8
gcc-ar-4.8: Cannot find binary 'ar'

so it only searches ar in the given paths, not on the path of the file system
(/usr/bin in this case)



Re: [PATCH] gcc-{ar,nm,ranlib}: Find binutils binaries relative to self

2013-06-19 Thread Matthias Klose
Am 19.06.2013 14:10, schrieb Jakub Jelinek:
 On Wed, Jun 19, 2013 at 02:03:34PM +0200, Matthias Klose wrote:
 Am 27.11.2012 19:14, schrieb Meador Inge:
 On 11/26/2012 09:05 AM, Richard Biener wrote:

 On Wed, Nov 7, 2012 at 10:51 PM, Meador Inge mead...@codesourcery.com 
 wrote:
 Ping ^ 4.

 Ok.

 Thanks for the review.  Committed to trunk.

 This did break gcc-ar and gcc-nm; now a regression on the 4.8 branch.

 $ gcc-ar-4.8 -h
 gcc-ar-4.8: Cannot find plugin 'liblto_plugin.so'

 the plugin is *not* installed with x permission flags (which seems to be the
 standard for shared libraries).   You did change the code to use find_a_file
 which searches only for files with the x bit set.
 
 That actually is the standard for shared libraries, the linker creates
 libraries with those permissions and libtool/automake installs them that way
 too.  So if you override this, you need to cope with that decision.

well, I did fix this assumption last year in gcc.c, then lets fix it in other
places too, just adding a mode parameter to the public find_a_file function.
Testing the attached patch.

  Matthias


Index: gcc-ar.c
===
--- gcc-ar.c(revision 200203)
+++ gcc-ar.c(working copy)
@@ -136,7 +136,7 @@
   setup_prefixes (av[0]);
 
   /* Find the GCC LTO plugin */
-  plugin = find_a_file (target_path, LTOPLUGINSONAME);
+  plugin = find_a_file (target_path, LTOPLUGINSONAME, R_OK);
   if (!plugin)
 {
   fprintf (stderr, %s: Cannot find plugin '%s'\n, av[0], 
LTOPLUGINSONAME);
@@ -151,7 +151,7 @@
   const char *cross_exe_name;
 
   cross_exe_name = concat (target_machine, -, PERSONALITY, NULL);
-  exe_name = find_a_file (path, cross_exe_name);
+  exe_name = find_a_file (path, cross_exe_name, X_OK);
   if (!exe_name)
{
  fprintf (stderr, %s: Cannot find binary '%s'\n, av[0],
Index: file-find.c
===
--- file-find.c (revision 200203)
+++ file-find.c (working copy)
@@ -31,7 +31,7 @@
 }
 
 char *
-find_a_file (struct path_prefix *pprefix, const char *name)
+find_a_file (struct path_prefix *pprefix, const char *name, int mode)
 {
   char *temp;
   struct prefix_list *pl;
@@ -50,7 +50,7 @@
 
   if (IS_ABSOLUTE_PATH (name))
 {
-  if (access (name, X_OK) == 0)
+  if (access (name, mode) == 0)
{
  strcpy (temp, name);
 
@@ -66,7 +66,7 @@
   strcpy (temp, name);
strcat (temp, HOST_EXECUTABLE_SUFFIX);
 
-   if (access (temp, X_OK) == 0)
+   if (access (temp, mode) == 0)
  return temp;
 #endif
 
@@ -83,7 +83,7 @@
 
if (stat (temp, st) = 0
 ! S_ISDIR (st.st_mode)
-access (temp, X_OK) == 0)
+access (temp, mode) == 0)
  return temp;
 
 #ifdef HOST_EXECUTABLE_SUFFIX
@@ -93,7 +93,7 @@
 
if (stat (temp, st) = 0
 ! S_ISDIR (st.st_mode)
-access (temp, X_OK) == 0)
+access (temp, mode) == 0)
  return temp;
 #endif
   }
Index: file-find.h
===
--- file-find.h (revision 200203)
+++ file-find.h (working copy)
@@ -38,7 +38,7 @@
 };
 
 extern void find_file_set_debug (bool);
-extern char *find_a_file (struct path_prefix *, const char *);
+extern char *find_a_file (struct path_prefix *, const char *, int mode);
 extern void add_prefix (struct path_prefix *, const char *);
 extern void prefix_from_env (const char *, struct path_prefix *);
 extern void prefix_from_string (const char *, struct path_prefix *);
Index: collect2.c
===
--- collect2.c  (revision 200203)
+++ collect2.c  (working copy)
@@ -1110,55 +1110,55 @@
   if (ld_file_name == 0)
 #endif
 #ifdef REAL_LD_FILE_NAME
-  ld_file_name = find_a_file (path, REAL_LD_FILE_NAME);
+ld_file_name = find_a_file (path, REAL_LD_FILE_NAME, X_OK);
   if (ld_file_name == 0)
 #endif
   /* Search the (target-specific) compiler dirs for ld'.  */
-  ld_file_name = find_a_file (cpath, real_ld_suffix);
+ld_file_name = find_a_file (cpath, real_ld_suffix, X_OK);
   /* Likewise for `collect-ld'.  */
   if (ld_file_name == 0)
 {
-  ld_file_name = find_a_file (cpath, collect_ld_suffix);
+  ld_file_name = find_a_file (cpath, collect_ld_suffix, X_OK);
   use_collect_ld = ld_file_name != 0;
 }
   /* Search the compiler directories for `ld'.  We have protection against
  recursive calls in find_a_file.  */
   if (ld_file_name == 0)
-ld_file_name = find_a_file (cpath, ld_suffixes[selected_linker]);
+ld_file_name = find_a_file (cpath, ld_suffixes[selected_linker], X_OK);
   /* Search the ordinary system bin directories
  for `ld' (if native linking) or `TARGET-ld' (if cross).  */
   if (ld_file_name == 0)
-ld_file_name = find_a_file (path, full_ld_suffixes[selected_linker]);
+ld_file_name = find_a_file (path, 

Re: [PATCH] gcc-{ar,nm,ranlib}: Find binutils binaries relative to self

2013-06-19 Thread Jakub Jelinek
On Wed, Jun 19, 2013 at 05:29:42PM +0200, Matthias Klose wrote:
 well, I did fix this assumption last year in gcc.c, then lets fix it in other
 places too, just adding a mode parameter to the public find_a_file function.
 Testing the attached patch.

Ok, provided you:
1) write proper ChangeLog
2) adjust the gcc-ar.c change (because it won't apply cleanly now that
   I've committed the other gcc-ar.c fix
3) 
 --- file-find.h   (revision 200203)
 +++ file-find.h   (working copy)
 @@ -38,7 +38,7 @@
  };
  
  extern void find_file_set_debug (bool);
 -extern char *find_a_file (struct path_prefix *, const char *);
 +extern char *find_a_file (struct path_prefix *, const char *, int mode);

Remove  mode above, none of the arguments have names, so adding it
is both inconsistent and useless.

4)
if (ld_file_name == 0)
 -ld_file_name = find_a_file (path, full_ld_suffixes[selected_linker]);
 +ld_file_name = find_a_file (path, full_ld_suffixes[selected_linker], 
 X_OK);

This line looks too long now.

Jakub


Re: [PATCH] gcc-{ar,nm,ranlib}: Find binutils binaries relative to self

2013-06-19 Thread Matthias Klose
Am 19.06.2013 19:46, schrieb Jakub Jelinek:
 On Wed, Jun 19, 2013 at 05:29:42PM +0200, Matthias Klose wrote:
 well, I did fix this assumption last year in gcc.c, then lets fix it in other
 places too, just adding a mode parameter to the public find_a_file function.
 Testing the attached patch.
 
 Ok, provided you:
 1) write proper ChangeLog
 2) adjust the gcc-ar.c change (because it won't apply cleanly now that
I've committed the other gcc-ar.c fix
 3) 
 --- file-find.h  (revision 200203)
 +++ file-find.h  (working copy)
 @@ -38,7 +38,7 @@
  };
  
  extern void find_file_set_debug (bool);
 -extern char *find_a_file (struct path_prefix *, const char *);
 +extern char *find_a_file (struct path_prefix *, const char *, int mode);
 
 Remove  mode above, none of the arguments have names, so adding it
 is both inconsistent and useless.
 
 4)
if (ld_file_name == 0)
 -ld_file_name = find_a_file (path, full_ld_suffixes[selected_linker]);
 +ld_file_name = find_a_file (path, full_ld_suffixes[selected_linker], 
 X_OK);
 
 This line looks too long now.

addressed 1-3, the semicolon is in column 79. committed to the trunk and the 4.8
branch as attached.

  Matthias



2013-06-19  Matthias Klose  d...@ubuntu.com

PR driver/57651
* file-find.h (find_a_file): Add a mode parameter.
* file-find.c (find_a_file): Likewise.
* gcc-ar.c (main): Call find_a_file with R_OK for the plugin,
with X_OK for the executables.
* collect2.c (main): Call find_a_file with X_OK.

Index: gcc-ar.c
===
--- gcc-ar.c(revision 200217)
+++ gcc-ar.c(working copy)
@@ -136,7 +136,7 @@
   setup_prefixes (av[0]);
 
   /* Find the GCC LTO plugin */
-  plugin = find_a_file (target_path, LTOPLUGINSONAME);
+  plugin = find_a_file (target_path, LTOPLUGINSONAME, R_OK);
   if (!plugin)
 {
   fprintf (stderr, %s: Cannot find plugin '%s'\n, av[0], 
LTOPLUGINSONAME);
@@ -144,14 +144,14 @@
 }
 
   /* Find the wrapped binutils program.  */
-  exe_name = find_a_file (target_path, PERSONALITY);
+  exe_name = find_a_file (target_path, PERSONALITY, X_OK);
   if (!exe_name)
 {
   const char *real_exe_name = PERSONALITY;
 #ifdef CROSS_DIRECTORY_STRUCTURE
   real_exe_name = concat (target_machine, -, PERSONALITY, NULL);
 #endif
-  exe_name = find_a_file (path, real_exe_name);
+  exe_name = find_a_file (path, real_exe_name, X_OK);
   if (!exe_name)
{
  fprintf (stderr, %s: Cannot find binary '%s'\n, av[0],
Index: file-find.c
===
--- file-find.c (revision 200217)
+++ file-find.c (working copy)
@@ -31,7 +31,7 @@
 }
 
 char *
-find_a_file (struct path_prefix *pprefix, const char *name)
+find_a_file (struct path_prefix *pprefix, const char *name, int mode)
 {
   char *temp;
   struct prefix_list *pl;
@@ -50,7 +50,7 @@
 
   if (IS_ABSOLUTE_PATH (name))
 {
-  if (access (name, X_OK) == 0)
+  if (access (name, mode) == 0)
{
  strcpy (temp, name);
 
@@ -66,7 +66,7 @@
   strcpy (temp, name);
strcat (temp, HOST_EXECUTABLE_SUFFIX);
 
-   if (access (temp, X_OK) == 0)
+   if (access (temp, mode) == 0)
  return temp;
 #endif
 
@@ -83,7 +83,7 @@
 
if (stat (temp, st) = 0
 ! S_ISDIR (st.st_mode)
-access (temp, X_OK) == 0)
+access (temp, mode) == 0)
  return temp;
 
 #ifdef HOST_EXECUTABLE_SUFFIX
@@ -93,7 +93,7 @@
 
if (stat (temp, st) = 0
 ! S_ISDIR (st.st_mode)
-access (temp, X_OK) == 0)
+access (temp, mode) == 0)
  return temp;
 #endif
   }
Index: file-find.h
===
--- file-find.h (revision 200217)
+++ file-find.h (working copy)
@@ -38,7 +38,7 @@
 };
 
 extern void find_file_set_debug (bool);
-extern char *find_a_file (struct path_prefix *, const char *);
+extern char *find_a_file (struct path_prefix *, const char *, int);
 extern void add_prefix (struct path_prefix *, const char *);
 extern void prefix_from_env (const char *, struct path_prefix *);
 extern void prefix_from_string (const char *, struct path_prefix *);
Index: collect2.c
===
--- collect2.c  (revision 200217)
+++ collect2.c  (working copy)
@@ -1110,55 +1110,55 @@
   if (ld_file_name == 0)
 #endif
 #ifdef REAL_LD_FILE_NAME
-  ld_file_name = find_a_file (path, REAL_LD_FILE_NAME);
+  ld_file_name = find_a_file (path, REAL_LD_FILE_NAME, X_OK);
   if (ld_file_name == 0)
 #endif
   /* Search the (target-specific) compiler dirs for ld'.  */
-  ld_file_name = find_a_file (cpath, real_ld_suffix);
+  ld_file_name = find_a_file (cpath, real_ld_suffix, X_OK);
   /* Likewise for `collect-ld'.  */
   if (ld_file_name == 0)
 {
-  ld_file_name = find_a_file (cpath, collect_ld_suffix);
+  

Re: [PATCH] gcc-{ar,nm,ranlib}: Find binutils binaries relative to self

2012-11-27 Thread Meador Inge
On 11/26/2012 09:05 AM, Richard Biener wrote:

 On Wed, Nov 7, 2012 at 10:51 PM, Meador Inge mead...@codesourcery.com wrote:
 Ping ^ 4.
 
 Ok.

Thanks for the review.  Committed to trunk.

-- 
Meador Inge
CodeSourcery / Mentor Embedded
http://www.mentor.com/embedded-software


Re: [PATCH] gcc-{ar,nm,ranlib}: Find binutils binaries relative to self

2012-11-26 Thread Richard Biener
On Wed, Nov 7, 2012 at 10:51 PM, Meador Inge mead...@codesourcery.com wrote:
 Ping ^ 4.

Ok.

Thanks,
Richard.

 On 10/29/2012 10:46 AM, Meador Inge wrote:
 Ping ^ 3.

 On 10/18/2012 10:30 AM, Meador Inge wrote:
 Ping ^ 2.

 On 10/09/2012 09:44 PM, Meador Inge wrote:
 Ping.

 On 10/04/2012 03:45 PM, Meador Inge wrote:
 Hi All,

 Currently the gcc-{ar,nm,ranlib} utilities assume that binutils is in
 path when invoking the wrapped binutils program.  This goes against the
 accepted practice in GCC to find sub-programs relative to where the
 GCC binaries are stored and to not make assumptions about the PATH.

 This patch changes the gcc-{ar,nm,ranlib} utilities to do the same
 by factoring out some utility code for finding files from collect2.c.
 These functions are then leveraged to find the binutils programs.
 Note that similar code exist in gcc.c.  Perhaps one day everything
 can be merged to the file-find files.

 Tested for Windows and GNU/Linux hosts and i686-pc-linux-gnu and
 arm-none-eabi targets.  OK?

 P.S. I am not quite sure what is best for the copyrights and contributed
 by comments in the file-find* files I added since that code was just 
 moved.
 This patch drops the contributed by and keeps all the copyright dates from
 collect2.c.

 2012-10-04  Meador Inge  mead...@codesourcery.com

* collect2.c (main): Call find_file_set_debug.
(find_a_find, add_prefix, prefix_from_env, prefix_from_string):
Factor out into ...
* file-find.c (New file): ... here and ...
* file-find.h (New file): ... here.
* gcc-ar.c (standard_exec_prefix): New variable.
(standard_libexec_prefix): Ditto.
(tooldir_base_prefix) Ditto.
(self_exec_prefix): Ditto.
(self_libexec_prefix): Ditto.
(self_tooldir_prefix): Ditto.
(target_version): Ditto.
(path): Ditto.
(target_path): Ditto.
(setup_prefixes): New function.
(main): Rework how wrapped programs are found.
* Makefile.in (OBJS-libcommon-target): Add file-find.o.
(AR_OBJS): New variable.
(gcc-ar$(exeext)): Add dependency on $(AR_OBJS).
(gcc-nm$(exeext)): Ditto.
(gcc-ranlib(exeext)): Ditto.
(COLLECT2_OBJS): Add file-find.o.
(collect2.o): Add file-find.h prerequisite.
(file-find.o): New rule.

 Index: gcc/gcc-ar.c
 ===
 --- gcc/gcc-ar.c   (revision 192099)
 +++ gcc/gcc-ar.c   (working copy)
 @@ -21,21 +21,110 @@
  #include config.h
  #include system.h
  #include libiberty.h
 +#include file-find.h

  #ifndef PERSONALITY
  #error Please set personality
  #endif

 +/* The exec prefix as derived at compile-time from --prefix.  */
 +
 +static const char standard_exec_prefix[] = STANDARD_EXEC_PREFIX;
 +
 +/* The libexec prefix as derived at compile-time from --prefix.  */
 +
  static const char standard_libexec_prefix[] = STANDARD_LIBEXEC_PREFIX;
 +
 +/* The bindir prefix as derived at compile-time from --prefix.  */
 +
  static const char standard_bin_prefix[] = STANDARD_BINDIR_PREFIX;
 -static const char *const target_machine = TARGET_MACHINE;

 +/* A relative path to be used in finding the location of tools
 +   relative to this program.  */
 +
 +static const char *const tooldir_base_prefix = TOOLDIR_BASE_PREFIX;
 +
 +/* The exec prefix as relocated from the location of this program.  */
 +
 +static const char *self_exec_prefix;
 +
 +/* The libexec prefix as relocated from the location of this program.  */
 +
 +static const char *self_libexec_prefix;
 +
 +/* The tools prefix as relocated from the location of this program.  */
 +
 +static const char *self_tooldir_prefix;
 +
 +/* The name of the machine that is being targeted.  */
 +
 +static const char *const target_machine = DEFAULT_TARGET_MACHINE;
 +
 +/* The target version.  */
 +
 +static const char *const target_version = DEFAULT_TARGET_VERSION;
 +
 +/* The collection of target specific path prefixes.  */
 +
 +static struct path_prefix target_path;
 +
 +/* The collection path prefixes.  */
 +
 +static struct path_prefix path;
 +
 +/* The directory separator.  */
 +
  static const char dir_separator[] = { DIR_SEPARATOR, 0 };

 +static void
 +setup_prefixes (const char *exec_path)
 +{
 +  const char *self;
 +
 +  self = getenv (GCC_EXEC_PREFIX);
 +  if (!self)
 +self = exec_path;
 +  else
 +self = concat (self, gcc- PERSONALITY, NULL);
 +
 +  /* Relocate the exec prefix.  */
 +  self_exec_prefix = make_relative_prefix (self,
 + standard_bin_prefix,
 + standard_exec_prefix);
 +  if (self_exec_prefix == NULL)
 +self_exec_prefix = standard_exec_prefix;
 +
 +  /* Relocate libexec prefix.  */
 +  self_libexec_prefix = make_relative_prefix (self,
 +standard_bin_prefix,
 +standard_libexec_prefix);
 +  if (self_libexec_prefix == NULL)
 +self_libexec_prefix = standard_libexec_prefix;
 +
 +
 +  /* Build the relative 

Re: [PATCH] gcc-{ar,nm,ranlib}: Find binutils binaries relative to self

2012-11-07 Thread Meador Inge
Ping ^ 4.

On 10/29/2012 10:46 AM, Meador Inge wrote:
 Ping ^ 3.
 
 On 10/18/2012 10:30 AM, Meador Inge wrote:
 Ping ^ 2.

 On 10/09/2012 09:44 PM, Meador Inge wrote:
 Ping.

 On 10/04/2012 03:45 PM, Meador Inge wrote:
 Hi All,

 Currently the gcc-{ar,nm,ranlib} utilities assume that binutils is in
 path when invoking the wrapped binutils program.  This goes against the
 accepted practice in GCC to find sub-programs relative to where the
 GCC binaries are stored and to not make assumptions about the PATH.

 This patch changes the gcc-{ar,nm,ranlib} utilities to do the same
 by factoring out some utility code for finding files from collect2.c.
 These functions are then leveraged to find the binutils programs.
 Note that similar code exist in gcc.c.  Perhaps one day everything
 can be merged to the file-find files.

 Tested for Windows and GNU/Linux hosts and i686-pc-linux-gnu and
 arm-none-eabi targets.  OK?

 P.S. I am not quite sure what is best for the copyrights and contributed
 by comments in the file-find* files I added since that code was just moved.
 This patch drops the contributed by and keeps all the copyright dates from
 collect2.c.

 2012-10-04  Meador Inge  mead...@codesourcery.com

* collect2.c (main): Call find_file_set_debug.
(find_a_find, add_prefix, prefix_from_env, prefix_from_string):
Factor out into ...
* file-find.c (New file): ... here and ...
* file-find.h (New file): ... here.
* gcc-ar.c (standard_exec_prefix): New variable.
(standard_libexec_prefix): Ditto.
(tooldir_base_prefix) Ditto.
(self_exec_prefix): Ditto.
(self_libexec_prefix): Ditto.
(self_tooldir_prefix): Ditto.
(target_version): Ditto.
(path): Ditto.
(target_path): Ditto.
(setup_prefixes): New function.
(main): Rework how wrapped programs are found.
* Makefile.in (OBJS-libcommon-target): Add file-find.o.
(AR_OBJS): New variable.
(gcc-ar$(exeext)): Add dependency on $(AR_OBJS).
(gcc-nm$(exeext)): Ditto.
(gcc-ranlib(exeext)): Ditto.
(COLLECT2_OBJS): Add file-find.o.
(collect2.o): Add file-find.h prerequisite.
(file-find.o): New rule.

 Index: gcc/gcc-ar.c
 ===
 --- gcc/gcc-ar.c   (revision 192099)
 +++ gcc/gcc-ar.c   (working copy)
 @@ -21,21 +21,110 @@
  #include config.h
  #include system.h
  #include libiberty.h
 +#include file-find.h
  
  #ifndef PERSONALITY
  #error Please set personality
  #endif
  
 +/* The exec prefix as derived at compile-time from --prefix.  */
 +
 +static const char standard_exec_prefix[] = STANDARD_EXEC_PREFIX;
 +
 +/* The libexec prefix as derived at compile-time from --prefix.  */
 +
  static const char standard_libexec_prefix[] = STANDARD_LIBEXEC_PREFIX;
 +
 +/* The bindir prefix as derived at compile-time from --prefix.  */
 +
  static const char standard_bin_prefix[] = STANDARD_BINDIR_PREFIX;
 -static const char *const target_machine = TARGET_MACHINE;
  
 +/* A relative path to be used in finding the location of tools
 +   relative to this program.  */
 +
 +static const char *const tooldir_base_prefix = TOOLDIR_BASE_PREFIX;
 +
 +/* The exec prefix as relocated from the location of this program.  */
 +
 +static const char *self_exec_prefix;
 +
 +/* The libexec prefix as relocated from the location of this program.  */
 +
 +static const char *self_libexec_prefix;
 +
 +/* The tools prefix as relocated from the location of this program.  */
 +
 +static const char *self_tooldir_prefix;
 +
 +/* The name of the machine that is being targeted.  */
 +
 +static const char *const target_machine = DEFAULT_TARGET_MACHINE;
 +
 +/* The target version.  */
 +
 +static const char *const target_version = DEFAULT_TARGET_VERSION;
 +
 +/* The collection of target specific path prefixes.  */
 +
 +static struct path_prefix target_path;
 +
 +/* The collection path prefixes.  */
 +
 +static struct path_prefix path;
 +
 +/* The directory separator.  */
 +
  static const char dir_separator[] = { DIR_SEPARATOR, 0 };
  
 +static void
 +setup_prefixes (const char *exec_path)
 +{
 +  const char *self;
 +
 +  self = getenv (GCC_EXEC_PREFIX);
 +  if (!self)
 +self = exec_path;
 +  else
 +self = concat (self, gcc- PERSONALITY, NULL);
 +
 +  /* Relocate the exec prefix.  */
 +  self_exec_prefix = make_relative_prefix (self,
 + standard_bin_prefix,
 + standard_exec_prefix);
 +  if (self_exec_prefix == NULL)
 +self_exec_prefix = standard_exec_prefix;
 +
 +  /* Relocate libexec prefix.  */
 +  self_libexec_prefix = make_relative_prefix (self,
 +standard_bin_prefix,
 +standard_libexec_prefix);
 +  if (self_libexec_prefix == NULL)
 +self_libexec_prefix = standard_libexec_prefix;
 +
 +
 +  /* Build the relative path to the target-specific tool directory.  */
 +  self_tooldir_prefix = concat 

Re: [PATCH] gcc-{ar,nm,ranlib}: Find binutils binaries relative to self

2012-10-29 Thread Meador Inge
Ping ^ 3.

On 10/18/2012 10:30 AM, Meador Inge wrote:
 Ping ^ 2.
 
 On 10/09/2012 09:44 PM, Meador Inge wrote:
 Ping.

 On 10/04/2012 03:45 PM, Meador Inge wrote:
 Hi All,

 Currently the gcc-{ar,nm,ranlib} utilities assume that binutils is in
 path when invoking the wrapped binutils program.  This goes against the
 accepted practice in GCC to find sub-programs relative to where the
 GCC binaries are stored and to not make assumptions about the PATH.

 This patch changes the gcc-{ar,nm,ranlib} utilities to do the same
 by factoring out some utility code for finding files from collect2.c.
 These functions are then leveraged to find the binutils programs.
 Note that similar code exist in gcc.c.  Perhaps one day everything
 can be merged to the file-find files.

 Tested for Windows and GNU/Linux hosts and i686-pc-linux-gnu and
 arm-none-eabi targets.  OK?

 P.S. I am not quite sure what is best for the copyrights and contributed
 by comments in the file-find* files I added since that code was just moved.
 This patch drops the contributed by and keeps all the copyright dates from
 collect2.c.

 2012-10-04  Meador Inge  mead...@codesourcery.com

 * collect2.c (main): Call find_file_set_debug.
 (find_a_find, add_prefix, prefix_from_env, prefix_from_string):
 Factor out into ...
 * file-find.c (New file): ... here and ...
 * file-find.h (New file): ... here.
 * gcc-ar.c (standard_exec_prefix): New variable.
 (standard_libexec_prefix): Ditto.
 (tooldir_base_prefix) Ditto.
 (self_exec_prefix): Ditto.
 (self_libexec_prefix): Ditto.
 (self_tooldir_prefix): Ditto.
 (target_version): Ditto.
 (path): Ditto.
 (target_path): Ditto.
 (setup_prefixes): New function.
 (main): Rework how wrapped programs are found.
 * Makefile.in (OBJS-libcommon-target): Add file-find.o.
 (AR_OBJS): New variable.
 (gcc-ar$(exeext)): Add dependency on $(AR_OBJS).
 (gcc-nm$(exeext)): Ditto.
 (gcc-ranlib(exeext)): Ditto.
 (COLLECT2_OBJS): Add file-find.o.
 (collect2.o): Add file-find.h prerequisite.
 (file-find.o): New rule.

 Index: gcc/gcc-ar.c
 ===
 --- gcc/gcc-ar.c(revision 192099)
 +++ gcc/gcc-ar.c(working copy)
 @@ -21,21 +21,110 @@
  #include config.h
  #include system.h
  #include libiberty.h
 +#include file-find.h
  
  #ifndef PERSONALITY
  #error Please set personality
  #endif
  
 +/* The exec prefix as derived at compile-time from --prefix.  */
 +
 +static const char standard_exec_prefix[] = STANDARD_EXEC_PREFIX;
 +
 +/* The libexec prefix as derived at compile-time from --prefix.  */
 +
  static const char standard_libexec_prefix[] = STANDARD_LIBEXEC_PREFIX;
 +
 +/* The bindir prefix as derived at compile-time from --prefix.  */
 +
  static const char standard_bin_prefix[] = STANDARD_BINDIR_PREFIX;
 -static const char *const target_machine = TARGET_MACHINE;
  
 +/* A relative path to be used in finding the location of tools
 +   relative to this program.  */
 +
 +static const char *const tooldir_base_prefix = TOOLDIR_BASE_PREFIX;
 +
 +/* The exec prefix as relocated from the location of this program.  */
 +
 +static const char *self_exec_prefix;
 +
 +/* The libexec prefix as relocated from the location of this program.  */
 +
 +static const char *self_libexec_prefix;
 +
 +/* The tools prefix as relocated from the location of this program.  */
 +
 +static const char *self_tooldir_prefix;
 +
 +/* The name of the machine that is being targeted.  */
 +
 +static const char *const target_machine = DEFAULT_TARGET_MACHINE;
 +
 +/* The target version.  */
 +
 +static const char *const target_version = DEFAULT_TARGET_VERSION;
 +
 +/* The collection of target specific path prefixes.  */
 +
 +static struct path_prefix target_path;
 +
 +/* The collection path prefixes.  */
 +
 +static struct path_prefix path;
 +
 +/* The directory separator.  */
 +
  static const char dir_separator[] = { DIR_SEPARATOR, 0 };
  
 +static void
 +setup_prefixes (const char *exec_path)
 +{
 +  const char *self;
 +
 +  self = getenv (GCC_EXEC_PREFIX);
 +  if (!self)
 +self = exec_path;
 +  else
 +self = concat (self, gcc- PERSONALITY, NULL);
 +
 +  /* Relocate the exec prefix.  */
 +  self_exec_prefix = make_relative_prefix (self,
 +  standard_bin_prefix,
 +  standard_exec_prefix);
 +  if (self_exec_prefix == NULL)
 +self_exec_prefix = standard_exec_prefix;
 +
 +  /* Relocate libexec prefix.  */
 +  self_libexec_prefix = make_relative_prefix (self,
 + standard_bin_prefix,
 + standard_libexec_prefix);
 +  if (self_libexec_prefix == NULL)
 +self_libexec_prefix = standard_libexec_prefix;
 +
 +
 +  /* Build the relative path to the target-specific tool directory.  */
 +  self_tooldir_prefix = concat (tooldir_base_prefix, target_machine,
 +   

Re: [PATCH] gcc-{ar,nm,ranlib}: Find binutils binaries relative to self

2012-10-19 Thread Meador Inge
On 10/18/2012 01:33 PM, Bernhard Reutner-Fischer wrote:

 On 18 October 2012 17:30:20 Meador Inge mead...@codesourcery.com wrote:
 Ping ^ 2
 
 Been a while but wasn't --with-build-sysroot for exactly this?

AFAICT, no.  --with-build-sysroot seems to be used for setting a different
sysroot to use for compiling target libraries while GCC is being built [1].
This patch fixes the gcc-{ar,nm,ranlib} programs that are built and deployed
with GCC to not rely on the current PATH when running the binutils programs
they are wrapping.

[1] http://gcc.gnu.org/install/configure.html

-- 
Meador Inge
CodeSourcery / Mentor Embedded


Re: [PATCH] gcc-{ar,nm,ranlib}: Find binutils binaries relative to self

2012-10-19 Thread Meador Inge
CC'ing the LTO maintainers.

On 10/18/2012 10:30 AM, Meador Inge wrote:
 Ping ^ 2.
 
 On 10/09/2012 09:44 PM, Meador Inge wrote:
 Ping.

 On 10/04/2012 03:45 PM, Meador Inge wrote:
 Hi All,

 Currently the gcc-{ar,nm,ranlib} utilities assume that binutils is in
 path when invoking the wrapped binutils program.  This goes against the
 accepted practice in GCC to find sub-programs relative to where the
 GCC binaries are stored and to not make assumptions about the PATH.

 This patch changes the gcc-{ar,nm,ranlib} utilities to do the same
 by factoring out some utility code for finding files from collect2.c.
 These functions are then leveraged to find the binutils programs.
 Note that similar code exist in gcc.c.  Perhaps one day everything
 can be merged to the file-find files.

 Tested for Windows and GNU/Linux hosts and i686-pc-linux-gnu and
 arm-none-eabi targets.  OK?

 P.S. I am not quite sure what is best for the copyrights and contributed
 by comments in the file-find* files I added since that code was just moved.
 This patch drops the contributed by and keeps all the copyright dates from
 collect2.c.

 2012-10-04  Meador Inge  mead...@codesourcery.com

 * collect2.c (main): Call find_file_set_debug.
 (find_a_find, add_prefix, prefix_from_env, prefix_from_string):
 Factor out into ...
 * file-find.c (New file): ... here and ...
 * file-find.h (New file): ... here.
 * gcc-ar.c (standard_exec_prefix): New variable.
 (standard_libexec_prefix): Ditto.
 (tooldir_base_prefix) Ditto.
 (self_exec_prefix): Ditto.
 (self_libexec_prefix): Ditto.
 (self_tooldir_prefix): Ditto.
 (target_version): Ditto.
 (path): Ditto.
 (target_path): Ditto.
 (setup_prefixes): New function.
 (main): Rework how wrapped programs are found.
 * Makefile.in (OBJS-libcommon-target): Add file-find.o.
 (AR_OBJS): New variable.
 (gcc-ar$(exeext)): Add dependency on $(AR_OBJS).
 (gcc-nm$(exeext)): Ditto.
 (gcc-ranlib(exeext)): Ditto.
 (COLLECT2_OBJS): Add file-find.o.
 (collect2.o): Add file-find.h prerequisite.
 (file-find.o): New rule.

 Index: gcc/gcc-ar.c
 ===
 --- gcc/gcc-ar.c(revision 192099)
 +++ gcc/gcc-ar.c(working copy)
 @@ -21,21 +21,110 @@
  #include config.h
  #include system.h
  #include libiberty.h
 +#include file-find.h
  
  #ifndef PERSONALITY
  #error Please set personality
  #endif
  
 +/* The exec prefix as derived at compile-time from --prefix.  */
 +
 +static const char standard_exec_prefix[] = STANDARD_EXEC_PREFIX;
 +
 +/* The libexec prefix as derived at compile-time from --prefix.  */
 +
  static const char standard_libexec_prefix[] = STANDARD_LIBEXEC_PREFIX;
 +
 +/* The bindir prefix as derived at compile-time from --prefix.  */
 +
  static const char standard_bin_prefix[] = STANDARD_BINDIR_PREFIX;
 -static const char *const target_machine = TARGET_MACHINE;
  
 +/* A relative path to be used in finding the location of tools
 +   relative to this program.  */
 +
 +static const char *const tooldir_base_prefix = TOOLDIR_BASE_PREFIX;
 +
 +/* The exec prefix as relocated from the location of this program.  */
 +
 +static const char *self_exec_prefix;
 +
 +/* The libexec prefix as relocated from the location of this program.  */
 +
 +static const char *self_libexec_prefix;
 +
 +/* The tools prefix as relocated from the location of this program.  */
 +
 +static const char *self_tooldir_prefix;
 +
 +/* The name of the machine that is being targeted.  */
 +
 +static const char *const target_machine = DEFAULT_TARGET_MACHINE;
 +
 +/* The target version.  */
 +
 +static const char *const target_version = DEFAULT_TARGET_VERSION;
 +
 +/* The collection of target specific path prefixes.  */
 +
 +static struct path_prefix target_path;
 +
 +/* The collection path prefixes.  */
 +
 +static struct path_prefix path;
 +
 +/* The directory separator.  */
 +
  static const char dir_separator[] = { DIR_SEPARATOR, 0 };
  
 +static void
 +setup_prefixes (const char *exec_path)
 +{
 +  const char *self;
 +
 +  self = getenv (GCC_EXEC_PREFIX);
 +  if (!self)
 +self = exec_path;
 +  else
 +self = concat (self, gcc- PERSONALITY, NULL);
 +
 +  /* Relocate the exec prefix.  */
 +  self_exec_prefix = make_relative_prefix (self,
 +  standard_bin_prefix,
 +  standard_exec_prefix);
 +  if (self_exec_prefix == NULL)
 +self_exec_prefix = standard_exec_prefix;
 +
 +  /* Relocate libexec prefix.  */
 +  self_libexec_prefix = make_relative_prefix (self,
 + standard_bin_prefix,
 + standard_libexec_prefix);
 +  if (self_libexec_prefix == NULL)
 +self_libexec_prefix = standard_libexec_prefix;
 +
 +
 +  /* Build the relative path to the target-specific tool directory.  */
 +  self_tooldir_prefix = concat (tooldir_base_prefix, 

Re: [PATCH] gcc-{ar,nm,ranlib}: Find binutils binaries relative to self

2012-10-18 Thread Meador Inge
Ping ^ 2.

On 10/09/2012 09:44 PM, Meador Inge wrote:
 Ping.
 
 On 10/04/2012 03:45 PM, Meador Inge wrote:
 Hi All,

 Currently the gcc-{ar,nm,ranlib} utilities assume that binutils is in
 path when invoking the wrapped binutils program.  This goes against the
 accepted practice in GCC to find sub-programs relative to where the
 GCC binaries are stored and to not make assumptions about the PATH.

 This patch changes the gcc-{ar,nm,ranlib} utilities to do the same
 by factoring out some utility code for finding files from collect2.c.
 These functions are then leveraged to find the binutils programs.
 Note that similar code exist in gcc.c.  Perhaps one day everything
 can be merged to the file-find files.

 Tested for Windows and GNU/Linux hosts and i686-pc-linux-gnu and
 arm-none-eabi targets.  OK?

 P.S. I am not quite sure what is best for the copyrights and contributed
 by comments in the file-find* files I added since that code was just moved.
 This patch drops the contributed by and keeps all the copyright dates from
 collect2.c.

 2012-10-04  Meador Inge  mead...@codesourcery.com

  * collect2.c (main): Call find_file_set_debug.
  (find_a_find, add_prefix, prefix_from_env, prefix_from_string):
  Factor out into ...
  * file-find.c (New file): ... here and ...
  * file-find.h (New file): ... here.
  * gcc-ar.c (standard_exec_prefix): New variable.
  (standard_libexec_prefix): Ditto.
  (tooldir_base_prefix) Ditto.
  (self_exec_prefix): Ditto.
  (self_libexec_prefix): Ditto.
  (self_tooldir_prefix): Ditto.
  (target_version): Ditto.
  (path): Ditto.
  (target_path): Ditto.
  (setup_prefixes): New function.
  (main): Rework how wrapped programs are found.
  * Makefile.in (OBJS-libcommon-target): Add file-find.o.
  (AR_OBJS): New variable.
  (gcc-ar$(exeext)): Add dependency on $(AR_OBJS).
  (gcc-nm$(exeext)): Ditto.
  (gcc-ranlib(exeext)): Ditto.
  (COLLECT2_OBJS): Add file-find.o.
  (collect2.o): Add file-find.h prerequisite.
  (file-find.o): New rule.

 Index: gcc/gcc-ar.c
 ===
 --- gcc/gcc-ar.c (revision 192099)
 +++ gcc/gcc-ar.c (working copy)
 @@ -21,21 +21,110 @@
  #include config.h
  #include system.h
  #include libiberty.h
 +#include file-find.h
  
  #ifndef PERSONALITY
  #error Please set personality
  #endif
  
 +/* The exec prefix as derived at compile-time from --prefix.  */
 +
 +static const char standard_exec_prefix[] = STANDARD_EXEC_PREFIX;
 +
 +/* The libexec prefix as derived at compile-time from --prefix.  */
 +
  static const char standard_libexec_prefix[] = STANDARD_LIBEXEC_PREFIX;
 +
 +/* The bindir prefix as derived at compile-time from --prefix.  */
 +
  static const char standard_bin_prefix[] = STANDARD_BINDIR_PREFIX;
 -static const char *const target_machine = TARGET_MACHINE;
  
 +/* A relative path to be used in finding the location of tools
 +   relative to this program.  */
 +
 +static const char *const tooldir_base_prefix = TOOLDIR_BASE_PREFIX;
 +
 +/* The exec prefix as relocated from the location of this program.  */
 +
 +static const char *self_exec_prefix;
 +
 +/* The libexec prefix as relocated from the location of this program.  */
 +
 +static const char *self_libexec_prefix;
 +
 +/* The tools prefix as relocated from the location of this program.  */
 +
 +static const char *self_tooldir_prefix;
 +
 +/* The name of the machine that is being targeted.  */
 +
 +static const char *const target_machine = DEFAULT_TARGET_MACHINE;
 +
 +/* The target version.  */
 +
 +static const char *const target_version = DEFAULT_TARGET_VERSION;
 +
 +/* The collection of target specific path prefixes.  */
 +
 +static struct path_prefix target_path;
 +
 +/* The collection path prefixes.  */
 +
 +static struct path_prefix path;
 +
 +/* The directory separator.  */
 +
  static const char dir_separator[] = { DIR_SEPARATOR, 0 };
  
 +static void
 +setup_prefixes (const char *exec_path)
 +{
 +  const char *self;
 +
 +  self = getenv (GCC_EXEC_PREFIX);
 +  if (!self)
 +self = exec_path;
 +  else
 +self = concat (self, gcc- PERSONALITY, NULL);
 +
 +  /* Relocate the exec prefix.  */
 +  self_exec_prefix = make_relative_prefix (self,
 +   standard_bin_prefix,
 +   standard_exec_prefix);
 +  if (self_exec_prefix == NULL)
 +self_exec_prefix = standard_exec_prefix;
 +
 +  /* Relocate libexec prefix.  */
 +  self_libexec_prefix = make_relative_prefix (self,
 +  standard_bin_prefix,
 +  standard_libexec_prefix);
 +  if (self_libexec_prefix == NULL)
 +self_libexec_prefix = standard_libexec_prefix;
 +
 +
 +  /* Build the relative path to the target-specific tool directory.  */
 +  self_tooldir_prefix = concat (tooldir_base_prefix, target_machine,
 +

Re: [PATCH] gcc-{ar,nm,ranlib}: Find binutils binaries relative to self

2012-10-18 Thread Bernhard Reutner-Fischer

On 18 October 2012 17:30:20 Meador Inge mead...@codesourcery.com wrote:

Ping ^ 2


Been a while but wasn't --with-build-sysroot for exactly this?


On 10/09/2012 09:44 PM, Meador Inge wrote:
 Ping.

 On 102012 03:45 PM, Meador Inge wrote:
 Hi All,

 Currently the gcc-{ar,nm,ranlib} utilities assume that binutils is in
 path when invoking the wrapped binutils program.  This goes against the
 accepted practice in GCC to find sub-programs relative to where the
 GCC binaries are stored and to not make assumptions about the PATH.

 This patch changes the gcc-{ar,nm,ranlib} utilities to do the same
 by factoring out some utility code for finding files from collect2.c.
 These functions are then leveraged to find the binutils programs.
 Note that similar code exist in gcc.c.  Perhaps one day everything
 can be merged to the file-find files.

 Tested for Windows and GNU/Linux hosts and i686-pc-linux-gnu and
 arm-none-eabi targets.



Sent with AquaMail for Android
http://www.aqua-mail.com




Re: [PATCH] gcc-{ar,nm,ranlib}: Find binutils binaries relative to self

2012-10-09 Thread Meador Inge
Ping.

On 10/04/2012 03:45 PM, Meador Inge wrote:
 Hi All,
 
 Currently the gcc-{ar,nm,ranlib} utilities assume that binutils is in
 path when invoking the wrapped binutils program.  This goes against the
 accepted practice in GCC to find sub-programs relative to where the
 GCC binaries are stored and to not make assumptions about the PATH.
 
 This patch changes the gcc-{ar,nm,ranlib} utilities to do the same
 by factoring out some utility code for finding files from collect2.c.
 These functions are then leveraged to find the binutils programs.
 Note that similar code exist in gcc.c.  Perhaps one day everything
 can be merged to the file-find files.
 
 Tested for Windows and GNU/Linux hosts and i686-pc-linux-gnu and
 arm-none-eabi targets.  OK?
 
 P.S. I am not quite sure what is best for the copyrights and contributed
 by comments in the file-find* files I added since that code was just moved.
 This patch drops the contributed by and keeps all the copyright dates from
 collect2.c.
 
 2012-10-04  Meador Inge  mead...@codesourcery.com
 
   * collect2.c (main): Call find_file_set_debug.
   (find_a_find, add_prefix, prefix_from_env, prefix_from_string):
   Factor out into ...
   * file-find.c (New file): ... here and ...
   * file-find.h (New file): ... here.
   * gcc-ar.c (standard_exec_prefix): New variable.
   (standard_libexec_prefix): Ditto.
   (tooldir_base_prefix) Ditto.
   (self_exec_prefix): Ditto.
   (self_libexec_prefix): Ditto.
   (self_tooldir_prefix): Ditto.
   (target_version): Ditto.
   (path): Ditto.
   (target_path): Ditto.
   (setup_prefixes): New function.
   (main): Rework how wrapped programs are found.
   * Makefile.in (OBJS-libcommon-target): Add file-find.o.
   (AR_OBJS): New variable.
   (gcc-ar$(exeext)): Add dependency on $(AR_OBJS).
   (gcc-nm$(exeext)): Ditto.
   (gcc-ranlib(exeext)): Ditto.
   (COLLECT2_OBJS): Add file-find.o.
   (collect2.o): Add file-find.h prerequisite.
   (file-find.o): New rule.
 
 Index: gcc/gcc-ar.c
 ===
 --- gcc/gcc-ar.c  (revision 192099)
 +++ gcc/gcc-ar.c  (working copy)
 @@ -21,21 +21,110 @@
  #include config.h
  #include system.h
  #include libiberty.h
 +#include file-find.h
  
  #ifndef PERSONALITY
  #error Please set personality
  #endif
  
 +/* The exec prefix as derived at compile-time from --prefix.  */
 +
 +static const char standard_exec_prefix[] = STANDARD_EXEC_PREFIX;
 +
 +/* The libexec prefix as derived at compile-time from --prefix.  */
 +
  static const char standard_libexec_prefix[] = STANDARD_LIBEXEC_PREFIX;
 +
 +/* The bindir prefix as derived at compile-time from --prefix.  */
 +
  static const char standard_bin_prefix[] = STANDARD_BINDIR_PREFIX;
 -static const char *const target_machine = TARGET_MACHINE;
  
 +/* A relative path to be used in finding the location of tools
 +   relative to this program.  */
 +
 +static const char *const tooldir_base_prefix = TOOLDIR_BASE_PREFIX;
 +
 +/* The exec prefix as relocated from the location of this program.  */
 +
 +static const char *self_exec_prefix;
 +
 +/* The libexec prefix as relocated from the location of this program.  */
 +
 +static const char *self_libexec_prefix;
 +
 +/* The tools prefix as relocated from the location of this program.  */
 +
 +static const char *self_tooldir_prefix;
 +
 +/* The name of the machine that is being targeted.  */
 +
 +static const char *const target_machine = DEFAULT_TARGET_MACHINE;
 +
 +/* The target version.  */
 +
 +static const char *const target_version = DEFAULT_TARGET_VERSION;
 +
 +/* The collection of target specific path prefixes.  */
 +
 +static struct path_prefix target_path;
 +
 +/* The collection path prefixes.  */
 +
 +static struct path_prefix path;
 +
 +/* The directory separator.  */
 +
  static const char dir_separator[] = { DIR_SEPARATOR, 0 };
  
 +static void
 +setup_prefixes (const char *exec_path)
 +{
 +  const char *self;
 +
 +  self = getenv (GCC_EXEC_PREFIX);
 +  if (!self)
 +self = exec_path;
 +  else
 +self = concat (self, gcc- PERSONALITY, NULL);
 +
 +  /* Relocate the exec prefix.  */
 +  self_exec_prefix = make_relative_prefix (self,
 +standard_bin_prefix,
 +standard_exec_prefix);
 +  if (self_exec_prefix == NULL)
 +self_exec_prefix = standard_exec_prefix;
 +
 +  /* Relocate libexec prefix.  */
 +  self_libexec_prefix = make_relative_prefix (self,
 +   standard_bin_prefix,
 +   standard_libexec_prefix);
 +  if (self_libexec_prefix == NULL)
 +self_libexec_prefix = standard_libexec_prefix;
 +
 +
 +  /* Build the relative path to the target-specific tool directory.  */
 +  self_tooldir_prefix = concat (tooldir_base_prefix, target_machine,
 + dir_separator, 

[PATCH] gcc-{ar,nm,ranlib}: Find binutils binaries relative to self

2012-10-04 Thread Meador Inge
Hi All,

Currently the gcc-{ar,nm,ranlib} utilities assume that binutils is in
path when invoking the wrapped binutils program.  This goes against the
accepted practice in GCC to find sub-programs relative to where the
GCC binaries are stored and to not make assumptions about the PATH.

This patch changes the gcc-{ar,nm,ranlib} utilities to do the same
by factoring out some utility code for finding files from collect2.c.
These functions are then leveraged to find the binutils programs.
Note that similar code exist in gcc.c.  Perhaps one day everything
can be merged to the file-find files.

Tested for Windows and GNU/Linux hosts and i686-pc-linux-gnu and
arm-none-eabi targets.  OK?

P.S. I am not quite sure what is best for the copyrights and contributed
by comments in the file-find* files I added since that code was just moved.
This patch drops the contributed by and keeps all the copyright dates from
collect2.c.

2012-10-04  Meador Inge  mead...@codesourcery.com

* collect2.c (main): Call find_file_set_debug.
(find_a_find, add_prefix, prefix_from_env, prefix_from_string):
Factor out into ...
* file-find.c (New file): ... here and ...
* file-find.h (New file): ... here.
* gcc-ar.c (standard_exec_prefix): New variable.
(standard_libexec_prefix): Ditto.
(tooldir_base_prefix) Ditto.
(self_exec_prefix): Ditto.
(self_libexec_prefix): Ditto.
(self_tooldir_prefix): Ditto.
(target_version): Ditto.
(path): Ditto.
(target_path): Ditto.
(setup_prefixes): New function.
(main): Rework how wrapped programs are found.
* Makefile.in (OBJS-libcommon-target): Add file-find.o.
(AR_OBJS): New variable.
(gcc-ar$(exeext)): Add dependency on $(AR_OBJS).
(gcc-nm$(exeext)): Ditto.
(gcc-ranlib(exeext)): Ditto.
(COLLECT2_OBJS): Add file-find.o.
(collect2.o): Add file-find.h prerequisite.
(file-find.o): New rule.

Index: gcc/gcc-ar.c
===
--- gcc/gcc-ar.c(revision 192099)
+++ gcc/gcc-ar.c(working copy)
@@ -21,21 +21,110 @@
 #include config.h
 #include system.h
 #include libiberty.h
+#include file-find.h
 
 #ifndef PERSONALITY
 #error Please set personality
 #endif
 
+/* The exec prefix as derived at compile-time from --prefix.  */
+
+static const char standard_exec_prefix[] = STANDARD_EXEC_PREFIX;
+
+/* The libexec prefix as derived at compile-time from --prefix.  */
+
 static const char standard_libexec_prefix[] = STANDARD_LIBEXEC_PREFIX;
+
+/* The bindir prefix as derived at compile-time from --prefix.  */
+
 static const char standard_bin_prefix[] = STANDARD_BINDIR_PREFIX;
-static const char *const target_machine = TARGET_MACHINE;
 
+/* A relative path to be used in finding the location of tools
+   relative to this program.  */
+
+static const char *const tooldir_base_prefix = TOOLDIR_BASE_PREFIX;
+
+/* The exec prefix as relocated from the location of this program.  */
+
+static const char *self_exec_prefix;
+
+/* The libexec prefix as relocated from the location of this program.  */
+
+static const char *self_libexec_prefix;
+
+/* The tools prefix as relocated from the location of this program.  */
+
+static const char *self_tooldir_prefix;
+
+/* The name of the machine that is being targeted.  */
+
+static const char *const target_machine = DEFAULT_TARGET_MACHINE;
+
+/* The target version.  */
+
+static const char *const target_version = DEFAULT_TARGET_VERSION;
+
+/* The collection of target specific path prefixes.  */
+
+static struct path_prefix target_path;
+
+/* The collection path prefixes.  */
+
+static struct path_prefix path;
+
+/* The directory separator.  */
+
 static const char dir_separator[] = { DIR_SEPARATOR, 0 };
 
+static void
+setup_prefixes (const char *exec_path)
+{
+  const char *self;
+
+  self = getenv (GCC_EXEC_PREFIX);
+  if (!self)
+self = exec_path;
+  else
+self = concat (self, gcc- PERSONALITY, NULL);
+
+  /* Relocate the exec prefix.  */
+  self_exec_prefix = make_relative_prefix (self,
+  standard_bin_prefix,
+  standard_exec_prefix);
+  if (self_exec_prefix == NULL)
+self_exec_prefix = standard_exec_prefix;
+
+  /* Relocate libexec prefix.  */
+  self_libexec_prefix = make_relative_prefix (self,
+ standard_bin_prefix,
+ standard_libexec_prefix);
+  if (self_libexec_prefix == NULL)
+self_libexec_prefix = standard_libexec_prefix;
+
+
+  /* Build the relative path to the target-specific tool directory.  */
+  self_tooldir_prefix = concat (tooldir_base_prefix, target_machine,
+   dir_separator, NULL);
+  self_tooldir_prefix = concat (self_exec_prefix, target_machine, 
+   dir_separator,