source: patches/gcc-4.1.1-PR20425-1.patch @ f71c005

clfs-1.2clfs-2.1clfs-3.0.0-systemdclfs-3.0.0-sysvinitsystemdsysvinit
Last change on this file since f71c005 was 89d1048, checked in by Jim Gifford <clfs@…>, 17 years ago

Updated to GCC 4.1.1 patches

  • Property mode set to 100644
File size: 34.9 KB
RevLine 
[4fc5a87]1Submitted By: Ryan Oliver <ryan at pha dot com dot au>
2Date: 2006-03-10
3Initial Package Version: 4.1.0
4Origin: GCC SVN Revision 108635 (diffed against 4.1.0 release)
5Upstream Status: In GCC trunk
6Description: Fix for PR20425
7
[89d1048]8Modified by Jim Gifford for 4.1.1
9
[4fc5a87]10From http://gcc.gnu.org/ml/gcc-patches/2005-12/msg00818.html
11---------------------------------8<------------------------------------
12This gives the gcc driver a new path iteration function, for_each_path,
13and uses it everywhere, making path iteration a little more consistent.
14for_each_path uses the same path ordering as the existing find_file
15function.  I've also tweaked some of the existing find_a_file calls for
16consistency, and uncovered and fixed some other bugs..
17
18Functional changes are:
19
20o  %D library paths are printed in the same order as gcc uses elsewhere
21   when searching library directories, ie. all multilib paths are first.
22   http://gcc.gnu.org/ml/gcc-patches/2005-03/msg02044.html effectively
23   reverted by the rewrite because I believe the same speedup is gained
24   by searching the right dirs first.
25
26o  gcc -print-search-dirs prints library multilib paths followed by
27   non-multilib paths where before we just printed non-multilib paths.
28
29o  LIBRARY_PATH_ENV similarly includes multilib directories.
30
31o  All searches of startfile_prefixes now look in multilib dirs first
32   followed by non-multilib dirs.  This changes the dirs we search for
33   spec files, and %include and %include_noerr in specs.  Previously
34   we only searched the non-multilib dirs for specs files.  I think this
35   change is worthwhile just for consistency, and the extension is
36   reasonable.  For instance, it would allow different spec files to be
37   used for gcc -m64 vs. gcc -m32.  However, if others think this wrong,
38   I won't argue.  Consistency isn't everything.
39
40o  Some attempt made to prevent searching of duplicate paths.  The old
41   find_file would search some paths twice (when multilib_dir was NULL
42   but multilib_os_dir non-NULL).  We still search twice in some cases,
43   eg. /usr/lib/../lib and /usr/lib are considered different paths.
44
45o  find_a_file with last param (do_multi) true now searches both
46   multilib and non-multilib paths.  Before, do_multi (well, the old
47   param name was multilib) meant just search multilib paths.  This
48   isn't a user-visible change as the only place where find_a_file was
49   invoked with the last param true was from find_file, where we
50   immediately followed with a non-multilib find_a_file.
51
52o  Memory leaks fixed in is_directory.
53
54o  LIBRARY_PATH_ENV and COMPILER_PATH now only have existing
55   directories, making LIBRARY_PATH_ENV closer to %D paths.  The
56   following lines (which I remove) in is_directory meant that
57   is_directory didn't do much for LIBRARY_PATH_ENV, except on
58   SMALL_ARG_MAX machines.
59
60  4278        ian #ifndef SMALL_ARG_MAX
61  4278        ian   if (! linker)
62  4278        ian     return 1;
63  4278        ian #endif
64
65   I'll also remove mention of SMALL_ARG_MAX in config and doc files
66   when I commit this change as this is the only place it is used.
67
68o  gcc -Bnon-dir-prefix- now works properly.  The previously mentioned
69   is_directory peculiarity affected the following code.
70
71 43664      nickc /* Catch the case where the user has forgotten to append a
72 46063      jsm28    directory separator to the path.  Note, they may be using
73 43664      nickc    -B to add an executable name prefix, eg "i386-elf-", in
74 43664      nickc    order to distinguish between multiple installations of
75 43664      nickc    GCC in the same directory.  Hence we must check to see
76 43664      nickc    if appending a directory separator actually makes a
77 43664      nickc    valid directory name.  */
78 43664      nickc if (! IS_DIR_SEPARATOR (value [len - 1])
79 43664      nickc     && is_directory (value, "", 0))
80 43664      nickc   {
81 43767      ghazi     char *tmp = xmalloc (len + 2);
82 43767      ghazi     strcpy (tmp, value);
83 43767      ghazi     tmp[len] = DIR_SEPARATOR;
84 43767      ghazi     tmp[++ len] = 0;
85 43767      ghazi     value = tmp;
86 43664      nickc   }
87
88Bootstrapped and regression tested powerpc64-linux and powerpc-linux on
89a previous iteration of this patch missing is_directory fixes.
90Currently running tests on this patch.
91---------------------------------8<------------------------------------
92
93diff -uNr gcc-4.1.0/gcc/config.build gcc-4.1.0-PR20425/gcc/config.build
94--- gcc-4.1.0/gcc/config.build  2005-06-25 12:02:01.000000000 +1000
95+++ gcc-4.1.0-PR20425/gcc/config.build  2006-03-10 23:47:02.000000000 +1100
96@@ -90,15 +90,10 @@
97     build_install_headers_dir=install-headers-cpio
98     ;;
99   i[34567]86-sequent-ptx4* | i[34567]86-sequent-sysv4* )
100-    build_xm_defines="SMALL_ARG_MAX"
101     build_install_headers_dir=install-headers-cpio
102     ;;
103-  i[34567]86-*-solaris2*)
104-    build_xm_defines="SMALL_ARG_MAX"
105-    ;;
106   i[34567]86-*-sysv4*)
107     # Intel x86 running system V r4
108-    build_xm_defines="SMALL_ARG_MAX"
109     build_install_headers_dir=install-headers-cpio
110     ;;
111   i[34567]86-*-udk*)
112diff -uNr gcc-4.1.0/gcc/config.gcc gcc-4.1.0-PR20425/gcc/config.gcc
113--- gcc-4.1.0/gcc/config.gcc    2006-02-07 03:07:46.000000000 +1100
114+++ gcc-4.1.0-PR20425/gcc/config.gcc    2006-03-10 23:47:20.000000000 +1100
115@@ -994,7 +994,6 @@
116        then
117                tm_file="${tm_file} usegas.h"
118        fi
119-       xm_defines="SMALL_ARG_MAX"
120        tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h ptx4.h i386/ptx4-i.h"
121        tmake_file=t-svr4
122        extra_parts="crtbegin.o crtend.o"
123@@ -1125,7 +1124,6 @@
124        use_fixproto=yes
125        ;;
126 i[34567]86-*-solaris2*)
127-       xm_defines="SMALL_ARG_MAX"
128        tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h svr4.h i386/sysv4.h sol2.h"
129        case ${target} in
130        *-*-solaris2.[0-6] | *-*-solaris2.[0-6].*)
131@@ -1192,7 +1190,6 @@
132        use_fixproto=yes
133        ;;
134 i[34567]86-*-sysv4*)           # Intel 80386's running system V.4
135-       xm_defines="SMALL_ARG_MAX"
136        tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h svr4.h i386/sysv4.h i386/sysv4-cpp.h"
137        if test x$stabs = xyes
138        then
139diff -uNr gcc-4.1.0/gcc/config.host gcc-4.1.0-PR20425/gcc/config.host
140--- gcc-4.1.0/gcc/config.host   2006-02-06 03:18:20.000000000 +1100
141+++ gcc-4.1.0-PR20425/gcc/config.host   2006-03-10 23:47:52.000000000 +1100
142@@ -135,17 +135,10 @@
143   i370-*-opened* | i370-*-mvs* ) # IBM 360/370/390 Architecture
144     host_xm_defines='FATAL_EXIT_CODE=12'
145     ;;
146-  i[34567]86-sequent-ptx4*)
147-    host_xm_defines="SMALL_ARG_MAX"
148-    ;;
149   i[34567]86-*-solaris2*)
150-    host_xm_defines="SMALL_ARG_MAX"
151     out_host_hook_obj=host-solaris.o
152     host_xmake_file=x-solaris
153     ;;
154-  i[34567]86-*-sysv4*) # Intel 80386's running System V Release 4
155-    host_xm_defines="SMALL_ARG_MAX"
156-    ;;
157   i[34567]86-pc-msdosdjgpp*)
158     host_xm_file=i386/xm-djgpp.h
159     host_exeext=.exe
160diff -uNr gcc-4.1.0/gcc/doc/hostconfig.texi gcc-4.1.0-PR20425/gcc/doc/hostconfig.texi
161--- gcc-4.1.0/gcc/doc/hostconfig.texi   2004-11-24 15:31:58.000000000 +1100
162+++ gcc-4.1.0-PR20425/gcc/doc/hostconfig.texi   2006-03-10 23:48:20.000000000 +1100
163@@ -208,11 +208,6 @@
164 If defined, a C statement (sans semicolon) that performs host-dependent
165 initialization when a compilation driver is being initialized.
166 
167-@item SMALL_ARG_MAX
168-Define this macro if the host system has a small limit on the total
169-size of an argument vector.  This causes the driver to take more care
170-not to pass unnecessary arguments to subprocesses.
171-
172 @item HOST_LONG_LONG_FORMAT
173 If defined, the string used to indicate an argument of type @code{long
174 long} to functions like @code{printf}.  The default value is
175diff -uNr gcc-4.1.0/gcc/gcc.c gcc-4.1.0-PR20425/gcc/gcc.c
176--- gcc-4.1.0/gcc/gcc.c 2006-01-22 05:29:08.000000000 +1100
177+++ gcc-4.1.0-PR20425/gcc/gcc.c 2006-03-10 22:14:35.000000000 +1100
178@@ -287,10 +287,12 @@
179 static void read_specs (const char *, int);
180 static void set_spec (const char *, const char *);
181 static struct compiler *lookup_compiler (const char *, size_t, const char *);
182-static char *build_search_list (struct path_prefix *, const char *, int);
183-static void putenv_from_prefixes (struct path_prefix *, const char *);
184+static char *build_search_list (const struct path_prefix *, const char *,
185+                               bool, bool);
186+static void putenv_from_prefixes (const struct path_prefix *, const char *,
187+                                 bool);
188 static int access_check (const char *, int);
189-static char *find_a_file (struct path_prefix *, const char *, int, int);
190+static char *find_a_file (const struct path_prefix *, const char *, int, bool);
191 static void add_prefix (struct path_prefix *, const char *, const char *,
192                        int, int, int);
193 static void add_sysrooted_prefix (struct path_prefix *, const char *,
194@@ -313,13 +315,12 @@
195 static const char *handle_spec_function (const char *);
196 static char *save_string (const char *, int);
197 static void set_collect_gcc_options (void);
198-static void do_spec_path (struct prefix_list *, const char *, int, int, int, const char *, const char *);
199 static int do_spec_1 (const char *, int, const char *);
200 static int do_spec_2 (const char *);
201 static void do_option_spec (const char *, const char *);
202 static void do_self_spec (const char *);
203 static const char *find_file (const char *);
204-static int is_directory (const char *, const char *, int);
205+static int is_directory (const char *, bool);
206 static const char *validate_switches (const char *);
207 static void validate_all_switches (void);
208 static inline void validate_switches_from_spec (const char *);
209@@ -2036,7 +2037,7 @@
210                       (long) (p1 - buffer + 1));
211 
212              p[-2] = '\0';
213-             new_filename = find_a_file (&startfile_prefixes, p1, R_OK, 0);
214+             new_filename = find_a_file (&startfile_prefixes, p1, R_OK, true);
215              read_specs (new_filename ? new_filename : p1, FALSE);
216              continue;
217            }
218@@ -2055,7 +2056,7 @@
219                       (long) (p1 - buffer + 1));
220 
221              p[-2] = '\0';
222-             new_filename = find_a_file (&startfile_prefixes, p1, R_OK, 0);
223+             new_filename = find_a_file (&startfile_prefixes, p1, R_OK, true);
224              if (new_filename)
225                read_specs (new_filename, FALSE);
226              else if (verbose_flag)
227@@ -2352,65 +2353,214 @@
228   failure_delete_queue = 0;
229 }
230 
231-/* Build a list of search directories from PATHS.
232-   PREFIX is a string to prepend to the list.
233-   If CHECK_DIR_P is nonzero we ensure the directory exists.
234-   This is used mostly by putenv_from_prefixes so we use `collect_obstack'.
235-   It is also used by the --print-search-dirs flag.  */
236-
237-static char *
238-build_search_list (struct path_prefix *paths, const char *prefix,
239-                  int check_dir_p)
240+/* Call CALLBACK for each path in PATHS, breaking out early if CALLBACK
241+   returns non-NULL.
242+   If DO_MULTI is true iterate over the paths twice, first with multilib
243+   suffix then without, otherwise iterate over the paths once without
244+   adding a multilib suffix.  When DO_MULTI is true, some attempt is made
245+   to avoid visiting the same path twice, but we could do better.  For
246+   instance, /usr/lib/../lib is considered different from /usr/lib.
247+   At least EXTRA_SPACE chars past the end of the path passed to
248+   CALLBACK are available for use by the callback.
249+   CALLBACK_INFO allows extra parameters to be passed to CALLBACK.
250+
251+   Returns the value returned by CALLBACK.  */
252+
253+static void *
254+for_each_path (const struct path_prefix *paths,
255+              bool do_multi,
256+              size_t extra_space,
257+              void *(*callback) (char *, void *),
258+              void *callback_info)
259 {
260-  int suffix_len = (machine_suffix) ? strlen (machine_suffix) : 0;
261-  int just_suffix_len
262-    = (just_machine_suffix) ? strlen (just_machine_suffix) : 0;
263-  int first_time = TRUE;
264-  struct prefix_list *pprefix;
265-
266-  obstack_grow (&collect_obstack, prefix, strlen (prefix));
267-  obstack_1grow (&collect_obstack, '=');
268+  struct prefix_list *pl;
269+  const char *multi_dir = NULL;
270+  const char *multi_os_dir = NULL;
271+  const char *multi_suffix;
272+  const char *just_multi_suffix;
273+  char *path = NULL;
274+  void *ret = NULL;
275+  bool skip_multi_dir = false;
276+  bool skip_multi_os_dir = false;
277+
278+  multi_suffix = machine_suffix;
279+  just_multi_suffix = just_machine_suffix;
280+  if (do_multi && multilib_dir && strcmp (multilib_dir, ".") != 0)
281+    {
282+      multi_dir = concat (multilib_dir, dir_separator_str, NULL);
283+      multi_suffix = concat (multi_suffix, multi_dir, NULL);
284+      just_multi_suffix = concat (just_multi_suffix, multi_dir, NULL);
285+    }
286+  if (do_multi && multilib_os_dir && strcmp (multilib_os_dir, ".") != 0)
287+    multi_os_dir = concat (multilib_os_dir, dir_separator_str, NULL);
288 
289-  for (pprefix = paths->plist; pprefix != 0; pprefix = pprefix->next)
290+  while (1)
291     {
292-      int len = strlen (pprefix->prefix);
293+      size_t multi_dir_len = 0;
294+      size_t multi_os_dir_len = 0;
295+      size_t suffix_len;
296+      size_t just_suffix_len;
297+      size_t len;
298+
299+      if (multi_dir)
300+       multi_dir_len = strlen (multi_dir);
301+      if (multi_os_dir)
302+       multi_os_dir_len = strlen (multi_os_dir);
303+      suffix_len = strlen (multi_suffix);
304+      just_suffix_len = strlen (just_multi_suffix);
305+
306+      if (path == NULL)
307+       {
308+         len = paths->max_len + extra_space + 1;
309+         if (suffix_len > multi_os_dir_len)
310+           len += suffix_len;
311+         else
312+           len += multi_os_dir_len;
313+         path = xmalloc (len);
314+       }
315 
316-      if (machine_suffix
317-         && (! check_dir_p
318-             || is_directory (pprefix->prefix, machine_suffix, 0)))
319+      for (pl = paths->plist; pl != 0; pl = pl->next)
320        {
321-         if (!first_time)
322-           obstack_1grow (&collect_obstack, PATH_SEPARATOR);
323+         len = strlen (pl->prefix);
324+         memcpy (path, pl->prefix, len);
325 
326-         first_time = FALSE;
327-         obstack_grow (&collect_obstack, pprefix->prefix, len);
328-         obstack_grow (&collect_obstack, machine_suffix, suffix_len);
329-       }
330+         /* Look first in MACHINE/VERSION subdirectory.  */
331+         if (!skip_multi_dir)
332+           {
333+             memcpy (path + len, multi_suffix, suffix_len + 1);
334+             ret = callback (path, callback_info);
335+             if (ret)
336+               break;
337+           }
338 
339-      if (just_machine_suffix
340-         && pprefix->require_machine_suffix == 2
341-         && (! check_dir_p
342-             || is_directory (pprefix->prefix, just_machine_suffix, 0)))
343-       {
344-         if (! first_time)
345-           obstack_1grow (&collect_obstack, PATH_SEPARATOR);
346+         /* Some paths are tried with just the machine (ie. target)
347+            subdir.  This is used for finding as, ld, etc.  */
348+         if (!skip_multi_dir
349+             && pl->require_machine_suffix == 2)
350+           {
351+             memcpy (path + len, just_multi_suffix, just_suffix_len + 1);
352+             ret = callback (path, callback_info);
353+             if (ret)
354+               break;
355+           }
356+
357+         /* Now try the base path.  */
358+         if (!pl->require_machine_suffix
359+             && !(pl->os_multilib ? skip_multi_os_dir : skip_multi_dir))
360+           {
361+             const char *this_multi;
362+             size_t this_multi_len;
363+
364+             if (pl->os_multilib)
365+               {
366+                 this_multi = multi_os_dir;
367+                 this_multi_len = multi_os_dir_len;
368+               }
369+             else
370+               {
371+                 this_multi = multi_dir;
372+                 this_multi_len = multi_dir_len;
373+               }
374 
375-         first_time = FALSE;
376-         obstack_grow (&collect_obstack, pprefix->prefix, len);
377-         obstack_grow (&collect_obstack, just_machine_suffix,
378-                       just_suffix_len);
379+             if (this_multi_len)
380+               memcpy (path + len, this_multi, this_multi_len + 1);
381+             else
382+               path[len] = '\0';
383+
384+             ret = callback (path, callback_info);
385+             if (ret)
386+               break;
387+           }
388        }
389+      if (pl)
390+       break;
391 
392-      if (! pprefix->require_machine_suffix)
393-       {
394-         if (! first_time)
395-           obstack_1grow (&collect_obstack, PATH_SEPARATOR);
396+      if (multi_dir == NULL && multi_os_dir == NULL)
397+       break;
398 
399-         first_time = FALSE;
400-         obstack_grow (&collect_obstack, pprefix->prefix, len);
401+      /* Run through the paths again, this time without multilibs.
402+        Don't repeat any we have already seen.  */
403+      if (multi_dir)
404+       {
405+         free ((char *) multi_dir);
406+         multi_dir = NULL;
407+         free ((char *) multi_suffix);
408+         multi_suffix = machine_suffix;
409+         free ((char *) just_multi_suffix);
410+         just_multi_suffix = just_machine_suffix;
411+       }
412+      else
413+       skip_multi_dir = true;
414+      if (multi_os_dir)
415+       {
416+         free ((char *) multi_os_dir);
417+         multi_os_dir = NULL;
418        }
419+      else
420+       skip_multi_os_dir = true;
421     }
422 
423+  if (multi_dir)
424+    {
425+      free ((char *) multi_dir);
426+      free ((char *) multi_suffix);
427+      free ((char *) just_multi_suffix);
428+    }
429+  if (multi_os_dir)
430+    free ((char *) multi_os_dir);
431+  if (ret != path)
432+    free (path);
433+  return ret;
434+}
435+
436+/* Callback for build_search_list.  Adds path to obstack being built.  */
437+
438+struct add_to_obstack_info {
439+  struct obstack *ob;
440+  bool check_dir;
441+  bool first_time;
442+};
443+
444+static void *
445+add_to_obstack (char *path, void *data)
446+{
447+  struct add_to_obstack_info *info = data;
448+
449+  if (info->check_dir && !is_directory (path, false))
450+    return NULL;
451+
452+  if (!info->first_time)
453+    obstack_1grow (info->ob, PATH_SEPARATOR);
454+
455+  obstack_grow (info->ob, path, strlen (path));
456+
457+  info->first_time = false;
458+  return NULL;
459+}
460+
461+/* Build a list of search directories from PATHS.
462+   PREFIX is a string to prepend to the list.
463+   If CHECK_DIR_P is true we ensure the directory exists.
464+   If DO_MULTI is true, multilib paths are output first, then
465+   non-multilib paths.
466+   This is used mostly by putenv_from_prefixes so we use `collect_obstack'.
467+   It is also used by the --print-search-dirs flag.  */
468+
469+static char *
470+build_search_list (const struct path_prefix *paths, const char *prefix,
471+                  bool check_dir, bool do_multi)
472+{
473+  struct add_to_obstack_info info;
474+
475+  info.ob = &collect_obstack;
476+  info.check_dir = check_dir;
477+  info.first_time = true;
478+
479+  obstack_grow (&collect_obstack, prefix, strlen (prefix));
480+  obstack_1grow (&collect_obstack, '=');
481+
482+  for_each_path (paths, do_multi, 0, add_to_obstack, &info);
483+
484   obstack_1grow (&collect_obstack, '\0');
485   return XOBFINISH (&collect_obstack, char *);
486 }
487@@ -2419,9 +2569,10 @@
488    for collect.  */
489 
490 static void
491-putenv_from_prefixes (struct path_prefix *paths, const char *env_var)
492+putenv_from_prefixes (const struct path_prefix *paths, const char *env_var,
493+                     bool do_multi)
494 {
495-  putenv (build_search_list (paths, env_var, 1));
496+  putenv (build_search_list (paths, env_var, true, do_multi));
497 }
498 
499 /* Check whether NAME can be accessed in MODE.  This is like access,
500@@ -2442,20 +2593,53 @@
501   return access (name, mode);
502 }
503 
504+/* Callback for find_a_file.  Appends the file name to the directory
505+   path.  If the resulting file exists in the right mode, return the
506+   full pathname to the file.  */
507+
508+struct file_at_path_info {
509+  const char *name;
510+  const char *suffix;
511+  int name_len;
512+  int suffix_len;
513+  int mode;
514+};
515+
516+static void *
517+file_at_path (char *path, void *data)
518+{
519+  struct file_at_path_info *info = data;
520+  size_t len = strlen (path);
521+
522+  memcpy (path + len, info->name, info->name_len);
523+  len += info->name_len;
524+
525+  /* Some systems have a suffix for executable files.
526+     So try appending that first.  */
527+  if (info->suffix_len)
528+    {
529+      memcpy (path + len, info->suffix, info->suffix_len + 1);
530+      if (access_check (path, info->mode) == 0)
531+       return path;
532+    }
533+
534+  path[len] = '\0';
535+  if (access_check (path, info->mode) == 0)
536+    return path;
537+
538+  return NULL;
539+}
540+
541 /* Search for NAME using the prefix list PREFIXES.  MODE is passed to
542-   access to check permissions.
543+   access to check permissions.  If DO_MULTI is true, search multilib
544+   paths then non-multilib paths, otherwise do not search multilib paths.
545    Return 0 if not found, otherwise return its name, allocated with malloc.  */
546 
547 static char *
548-find_a_file (struct path_prefix *pprefix, const char *name, int mode,
549-            int multilib)
550+find_a_file (const struct path_prefix *pprefix, const char *name, int mode,
551+            bool do_multi)
552 {
553-  char *temp;
554-  const char *const file_suffix =
555-    ((mode & X_OK) != 0 ? HOST_EXECUTABLE_SUFFIX : "");
556-  struct prefix_list *pl;
557-  int len = pprefix->max_len + strlen (name) + strlen (file_suffix) + 1;
558-  const char *multilib_name, *multilib_os_name;
559+  struct file_at_path_info info;
560 
561 #ifdef DEFAULT_ASSEMBLER
562   if (! strcmp (name, "as") && access (DEFAULT_ASSEMBLER, mode) == 0)
563@@ -2467,112 +2651,24 @@
564     return xstrdup (DEFAULT_LINKER);
565 #endif
566 
567-  if (machine_suffix)
568-    len += strlen (machine_suffix);
569-
570-  multilib_name = name;
571-  multilib_os_name = name;
572-  if (multilib && multilib_os_dir)
573-    {
574-      int len1 = multilib_dir ? strlen (multilib_dir) + 1 : 0;
575-      int len2 = strlen (multilib_os_dir) + 1;
576-
577-      len += len1 > len2 ? len1 : len2;
578-      if (multilib_dir)
579-       multilib_name = ACONCAT ((multilib_dir, dir_separator_str, name,
580-                                 NULL));
581-      if (strcmp (multilib_os_dir, ".") != 0)
582-       multilib_os_name = ACONCAT ((multilib_os_dir, dir_separator_str, name,
583-                                   NULL));
584-    }
585-
586-  temp = xmalloc (len);
587-
588   /* Determine the filename to execute (special case for absolute paths).  */
589 
590   if (IS_ABSOLUTE_PATH (name))
591     {
592       if (access (name, mode) == 0)
593-       {
594-         strcpy (temp, name);
595-         return temp;
596-       }
597-    }
598-  else
599-    for (pl = pprefix->plist; pl; pl = pl->next)
600-      {
601-       const char *this_name
602-         = pl->os_multilib ? multilib_os_name : multilib_name;
603+       return xstrdup (name);
604 
605-       if (machine_suffix)
606-         {
607-           /* Some systems have a suffix for executable files.
608-              So try appending that first.  */
609-           if (file_suffix[0] != 0)
610-             {
611-               strcpy (temp, pl->prefix);
612-               strcat (temp, machine_suffix);
613-               strcat (temp, multilib_name);
614-               strcat (temp, file_suffix);
615-               if (access_check (temp, mode) == 0)
616-                 return temp;
617-             }
618-
619-           /* Now try just the multilib_name.  */
620-           strcpy (temp, pl->prefix);
621-           strcat (temp, machine_suffix);
622-           strcat (temp, multilib_name);
623-           if (access_check (temp, mode) == 0)
624-             return temp;
625-         }
626-
627-       /* Certain prefixes are tried with just the machine type,
628-          not the version.  This is used for finding as, ld, etc.  */
629-       if (just_machine_suffix && pl->require_machine_suffix == 2)
630-         {
631-           /* Some systems have a suffix for executable files.
632-              So try appending that first.  */
633-           if (file_suffix[0] != 0)
634-             {
635-               strcpy (temp, pl->prefix);
636-               strcat (temp, just_machine_suffix);
637-               strcat (temp, multilib_name);
638-               strcat (temp, file_suffix);
639-               if (access_check (temp, mode) == 0)
640-                 return temp;
641-             }
642-
643-           strcpy (temp, pl->prefix);
644-           strcat (temp, just_machine_suffix);
645-           strcat (temp, multilib_name);
646-           if (access_check (temp, mode) == 0)
647-             return temp;
648-         }
649-
650-       /* Certain prefixes can't be used without the machine suffix
651-          when the machine or version is explicitly specified.  */
652-       if (! pl->require_machine_suffix)
653-         {
654-           /* Some systems have a suffix for executable files.
655-              So try appending that first.  */
656-           if (file_suffix[0] != 0)
657-             {
658-               strcpy (temp, pl->prefix);
659-               strcat (temp, this_name);
660-               strcat (temp, file_suffix);
661-               if (access_check (temp, mode) == 0)
662-                 return temp;
663-             }
664+      return NULL;
665+    }
666 
667-           strcpy (temp, pl->prefix);
668-           strcat (temp, this_name);
669-           if (access_check (temp, mode) == 0)
670-             return temp;
671-         }
672-      }
673+  info.name = name;
674+  info.suffix = (mode & X_OK) != 0 ? HOST_EXECUTABLE_SUFFIX : "";
675+  info.name_len = strlen (info.name);
676+  info.suffix_len = strlen (info.suffix);
677+  info.mode = mode;
678 
679-  free (temp);
680-  return 0;
681+  return for_each_path (pprefix, do_multi, info.name_len + info.suffix_len,
682+                       file_at_path, &info);
683 }
684 
685 /* Ranking of prefixes in the sort list. -B prefixes are put before
686@@ -2691,7 +2787,7 @@
687 
688   commands[0].prog = argbuf[0]; /* first command.  */
689   commands[0].argv = &argbuf[0];
690-  string = find_a_file (&exec_prefixes, commands[0].prog, X_OK, 0);
691+  string = find_a_file (&exec_prefixes, commands[0].prog, X_OK, false);
692 
693   if (string)
694     commands[0].argv[0] = string;
695@@ -2706,7 +2802,7 @@
696        commands[n_commands].prog = argbuf[i + 1];
697        commands[n_commands].argv = &argbuf[i + 1];
698        string = find_a_file (&exec_prefixes, commands[n_commands].prog,
699-                             X_OK, 0);
700+                             X_OK, false);
701        if (string)
702          commands[n_commands].argv[0] = string;
703        n_commands++;
704@@ -3643,7 +3739,7 @@
705                   if appending a directory separator actually makes a
706                   valid directory name.  */
707                if (! IS_DIR_SEPARATOR (value [len - 1])
708-                   && is_directory (value, "", 0))
709+                   && is_directory (value, false))
710                  {
711                    char *tmp = xmalloc (len + 2);
712                    strcpy (tmp, value);
713@@ -4391,108 +4487,55 @@
714     }
715 }
716 
717-void
718-do_spec_path (struct prefix_list *pl, const char *option,
719-             int omit_if_relative, int separate_options,
720-             int only_subdir,
721-             const char *dir_for_machine_suffix,
722-             const char *dir_for_no_suffix)
723-{
724-  static size_t bufsize = 0;
725-  static char *buffer;
726-  int idx;
727-  bool multilib_p = false;
728-
729-  /* Used on systems which record the specified -L dirs
730-     and use them to search for dynamic linking.  */
731-  /* Relative directories always come from -B,
732-     and it is better not to use them for searching
733-     at run time.  In particular, stage1 loses.  */
734-  if (omit_if_relative
735-      && !IS_ABSOLUTE_PATH (pl->prefix))
736-    return;
737+/* Callback for processing %D and %I specs.  */
738 
739-  /* Try subdirectory if there is one.  */
740-  if (machine_suffix && dir_for_machine_suffix)
741-    {
742-      if (strlen (pl->prefix) + strlen (machine_suffix)
743-         >= bufsize)
744-       bufsize = (strlen (pl->prefix)
745-                 + strlen (machine_suffix)) * 2 + 1;
746-      buffer = xrealloc (buffer, bufsize);
747-      strcpy (buffer, pl->prefix);
748-      strcat (buffer, machine_suffix);
749-      if (is_directory (buffer, dir_for_machine_suffix, 1))
750-       {
751-         multilib_p = true;
752-         do_spec_1 (option, separate_options, NULL);
753-         if (separate_options)
754-           do_spec_1 (" ", 0, NULL);
755-         do_spec_1 (buffer, 1, NULL);
756-         do_spec_1 (dir_for_machine_suffix, 1, NULL);
757-         /* Make this a separate argument.  */
758-         do_spec_1 (" ", 0, NULL);
759-       }
760-    }
761-  if (!pl->require_machine_suffix && dir_for_no_suffix)
762+struct spec_path_info {
763+  const char *option;
764+  const char *append;
765+  size_t append_len;
766+  bool omit_relative;
767+  bool separate_options;
768+};
769+
770+static void *
771+spec_path (char *path, void *data)
772+{
773+  struct spec_path_info *info = data;
774+  size_t len = 0;
775+  char save = 0;
776+
777+  if (info->omit_relative && !IS_ABSOLUTE_PATH (path))
778+    return NULL;
779+
780+  if (info->append_len != 0)
781     {
782-      if (is_directory (pl->prefix, dir_for_no_suffix, 1))
783-       {
784-         multilib_p = true;
785-         do_spec_1 (option, separate_options, NULL);
786-         if (separate_options)
787-           do_spec_1 (" ", 0, NULL);
788-         do_spec_1 (pl->prefix, 1, NULL);
789-         do_spec_1 (dir_for_no_suffix, 1, NULL);
790-         /* Make this a separate argument.  */
791-         do_spec_1 (" ", 0, NULL);
792-       }
793+      len = strlen (path);
794+      memcpy (path + len, info->append, info->append_len + 1);
795     }
796 
797-  if (only_subdir || multilib_p)
798-    return;
799+  if (!is_directory (path, true))
800+    return NULL;
801+
802+  do_spec_1 (info->option, 1, NULL);
803+  if (info->separate_options)
804+    do_spec_1 (" ", 0, NULL);
805 
806-  if (machine_suffix)
807+  if (info->append_len == 0)
808     {
809-      if (is_directory (pl->prefix, machine_suffix, 1))
810-       {
811-         do_spec_1 (option, separate_options, NULL);
812-         if (separate_options)
813-           do_spec_1 (" ", 0, NULL);
814-         do_spec_1 (pl->prefix, 1, NULL);
815-         /* Remove slash from machine_suffix.  */
816-         if (strlen (machine_suffix) >= bufsize)
817-           bufsize = strlen (machine_suffix) * 2 + 1;
818-         buffer = xrealloc (buffer, bufsize);
819-         strcpy (buffer, machine_suffix);
820-         idx = strlen (buffer);
821-         if (IS_DIR_SEPARATOR (buffer[idx - 1]))
822-           buffer[idx - 1] = 0;
823-         do_spec_1 (buffer, 1, NULL);
824-         /* Make this a separate argument.  */
825-         do_spec_1 (" ", 0, NULL);
826-       }
827-    }
828-  if (!pl->require_machine_suffix)
829-    {
830-      if (is_directory (pl->prefix, "", 1))
831-       {
832-         do_spec_1 (option, separate_options, NULL);
833-         if (separate_options)
834-           do_spec_1 (" ", 0, NULL);
835-         /* Remove slash from pl->prefix.  */
836-         if (strlen (pl->prefix) >= bufsize)
837-           bufsize = strlen (pl->prefix) * 2 + 1;
838-         buffer = xrealloc (buffer, bufsize);
839-         strcpy (buffer, pl->prefix);
840-         idx = strlen (buffer);
841-         if (IS_DIR_SEPARATOR (buffer[idx - 1]))
842-           buffer[idx - 1] = 0;
843-         do_spec_1 (buffer, 1, NULL);
844-         /* Make this a separate argument.  */
845-         do_spec_1 (" ", 0, NULL);
846-       }
847+      len = strlen (path);
848+      save = path[len - 1];
849+      if (IS_DIR_SEPARATOR (path[len - 1]))
850+       path[len - 1] = '\0';
851     }
852+
853+  do_spec_1 (path, 1, NULL);
854+  do_spec_1 (" ", 0, NULL);
855+
856+  /* Must not damage the original path.  */
857+  if (info->append_len == 0)
858+    path[len - 1] = save;
859+
860+  return NULL;
861 }
862 
863 /* Process the sub-spec SPEC as a portion of a larger spec.
864@@ -4630,23 +4673,23 @@
865             that we search for startfiles.  */
866          case 'D':
867            {
868-             struct prefix_list *pl = startfile_prefixes.plist;
869-
870-             for (; pl; pl = pl->next)
871-               {
872-                 const char *no_suffix_multilib_dir;
873+             struct spec_path_info info;
874 
875-                 no_suffix_multilib_dir = pl->os_multilib ? multilib_os_dir
876-                                          : multilib_dir;
877-                 /* Do not separate options, include non-multilibbed variant.  */
878-                 do_spec_path (pl, "-L",
879+             info.option = "-L";
880+             info.append_len = 0;
881 #ifdef RELATIVE_PREFIX_NOT_LINKDIR
882-                               1,
883+             /* Used on systems which record the specified -L dirs
884+                and use them to search for dynamic linking.
885+                Relative directories always come from -B,
886+                and it is better not to use them for searching
887+                at run time.  In particular, stage1 loses.  */
888+             info.omit_relative = true;
889 #else
890-                               0,
891+             info.omit_relative = false;
892 #endif
893-                               0, 0, multilib_dir, no_suffix_multilib_dir);
894-               }
895+             info.separate_options = false;
896+
897+             for_each_path (&startfile_prefixes, true, 0, spec_path, &info);
898            }
899            break;
900 
901@@ -4883,7 +4926,7 @@
902 
903          case 'I':
904            {
905-             struct prefix_list *pl = include_prefixes.plist;
906+             struct spec_path_info info;
907 
908              if (gcc_exec_prefix)
909                {
910@@ -4906,9 +4949,14 @@
911                  do_spec_1 (" ", 0, NULL);
912                }
913 
914-             for (; pl; pl = pl->next)
915-               /* Separate options, don't include non-suffixed variant.  */
916-               do_spec_path (pl, "-isystem", 0, 1, 1, "include", "include");
917+             info.option = "-isystem";
918+             info.append = "include";
919+             info.append_len = strlen (info.append);
920+             info.omit_relative = false;
921+             info.separate_options = true;
922+
923+             for_each_path (&include_prefixes, false, info.append_len,
924+                            spec_path, &info);
925            }
926            break;
927 
928@@ -5894,48 +5942,27 @@
929 static const char *
930 find_file (const char *name)
931 {
932-  char *newname;
933-
934-  /* Try multilib_dir if it is defined.  */
935-  if (multilib_os_dir != NULL)
936-    {
937-      newname = find_a_file (&startfile_prefixes, name, R_OK, 1);
938-
939-      /* If we don't find it in the multi library dir, then fall
940-        through and look for it in the normal places.  */
941-      if (newname != NULL)
942-       return newname;
943-    }
944-
945-  newname = find_a_file (&startfile_prefixes, name, R_OK, 0);
946+  char *newname = find_a_file (&startfile_prefixes, name, R_OK, true);
947   return newname ? newname : name;
948 }
949 
950 /* Determine whether a directory exists.  If LINKER, return 0 for
951-   certain fixed names not needed by the linker.  If not LINKER, it is
952-   only important to return 0 if the host machine has a small ARG_MAX
953-   limit.  */
954+   certain fixed names not needed by the linker.  */
955 
956 static int
957-is_directory (const char *path1, const char *path2, int linker)
958+is_directory (const char *path1, bool linker)
959 {
960-  int len1 = strlen (path1);
961-  int len2 = strlen (path2);
962-  char *path = alloca (3 + len1 + len2);
963+  int len1;
964+  char *path;
965   char *cp;
966   struct stat st;
967 
968-#ifndef SMALL_ARG_MAX
969-  if (! linker)
970-    return 1;
971-#endif
972-
973-  /* Construct the path from the two parts.  Ensure the string ends with "/.".
974-     The resulting path will be a directory even if the given path is a
975-     symbolic link.  */
976+  /* Ensure the string ends with "/.".  The resulting path will be a
977+     directory even if the given path is a symbolic link.  */
978+  len1 = strlen (path1);
979+  path = alloca (3 + len1);
980   memcpy (path, path1, len1);
981-  memcpy (path + len1, path2, len2);
982-  cp = path + len1 + len2;
983+  cp = path + len1;
984   if (!IS_DIR_SEPARATOR (cp[-1]))
985     *cp++ = DIR_SEPARATOR;
986   *cp++ = '.';
987@@ -5943,13 +5970,13 @@
988 
989   /* Exclude directories that the linker is known to search.  */
990   if (linker
991+      && IS_DIR_SEPARATOR (path[0])
992       && ((cp - path == 6
993-          && strcmp (path, concat (dir_separator_str, "lib",
994-                                   dir_separator_str, ".", NULL)) == 0)
995+          && strncmp (path + 1, "lib", 3) == 0)
996          || (cp - path == 10
997-             && strcmp (path, concat (dir_separator_str, "usr",
998-                                      dir_separator_str, "lib",
999-                                      dir_separator_str, ".", NULL)) == 0)))
1000+             && strncmp (path + 1, "usr", 3) == 0
1001+             && IS_DIR_SEPARATOR (path[4])
1002+             && strncmp (path + 5, "lib", 3) == 0)))
1003     return 0;
1004 
1005   return (stat (path, &st) >= 0 && S_ISDIR (st.st_mode));
1006@@ -6139,7 +6166,7 @@
1007                           spec_version, dir_separator_str, NULL);
1008   just_machine_suffix = concat (spec_machine, dir_separator_str, NULL);
1009 
1010-  specs_file = find_a_file (&startfile_prefixes, "specs", R_OK, 0);
1011+  specs_file = find_a_file (&startfile_prefixes, "specs", R_OK, true);
1012   /* Read the specs file unless it is a default one.  */
1013   if (specs_file != 0 && strcmp (specs_file, "specs"))
1014     read_specs (specs_file, TRUE);
1015@@ -6275,7 +6302,7 @@
1016   for (uptr = user_specs_head; uptr; uptr = uptr->next)
1017     {
1018       char *filename = find_a_file (&startfile_prefixes, uptr->filename,
1019-                                   R_OK, 0);
1020+                                   R_OK, true);
1021       read_specs (filename ? filename : uptr->filename, FALSE);
1022     }
1023 
1024@@ -6304,8 +6331,10 @@
1025   if (print_search_dirs)
1026     {
1027       printf (_("install: %s%s\n"), standard_exec_prefix, machine_suffix);
1028-      printf (_("programs: %s\n"), build_search_list (&exec_prefixes, "", 0));
1029-      printf (_("libraries: %s\n"), build_search_list (&startfile_prefixes, "", 0));
1030+      printf (_("programs: %s\n"),
1031+             build_search_list (&exec_prefixes, "", false, false));
1032+      printf (_("libraries: %s\n"),
1033+             build_search_list (&startfile_prefixes, "", false, true));
1034       return (0);
1035     }
1036 
1037@@ -6622,14 +6651,14 @@
1038       /* We'll use ld if we can't find collect2.  */
1039       if (! strcmp (linker_name_spec, "collect2"))
1040        {
1041-         char *s = find_a_file (&exec_prefixes, "collect2", X_OK, 0);
1042+         char *s = find_a_file (&exec_prefixes, "collect2", X_OK, false);
1043          if (s == NULL)
1044            linker_name_spec = "ld";
1045        }
1046       /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
1047         for collect.  */
1048-      putenv_from_prefixes (&exec_prefixes, "COMPILER_PATH");
1049-      putenv_from_prefixes (&startfile_prefixes, LIBRARY_PATH_ENV);
1050+      putenv_from_prefixes (&exec_prefixes, "COMPILER_PATH", false);
1051+      putenv_from_prefixes (&startfile_prefixes, LIBRARY_PATH_ENV, true);
1052 
1053       value = do_spec (link_command_spec);
1054       if (value < 0)
1055diff -uNr gcc-4.1.0/gcc/system.h gcc-4.1.0-PR20425/gcc/system.h
1056--- gcc-4.1.0/gcc/system.h      2005-08-16 10:13:53.000000000 +1000
1057+++ gcc-4.1.0-PR20425/gcc/system.h      2006-03-10 23:51:31.000000000 +1100
1058@@ -728,7 +728,8 @@
1059         TARGET_ESC TARGET_FF TARGET_NEWLINE TARGET_TAB TARGET_VT          \
1060         LINK_LIBGCC_SPECIAL DONT_ACCESS_GBLS_AFTER_EPILOGUE               \
1061        TARGET_OPTIONS TARGET_SWITCHES EXTRA_CC_MODES FINALIZE_PIC         \
1062-       PREDICATE_CODES SPECIAL_MODE_PREDICATES HOST_PTR_PRINTF
1063+       PREDICATE_CODES SPECIAL_MODE_PREDICATES HOST_PTR_PRINTF            \
1064+       SMALL_ARG_MAX
1065 
1066 /* Hooks that are no longer used.  */
1067  #pragma GCC poison LANG_HOOKS_FUNCTION_MARK LANG_HOOKS_FUNCTION_FREE  \
Note: See TracBrowser for help on using the repository browser.