source: clfs-embedded/patches/gcc-4.1.1-PR20425-1.patch@ d88959a

Last change on this file since d88959a was e666df1, checked in by Jim Gifford <clfs@…>, 18 years ago

Updated Date
Added Busybox
Added Patches
Updated uClibc to build Busybox

  • Property mode set to 100644
File size: 34.9 KB
RevLine 
[e666df1]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
8Modified by Jim Gifford for 4.1.1
9
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
232-/* Build a list of search directories from PATHS.
233- PREFIX is a string to prepend to the list.
234- If CHECK_DIR_P is nonzero we ensure the directory exists.
235- This is used mostly by putenv_from_prefixes so we use `collect_obstack'.
236- It is also used by the --print-search-dirs flag. */
237-
238-static char *
239-build_search_list (struct path_prefix *paths, const char *prefix,
240- int check_dir_p)
241+/* Call CALLBACK for each path in PATHS, breaking out early if CALLBACK
242+ returns non-NULL.
243+ If DO_MULTI is true iterate over the paths twice, first with multilib
244+ suffix then without, otherwise iterate over the paths once without
245+ adding a multilib suffix. When DO_MULTI is true, some attempt is made
246+ to avoid visiting the same path twice, but we could do better. For
247+ instance, /usr/lib/../lib is considered different from /usr/lib.
248+ At least EXTRA_SPACE chars past the end of the path passed to
249+ CALLBACK are available for use by the callback.
250+ CALLBACK_INFO allows extra parameters to be passed to CALLBACK.
251+
252+ Returns the value returned by CALLBACK. */
253+
254+static void *
255+for_each_path (const struct path_prefix *paths,
256+ bool do_multi,
257+ size_t extra_space,
258+ void *(*callback) (char *, void *),
259+ void *callback_info)
260 {
261- int suffix_len = (machine_suffix) ? strlen (machine_suffix) : 0;
262- int just_suffix_len
263- = (just_machine_suffix) ? strlen (just_machine_suffix) : 0;
264- int first_time = TRUE;
265- struct prefix_list *pprefix;
266-
267- obstack_grow (&collect_obstack, prefix, strlen (prefix));
268- obstack_1grow (&collect_obstack, '=');
269+ struct prefix_list *pl;
270+ const char *multi_dir = NULL;
271+ const char *multi_os_dir = NULL;
272+ const char *multi_suffix;
273+ const char *just_multi_suffix;
274+ char *path = NULL;
275+ void *ret = NULL;
276+ bool skip_multi_dir = false;
277+ bool skip_multi_os_dir = false;
278+
279+ multi_suffix = machine_suffix;
280+ just_multi_suffix = just_machine_suffix;
281+ if (do_multi && multilib_dir && strcmp (multilib_dir, ".") != 0)
282+ {
283+ multi_dir = concat (multilib_dir, dir_separator_str, NULL);
284+ multi_suffix = concat (multi_suffix, multi_dir, NULL);
285+ just_multi_suffix = concat (just_multi_suffix, multi_dir, NULL);
286+ }
287+ if (do_multi && multilib_os_dir && strcmp (multilib_os_dir, ".") != 0)
288+ multi_os_dir = concat (multilib_os_dir, dir_separator_str, NULL);
289
290- for (pprefix = paths->plist; pprefix != 0; pprefix = pprefix->next)
291+ while (1)
292 {
293- int len = strlen (pprefix->prefix);
294+ size_t multi_dir_len = 0;
295+ size_t multi_os_dir_len = 0;
296+ size_t suffix_len;
297+ size_t just_suffix_len;
298+ size_t len;
299+
300+ if (multi_dir)
301+ multi_dir_len = strlen (multi_dir);
302+ if (multi_os_dir)
303+ multi_os_dir_len = strlen (multi_os_dir);
304+ suffix_len = strlen (multi_suffix);
305+ just_suffix_len = strlen (just_multi_suffix);
306+
307+ if (path == NULL)
308+ {
309+ len = paths->max_len + extra_space + 1;
310+ if (suffix_len > multi_os_dir_len)
311+ len += suffix_len;
312+ else
313+ len += multi_os_dir_len;
314+ path = xmalloc (len);
315+ }
316
317- if (machine_suffix
318- && (! check_dir_p
319- || is_directory (pprefix->prefix, machine_suffix, 0)))
320+ for (pl = paths->plist; pl != 0; pl = pl->next)
321 {
322- if (!first_time)
323- obstack_1grow (&collect_obstack, PATH_SEPARATOR);
324+ len = strlen (pl->prefix);
325+ memcpy (path, pl->prefix, len);
326
327- first_time = FALSE;
328- obstack_grow (&collect_obstack, pprefix->prefix, len);
329- obstack_grow (&collect_obstack, machine_suffix, suffix_len);
330- }
331+ /* Look first in MACHINE/VERSION subdirectory. */
332+ if (!skip_multi_dir)
333+ {
334+ memcpy (path + len, multi_suffix, suffix_len + 1);
335+ ret = callback (path, callback_info);
336+ if (ret)
337+ break;
338+ }
339
340- if (just_machine_suffix
341- && pprefix->require_machine_suffix == 2
342- && (! check_dir_p
343- || is_directory (pprefix->prefix, just_machine_suffix, 0)))
344- {
345- if (! first_time)
346- obstack_1grow (&collect_obstack, PATH_SEPARATOR);
347+ /* Some paths are tried with just the machine (ie. target)
348+ subdir. This is used for finding as, ld, etc. */
349+ if (!skip_multi_dir
350+ && pl->require_machine_suffix == 2)
351+ {
352+ memcpy (path + len, just_multi_suffix, just_suffix_len + 1);
353+ ret = callback (path, callback_info);
354+ if (ret)
355+ break;
356+ }
357+
358+ /* Now try the base path. */
359+ if (!pl->require_machine_suffix
360+ && !(pl->os_multilib ? skip_multi_os_dir : skip_multi_dir))
361+ {
362+ const char *this_multi;
363+ size_t this_multi_len;
364+
365+ if (pl->os_multilib)
366+ {
367+ this_multi = multi_os_dir;
368+ this_multi_len = multi_os_dir_len;
369+ }
370+ else
371+ {
372+ this_multi = multi_dir;
373+ this_multi_len = multi_dir_len;
374+ }
375
376- first_time = FALSE;
377- obstack_grow (&collect_obstack, pprefix->prefix, len);
378- obstack_grow (&collect_obstack, just_machine_suffix,
379- just_suffix_len);
380+ if (this_multi_len)
381+ memcpy (path + len, this_multi, this_multi_len + 1);
382+ else
383+ path[len] = '\0';
384+
385+ ret = callback (path, callback_info);
386+ if (ret)
387+ break;
388+ }
389 }
390+ if (pl)
391+ break;
392
393- if (! pprefix->require_machine_suffix)
394- {
395- if (! first_time)
396- obstack_1grow (&collect_obstack, PATH_SEPARATOR);
397+ if (multi_dir == NULL && multi_os_dir == NULL)
398+ break;
399
400- first_time = FALSE;
401- obstack_grow (&collect_obstack, pprefix->prefix, len);
402+ /* Run through the paths again, this time without multilibs.
403+ Don't repeat any we have already seen. */
404+ if (multi_dir)
405+ {
406+ free ((char *) multi_dir);
407+ multi_dir = NULL;
408+ free ((char *) multi_suffix);
409+ multi_suffix = machine_suffix;
410+ free ((char *) just_multi_suffix);
411+ just_multi_suffix = just_machine_suffix;
412+ }
413+ else
414+ skip_multi_dir = true;
415+ if (multi_os_dir)
416+ {
417+ free ((char *) multi_os_dir);
418+ multi_os_dir = NULL;
419 }
420+ else
421+ skip_multi_os_dir = true;
422 }
423
424+ if (multi_dir)
425+ {
426+ free ((char *) multi_dir);
427+ free ((char *) multi_suffix);
428+ free ((char *) just_multi_suffix);
429+ }
430+ if (multi_os_dir)
431+ free ((char *) multi_os_dir);
432+ if (ret != path)
433+ free (path);
434+ return ret;
435+}
436+
437+/* Callback for build_search_list. Adds path to obstack being built. */
438+
439+struct add_to_obstack_info {
440+ struct obstack *ob;
441+ bool check_dir;
442+ bool first_time;
443+};
444+
445+static void *
446+add_to_obstack (char *path, void *data)
447+{
448+ struct add_to_obstack_info *info = data;
449+
450+ if (info->check_dir && !is_directory (path, false))
451+ return NULL;
452+
453+ if (!info->first_time)
454+ obstack_1grow (info->ob, PATH_SEPARATOR);
455+
456+ obstack_grow (info->ob, path, strlen (path));
457+
458+ info->first_time = false;
459+ return NULL;
460+}
461+
462+/* Build a list of search directories from PATHS.
463+ PREFIX is a string to prepend to the list.
464+ If CHECK_DIR_P is true we ensure the directory exists.
465+ If DO_MULTI is true, multilib paths are output first, then
466+ non-multilib paths.
467+ This is used mostly by putenv_from_prefixes so we use `collect_obstack'.
468+ It is also used by the --print-search-dirs flag. */
469+
470+static char *
471+build_search_list (const struct path_prefix *paths, const char *prefix,
472+ bool check_dir, bool do_multi)
473+{
474+ struct add_to_obstack_info info;
475+
476+ info.ob = &collect_obstack;
477+ info.check_dir = check_dir;
478+ info.first_time = true;
479+
480+ obstack_grow (&collect_obstack, prefix, strlen (prefix));
481+ obstack_1grow (&collect_obstack, '=');
482+
483+ for_each_path (paths, do_multi, 0, add_to_obstack, &info);
484+
485 obstack_1grow (&collect_obstack, '\0');
486 return XOBFINISH (&collect_obstack, char *);
487 }
488@@ -2419,9 +2569,10 @@
489 for collect. */
490
491 static void
492-putenv_from_prefixes (struct path_prefix *paths, const char *env_var)
493+putenv_from_prefixes (const struct path_prefix *paths, const char *env_var,
494+ bool do_multi)
495 {
496- putenv (build_search_list (paths, env_var, 1));
497+ putenv (build_search_list (paths, env_var, true, do_multi));
498 }
499
500
501 /* Check whether NAME can be accessed in MODE. This is like access,
502@@ -2442,20 +2593,53 @@
503 return access (name, mode);
504 }
505
506+/* Callback for find_a_file. Appends the file name to the directory
507+ path. If the resulting file exists in the right mode, return the
508+ full pathname to the file. */
509+
510+struct file_at_path_info {
511+ const char *name;
512+ const char *suffix;
513+ int name_len;
514+ int suffix_len;
515+ int mode;
516+};
517+
518+static void *
519+file_at_path (char *path, void *data)
520+{
521+ struct file_at_path_info *info = data;
522+ size_t len = strlen (path);
523+
524+ memcpy (path + len, info->name, info->name_len);
525+ len += info->name_len;
526+
527+ /* Some systems have a suffix for executable files.
528+ So try appending that first. */
529+ if (info->suffix_len)
530+ {
531+ memcpy (path + len, info->suffix, info->suffix_len + 1);
532+ if (access_check (path, info->mode) == 0)
533+ return path;
534+ }
535+
536+ path[len] = '\0';
537+ if (access_check (path, info->mode) == 0)
538+ return path;
539+
540+ return NULL;
541+}
542+
543 /* Search for NAME using the prefix list PREFIXES. MODE is passed to
544- access to check permissions.
545+ access to check permissions. If DO_MULTI is true, search multilib
546+ paths then non-multilib paths, otherwise do not search multilib paths.
547 Return 0 if not found, otherwise return its name, allocated with malloc. */
548
549 static char *
550-find_a_file (struct path_prefix *pprefix, const char *name, int mode,
551- int multilib)
552+find_a_file (const struct path_prefix *pprefix, const char *name, int mode,
553+ bool do_multi)
554 {
555- char *temp;
556- const char *const file_suffix =
557- ((mode & X_OK) != 0 ? HOST_EXECUTABLE_SUFFIX : "");
558- struct prefix_list *pl;
559- int len = pprefix->max_len + strlen (name) + strlen (file_suffix) + 1;
560- const char *multilib_name, *multilib_os_name;
561+ struct file_at_path_info info;
562
563 #ifdef DEFAULT_ASSEMBLER
564 if (! strcmp (name, "as") && access (DEFAULT_ASSEMBLER, mode) == 0)
565@@ -2467,112 +2651,24 @@
566 return xstrdup (DEFAULT_LINKER);
567 #endif
568
569- if (machine_suffix)
570- len += strlen (machine_suffix);
571-
572- multilib_name = name;
573- multilib_os_name = name;
574- if (multilib && multilib_os_dir)
575- {
576- int len1 = multilib_dir ? strlen (multilib_dir) + 1 : 0;
577- int len2 = strlen (multilib_os_dir) + 1;
578-
579- len += len1 > len2 ? len1 : len2;
580- if (multilib_dir)
581- multilib_name = ACONCAT ((multilib_dir, dir_separator_str, name,
582- NULL));
583- if (strcmp (multilib_os_dir, ".") != 0)
584- multilib_os_name = ACONCAT ((multilib_os_dir, dir_separator_str, name,
585- NULL));
586- }
587-
588- temp = xmalloc (len);
589-
590 /* Determine the filename to execute (special case for absolute paths). */
591
592 if (IS_ABSOLUTE_PATH (name))
593 {
594 if (access (name, mode) == 0)
595- {
596- strcpy (temp, name);
597- return temp;
598- }
599- }
600- else
601- for (pl = pprefix->plist; pl; pl = pl->next)
602- {
603- const char *this_name
604- = pl->os_multilib ? multilib_os_name : multilib_name;
605+ return xstrdup (name);
606
607- if (machine_suffix)
608- {
609- /* Some systems have a suffix for executable files.
610- So try appending that first. */
611- if (file_suffix[0] != 0)
612- {
613- strcpy (temp, pl->prefix);
614- strcat (temp, machine_suffix);
615- strcat (temp, multilib_name);
616- strcat (temp, file_suffix);
617- if (access_check (temp, mode) == 0)
618- return temp;
619- }
620-
621- /* Now try just the multilib_name. */
622- strcpy (temp, pl->prefix);
623- strcat (temp, machine_suffix);
624- strcat (temp, multilib_name);
625- if (access_check (temp, mode) == 0)
626- return temp;
627- }
628-
629- /* Certain prefixes are tried with just the machine type,
630- not the version. This is used for finding as, ld, etc. */
631- if (just_machine_suffix && pl->require_machine_suffix == 2)
632- {
633- /* Some systems have a suffix for executable files.
634- So try appending that first. */
635- if (file_suffix[0] != 0)
636- {
637- strcpy (temp, pl->prefix);
638- strcat (temp, just_machine_suffix);
639- strcat (temp, multilib_name);
640- strcat (temp, file_suffix);
641- if (access_check (temp, mode) == 0)
642- return temp;
643- }
644-
645- strcpy (temp, pl->prefix);
646- strcat (temp, just_machine_suffix);
647- strcat (temp, multilib_name);
648- if (access_check (temp, mode) == 0)
649- return temp;
650- }
651-
652- /* Certain prefixes can't be used without the machine suffix
653- when the machine or version is explicitly specified. */
654- if (! pl->require_machine_suffix)
655- {
656- /* Some systems have a suffix for executable files.
657- So try appending that first. */
658- if (file_suffix[0] != 0)
659- {
660- strcpy (temp, pl->prefix);
661- strcat (temp, this_name);
662- strcat (temp, file_suffix);
663- if (access_check (temp, mode) == 0)
664- return temp;
665- }
666+ return NULL;
667+ }
668
669- strcpy (temp, pl->prefix);
670- strcat (temp, this_name);
671- if (access_check (temp, mode) == 0)
672- return temp;
673- }
674- }
675+ info.name = name;
676+ info.suffix = (mode & X_OK) != 0 ? HOST_EXECUTABLE_SUFFIX : "";
677+ info.name_len = strlen (info.name);
678+ info.suffix_len = strlen (info.suffix);
679+ info.mode = mode;
680
681- free (temp);
682- return 0;
683+ return for_each_path (pprefix, do_multi, info.name_len + info.suffix_len,
684+ file_at_path, &info);
685 }
686
687 /* Ranking of prefixes in the sort list. -B prefixes are put before
688@@ -2691,7 +2787,7 @@
689
690 commands[0].prog = argbuf[0]; /* first command. */
691 commands[0].argv = &argbuf[0];
692- string = find_a_file (&exec_prefixes, commands[0].prog, X_OK, 0);
693+ string = find_a_file (&exec_prefixes, commands[0].prog, X_OK, false);
694
695 if (string)
696 commands[0].argv[0] = string;
697@@ -2706,7 +2802,7 @@
698 commands[n_commands].prog = argbuf[i + 1];
699 commands[n_commands].argv = &argbuf[i + 1];
700 string = find_a_file (&exec_prefixes, commands[n_commands].prog,
701- X_OK, 0);
702+ X_OK, false);
703 if (string)
704 commands[n_commands].argv[0] = string;
705 n_commands++;
706@@ -3643,7 +3739,7 @@
707 if appending a directory separator actually makes a
708 valid directory name. */
709 if (! IS_DIR_SEPARATOR (value [len - 1])
710- && is_directory (value, "", 0))
711+ && is_directory (value, false))
712 {
713 char *tmp = xmalloc (len + 2);
714 strcpy (tmp, value);
715@@ -4391,108 +4487,55 @@
716 }
717 }
718
719-void
720-do_spec_path (struct prefix_list *pl, const char *option,
721- int omit_if_relative, int separate_options,
722- int only_subdir,
723- const char *dir_for_machine_suffix,
724- const char *dir_for_no_suffix)
725-{
726- static size_t bufsize = 0;
727- static char *buffer;
728- int idx;
729- bool multilib_p = false;
730-
731- /* Used on systems which record the specified -L dirs
732- and use them to search for dynamic linking. */
733- /* Relative directories always come from -B,
734- and it is better not to use them for searching
735- at run time. In particular, stage1 loses. */
736- if (omit_if_relative
737- && !IS_ABSOLUTE_PATH (pl->prefix))
738- return;
739+/* Callback for processing %D and %I specs. */
740
741- /* Try subdirectory if there is one. */
742- if (machine_suffix && dir_for_machine_suffix)
743- {
744- if (strlen (pl->prefix) + strlen (machine_suffix)
745- >= bufsize)
746- bufsize = (strlen (pl->prefix)
747- + strlen (machine_suffix)) * 2 + 1;
748- buffer = xrealloc (buffer, bufsize);
749- strcpy (buffer, pl->prefix);
750- strcat (buffer, machine_suffix);
751- if (is_directory (buffer, dir_for_machine_suffix, 1))
752- {
753- multilib_p = true;
754- do_spec_1 (option, separate_options, NULL);
755- if (separate_options)
756- do_spec_1 (" ", 0, NULL);
757- do_spec_1 (buffer, 1, NULL);
758- do_spec_1 (dir_for_machine_suffix, 1, NULL);
759- /* Make this a separate argument. */
760- do_spec_1 (" ", 0, NULL);
761- }
762- }
763- if (!pl->require_machine_suffix && dir_for_no_suffix)
764+struct spec_path_info {
765+ const char *option;
766+ const char *append;
767+ size_t append_len;
768+ bool omit_relative;
769+ bool separate_options;
770+};
771+
772+static void *
773+spec_path (char *path, void *data)
774+{
775+ struct spec_path_info *info = data;
776+ size_t len = 0;
777+ char save = 0;
778+
779+ if (info->omit_relative && !IS_ABSOLUTE_PATH (path))
780+ return NULL;
781+
782+ if (info->append_len != 0)
783 {
784- if (is_directory (pl->prefix, dir_for_no_suffix, 1))
785- {
786- multilib_p = true;
787- do_spec_1 (option, separate_options, NULL);
788- if (separate_options)
789- do_spec_1 (" ", 0, NULL);
790- do_spec_1 (pl->prefix, 1, NULL);
791- do_spec_1 (dir_for_no_suffix, 1, NULL);
792- /* Make this a separate argument. */
793- do_spec_1 (" ", 0, NULL);
794- }
795+ len = strlen (path);
796+ memcpy (path + len, info->append, info->append_len + 1);
797 }
798
799- if (only_subdir || multilib_p)
800- return;
801+ if (!is_directory (path, true))
802+ return NULL;
803+
804+ do_spec_1 (info->option, 1, NULL);
805+ if (info->separate_options)
806+ do_spec_1 (" ", 0, NULL);
807
808- if (machine_suffix)
809+ if (info->append_len == 0)
810 {
811- if (is_directory (pl->prefix, machine_suffix, 1))
812- {
813- do_spec_1 (option, separate_options, NULL);
814- if (separate_options)
815- do_spec_1 (" ", 0, NULL);
816- do_spec_1 (pl->prefix, 1, NULL);
817- /* Remove slash from machine_suffix. */
818- if (strlen (machine_suffix) >= bufsize)
819- bufsize = strlen (machine_suffix) * 2 + 1;
820- buffer = xrealloc (buffer, bufsize);
821- strcpy (buffer, machine_suffix);
822- idx = strlen (buffer);
823- if (IS_DIR_SEPARATOR (buffer[idx - 1]))
824- buffer[idx - 1] = 0;
825- do_spec_1 (buffer, 1, NULL);
826- /* Make this a separate argument. */
827- do_spec_1 (" ", 0, NULL);
828- }
829- }
830- if (!pl->require_machine_suffix)
831- {
832- if (is_directory (pl->prefix, "", 1))
833- {
834- do_spec_1 (option, separate_options, NULL);
835- if (separate_options)
836- do_spec_1 (" ", 0, NULL);
837- /* Remove slash from pl->prefix. */
838- if (strlen (pl->prefix) >= bufsize)
839- bufsize = strlen (pl->prefix) * 2 + 1;
840- buffer = xrealloc (buffer, bufsize);
841- strcpy (buffer, pl->prefix);
842- idx = strlen (buffer);
843- if (IS_DIR_SEPARATOR (buffer[idx - 1]))
844- buffer[idx - 1] = 0;
845- do_spec_1 (buffer, 1, NULL);
846- /* Make this a separate argument. */
847- do_spec_1 (" ", 0, NULL);
848- }
849+ len = strlen (path);
850+ save = path[len - 1];
851+ if (IS_DIR_SEPARATOR (path[len - 1]))
852+ path[len - 1] = '\0';
853 }
854+
855+ do_spec_1 (path, 1, NULL);
856+ do_spec_1 (" ", 0, NULL);
857+
858+ /* Must not damage the original path. */
859+ if (info->append_len == 0)
860+ path[len - 1] = save;
861+
862+ return NULL;
863 }
864
865 /* Process the sub-spec SPEC as a portion of a larger spec.
866@@ -4630,23 +4673,23 @@
867 that we search for startfiles. */
868 case 'D':
869 {
870- struct prefix_list *pl = startfile_prefixes.plist;
871-
872- for (; pl; pl = pl->next)
873- {
874- const char *no_suffix_multilib_dir;
875+ struct spec_path_info info;
876
877- no_suffix_multilib_dir = pl->os_multilib ? multilib_os_dir
878- : multilib_dir;
879- /* Do not separate options, include non-multilibbed variant. */
880- do_spec_path (pl, "-L",
881+ info.option = "-L";
882+ info.append_len = 0;
883 #ifdef RELATIVE_PREFIX_NOT_LINKDIR
884- 1,
885+ /* Used on systems which record the specified -L dirs
886+ and use them to search for dynamic linking.
887+ Relative directories always come from -B,
888+ and it is better not to use them for searching
889+ at run time. In particular, stage1 loses. */
890+ info.omit_relative = true;
891 #else
892- 0,
893+ info.omit_relative = false;
894 #endif
895- 0, 0, multilib_dir, no_suffix_multilib_dir);
896- }
897+ info.separate_options = false;
898+
899+ for_each_path (&startfile_prefixes, true, 0, spec_path, &info);
900 }
901 break;
902
903@@ -4883,7 +4926,7 @@
904
905 case 'I':
906 {
907- struct prefix_list *pl = include_prefixes.plist;
908+ struct spec_path_info info;
909
910 if (gcc_exec_prefix)
911 {
912@@ -4906,9 +4949,14 @@
913 do_spec_1 (" ", 0, NULL);
914 }
915
916- for (; pl; pl = pl->next)
917- /* Separate options, don't include non-suffixed variant. */
918- do_spec_path (pl, "-isystem", 0, 1, 1, "include", "include");
919+ info.option = "-isystem";
920+ info.append = "include";
921+ info.append_len = strlen (info.append);
922+ info.omit_relative = false;
923+ info.separate_options = true;
924+
925+ for_each_path (&include_prefixes, false, info.append_len,
926+ spec_path, &info);
927 }
928 break;
929
930@@ -5894,48 +5942,27 @@
931 static const char *
932 find_file (const char *name)
933 {
934- char *newname;
935-
936- /* Try multilib_dir if it is defined. */
937- if (multilib_os_dir != NULL)
938- {
939- newname = find_a_file (&startfile_prefixes, name, R_OK, 1);
940-
941- /* If we don't find it in the multi library dir, then fall
942- through and look for it in the normal places. */
943- if (newname != NULL)
944- return newname;
945- }
946-
947- newname = find_a_file (&startfile_prefixes, name, R_OK, 0);
948+ char *newname = find_a_file (&startfile_prefixes, name, R_OK, true);
949 return newname ? newname : name;
950 }
951
952 /* Determine whether a directory exists. If LINKER, return 0 for
953- certain fixed names not needed by the linker. If not LINKER, it is
954- only important to return 0 if the host machine has a small ARG_MAX
955- limit. */
956+ certain fixed names not needed by the linker. */
957
958 static int
959-is_directory (const char *path1, const char *path2, int linker)
960+is_directory (const char *path1, bool linker)
961 {
962- int len1 = strlen (path1);
963- int len2 = strlen (path2);
964- char *path = alloca (3 + len1 + len2);
965+ int len1;
966+ char *path;
967 char *cp;
968 struct stat st;
969
970-#ifndef SMALL_ARG_MAX
971- if (! linker)
972- return 1;
973-#endif
974-
975- /* Construct the path from the two parts. Ensure the string ends with "/.".
976- The resulting path will be a directory even if the given path is a
977- symbolic link. */
978+ /* Ensure the string ends with "/.". The resulting path will be a
979+ directory even if the given path is a symbolic link. */
980+ len1 = strlen (path1);
981+ path = alloca (3 + len1);
982 memcpy (path, path1, len1);
983- memcpy (path + len1, path2, len2);
984- cp = path + len1 + len2;
985+ cp = path + len1;
986 if (!IS_DIR_SEPARATOR (cp[-1]))
987 *cp++ = DIR_SEPARATOR;
988 *cp++ = '.';
989@@ -5943,13 +5970,13 @@
990
991 /* Exclude directories that the linker is known to search. */
992 if (linker
993+ && IS_DIR_SEPARATOR (path[0])
994 && ((cp - path == 6
995- && strcmp (path, concat (dir_separator_str, "lib",
996- dir_separator_str, ".", NULL)) == 0)
997+ && strncmp (path + 1, "lib", 3) == 0)
998 || (cp - path == 10
999- && strcmp (path, concat (dir_separator_str, "usr",
1000- dir_separator_str, "lib",
1001- dir_separator_str, ".", NULL)) == 0)))
1002+ && strncmp (path + 1, "usr", 3) == 0
1003+ && IS_DIR_SEPARATOR (path[4])
1004+ && strncmp (path + 5, "lib", 3) == 0)))
1005 return 0;
1006
1007 return (stat (path, &st) >= 0 && S_ISDIR (st.st_mode));
1008@@ -6139,7 +6166,7 @@
1009 spec_version, dir_separator_str, NULL);
1010 just_machine_suffix = concat (spec_machine, dir_separator_str, NULL);
1011
1012- specs_file = find_a_file (&startfile_prefixes, "specs", R_OK, 0);
1013+ specs_file = find_a_file (&startfile_prefixes, "specs", R_OK, true);
1014 /* Read the specs file unless it is a default one. */
1015 if (specs_file != 0 && strcmp (specs_file, "specs"))
1016 read_specs (specs_file, TRUE);
1017@@ -6275,7 +6302,7 @@
1018 for (uptr = user_specs_head; uptr; uptr = uptr->next)
1019 {
1020 char *filename = find_a_file (&startfile_prefixes, uptr->filename,
1021- R_OK, 0);
1022+ R_OK, true);
1023 read_specs (filename ? filename : uptr->filename, FALSE);
1024 }
1025
1026@@ -6304,8 +6331,10 @@
1027 if (print_search_dirs)
1028 {
1029 printf (_("install: %s%s\n"), standard_exec_prefix, machine_suffix);
1030- printf (_("programs: %s\n"), build_search_list (&exec_prefixes, "", 0));
1031- printf (_("libraries: %s\n"), build_search_list (&startfile_prefixes, "", 0));
1032+ printf (_("programs: %s\n"),
1033+ build_search_list (&exec_prefixes, "", false, false));
1034+ printf (_("libraries: %s\n"),
1035+ build_search_list (&startfile_prefixes, "", false, true));
1036 return (0);
1037 }
1038
1039@@ -6622,14 +6651,14 @@
1040 /* We'll use ld if we can't find collect2. */
1041 if (! strcmp (linker_name_spec, "collect2"))
1042 {
1043- char *s = find_a_file (&exec_prefixes, "collect2", X_OK, 0);
1044+ char *s = find_a_file (&exec_prefixes, "collect2", X_OK, false);
1045 if (s == NULL)
1046 linker_name_spec = "ld";
1047 }
1048 /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
1049 for collect. */
1050- putenv_from_prefixes (&exec_prefixes, "COMPILER_PATH");
1051- putenv_from_prefixes (&startfile_prefixes, LIBRARY_PATH_ENV);
1052+ putenv_from_prefixes (&exec_prefixes, "COMPILER_PATH", false);
1053+ putenv_from_prefixes (&startfile_prefixes, LIBRARY_PATH_ENV, true);
1054
1055 value = do_spec (link_command_spec);
1056 if (value < 0)
1057diff -uNr gcc-4.1.0/gcc/system.h gcc-4.1.0-PR20425/gcc/system.h
1058--- gcc-4.1.0/gcc/system.h 2005-08-16 10:13:53.000000000 +1000
1059+++ gcc-4.1.0-PR20425/gcc/system.h 2006-03-10 23:51:31.000000000 +1100
1060@@ -728,7 +728,8 @@
1061 TARGET_ESC TARGET_FF TARGET_NEWLINE TARGET_TAB TARGET_VT \
1062 LINK_LIBGCC_SPECIAL DONT_ACCESS_GBLS_AFTER_EPILOGUE \
1063 TARGET_OPTIONS TARGET_SWITCHES EXTRA_CC_MODES FINALIZE_PIC \
1064- PREDICATE_CODES SPECIAL_MODE_PREDICATES HOST_PTR_PRINTF
1065+ PREDICATE_CODES SPECIAL_MODE_PREDICATES HOST_PTR_PRINTF \
1066+ SMALL_ARG_MAX
1067
1068 /* Hooks that are no longer used. */
1069 #pragma GCC poison LANG_HOOKS_FUNCTION_MARK LANG_HOOKS_FUNCTION_FREE \
Note: See TracBrowser for help on using the repository browser.