This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Search appropriate subdirectories of a -B-specified directory
- From: Paolo Bonzini <bonzini at gnu dot org>
- To: gcc-patches at gnu dot org
- Cc: paolo dot bonzini at polimi dot it
- Date: Sun, 02 May 2004 10:26:20 +0200
- Subject: [PATCH] Search appropriate subdirectories of a -B-specified directory
As part of toplevel bootstrapping, I need a way to run a preinstalled
GCC driver, and have it find all the files without resorting to
relative paths---otherwise, you end up with comparison failures due to
debugging information for the preinstalled fixed includes.
The solution implemented in this patch is to have -B also add prefixes
for lib/gcc/MACHINE/VERSION, libexec/gcc/MACHINE/VERSION and
lib/gcc/MACHINE/VERSION/include. It seems to me that this, if maybe
not so useful, at least makes the `-B' (or `--prefix') option match
the purpose of `--prefix' as a configure option, or of `prefix' as a
Makefile variable.
Adding the correct include path is a bit tricky. Most of the code
needed to append something after the MACHINE/VERSION part is already
there to support multilibs, and is easily abstracted from do_spec_1
into a separate function; however, I needed to modify include_prefixes
so that it does not end with "include", and instead add "include" on
the fly while processing the %I spec.
In the meanwhile, I removed support for SPACE_AFTER_L_OPTION. No
target defines it, and it was actually generating "-L xxx" instead of
"-L" "xxx", which seemed a bug to me.
Bootstrapped i686-pc-linux-gnu both with `make bootstrap' and with `make
new-bootstrap' with my preinstalling patches. I did not regtest, but it
does not seems that it would stress the patch more than bootstrapping
and building target libraries. Ok for mainline?
Paolo
2004-04-30 Paolo Bonzini <bonzini@gnu.org>
* gcc.c (struct prefix_list): Add forward declaration.
(do_spec_path): New function, extracted from...
(do_spec_1) <'D'>: ... here. Drop support for
SPACE_AFTER_L_OPTION.
(do_spec_1) <'I'>: Use do_spec_path.
(process_command): Do not append "/include" at the end of
the include_prefixes. When given a -B option add prefixes
for lib/gcc/MACHINE/VERSION, libexec/gcc/MACHINE/VERSION
and lib/gcc/MACHINE/VERSION/include.
* system.h: Poison SPACE_AFTER_L_OPTION.
diff -cp gcc-backup/gcc/gcc.c gcc/gcc/gcc.c
*** gcc-backup/gcc/gcc.c Fri Apr 30 18:28:51 2004
--- gcc/gcc/gcc.c Fri Apr 30 20:02:09 2004
*************** static struct rusage rus, prus;
*** 290,295 ****
--- 290,296 ----
/* Forward declaration for prototypes. */
struct path_prefix;
+ struct prefix_list;
static void init_spec (void);
static void store_arg (const char *, int, int);
*************** static const char *eval_spec_function (c
*** 323,328 ****
--- 324,330 ----
static const char *handle_spec_function (const char *);
static char *save_string (const char *, int);
static void set_collect_gcc_options (void);
+ static void do_spec_path (struct prefix_list *, const char *, int, int, int, const char *, const char *);
static int do_spec_1 (const char *, int, const char *);
static int do_spec_2 (const char *);
static void do_option_spec (const char *, const char *);
*************** process_command (int argc, const char **
*** 3276,3284 ****
nstore[endp - startp] = 0;
add_prefix (&exec_prefixes, nstore, 0,
PREFIX_PRIORITY_LAST, 0, NULL, 0);
! add_prefix (&include_prefixes,
! concat (nstore, "include", NULL),
! 0, PREFIX_PRIORITY_LAST, 0, NULL, 0);
if (*endp == 0)
break;
endp = startp = endp + 1;
--- 3278,3285 ----
nstore[endp - startp] = 0;
add_prefix (&exec_prefixes, nstore, 0,
PREFIX_PRIORITY_LAST, 0, NULL, 0);
! add_prefix (&include_prefixes, nstore, 0,
! PREFIX_PRIORITY_LAST, 0, NULL, 0);
if (*endp == 0)
break;
endp = startp = endp + 1;
*************** warranty; not even for MERCHANTABILITY o
*** 3630,3654 ****
&& (IS_DIR_SEPARATOR (value[len - 1])))
{
if (len == 7)
! add_prefix (&include_prefixes, "include", NULL,
PREFIX_PRIORITY_B_OPT, 0, NULL, 0);
else
{
! char * string = xmalloc (len + 1);
!
! strncpy (string, value, len - 7);
! strcpy (string + len - 7, "include");
! add_prefix (&include_prefixes, string, NULL,
PREFIX_PRIORITY_B_OPT, 0, NULL, 0);
}
}
add_prefix (&exec_prefixes, value, NULL,
PREFIX_PRIORITY_B_OPT, 0, &warn_B, 0);
add_prefix (&startfile_prefixes, value, NULL,
PREFIX_PRIORITY_B_OPT, 0, &warn_B, 0);
! add_prefix (&include_prefixes, concat (value, "include", NULL),
! NULL, PREFIX_PRIORITY_B_OPT, 0, NULL, 0);
n_switches++;
}
break;
--- 3631,3660 ----
&& (IS_DIR_SEPARATOR (value[len - 1])))
{
if (len == 7)
! add_prefix (&include_prefixes, "./", NULL,
PREFIX_PRIORITY_B_OPT, 0, NULL, 0);
else
{
! char *string = xmalloc (len - 6);
! memcpy (string, value, len - 7);
! string[len - 7] = 0;
! add_prefix (&include_prefixes, string, NULL,
PREFIX_PRIORITY_B_OPT, 0, NULL, 0);
}
}
add_prefix (&exec_prefixes, value, NULL,
PREFIX_PRIORITY_B_OPT, 0, &warn_B, 0);
+ add_prefix (&exec_prefixes, concat (value, "libexec/gcc/", NULL),
+ NULL, PREFIX_PRIORITY_B_OPT, 1, &warn_B, 0);
add_prefix (&startfile_prefixes, value, NULL,
PREFIX_PRIORITY_B_OPT, 0, &warn_B, 0);
! add_prefix (&startfile_prefixes, concat (value, "lib/gcc/", NULL),
! NULL, PREFIX_PRIORITY_B_OPT, 1, &warn_B, 0);
! add_prefix (&include_prefixes, value, NULL,
! PREFIX_PRIORITY_B_OPT, 0, NULL, 0);
! add_prefix (&include_prefixes, concat (value, "lib/gcc/", NULL),
! NULL, PREFIX_PRIORITY_B_OPT, 1, &warn_B, 0);
n_switches++;
}
break;
*************** do_self_spec (const char *spec)
*** 4361,4366 ****
--- 4367,4473 ----
}
}
+ void
+ do_spec_path (struct prefix_list *pl, const char *option,
+ int omit_if_relative, int separate_options,
+ int only_subdir,
+ const char *dir_for_machine_suffix,
+ const char *dir_for_no_suffix)
+ {
+ static size_t bufsize = 0;
+ static char *buffer;
+ int idx;
+
+ /* Used on systems which record the specified -L dirs
+ and use them to search for dynamic linking. */
+ /* Relative directories always come from -B,
+ and it is better not to use them for searching
+ at run time. In particular, stage1 loses. */
+ if (omit_if_relative
+ && !IS_ABSOLUTE_PATH (pl->prefix))
+ return;
+
+ /* Try subdirectory if there is one. */
+ if (machine_suffix && dir_for_machine_suffix)
+ {
+ if (strlen (pl->prefix) + strlen (machine_suffix)
+ >= bufsize)
+ bufsize = (strlen (pl->prefix)
+ + strlen (machine_suffix)) * 2 + 1;
+ buffer = xrealloc (buffer, bufsize);
+ strcpy (buffer, pl->prefix);
+ strcat (buffer, machine_suffix);
+ if (is_directory (buffer, dir_for_machine_suffix, 1))
+ {
+ do_spec_1 (option, separate_options, NULL);
+ if (separate_options)
+ do_spec_1 (" ", 0, NULL);
+ do_spec_1 (buffer, 1, NULL);
+ do_spec_1 (dir_for_machine_suffix, 1, NULL);
+ /* Make this a separate argument. */
+ do_spec_1 (" ", 0, NULL);
+ }
+ }
+ if (!pl->require_machine_suffix && dir_for_no_suffix)
+ {
+ if (is_directory (pl->prefix, dir_for_no_suffix, 1))
+ {
+ do_spec_1 (option, separate_options, NULL);
+ if (separate_options)
+ do_spec_1 (" ", 0, NULL);
+ do_spec_1 (pl->prefix, 1, NULL);
+ do_spec_1 (dir_for_no_suffix, 1, NULL);
+ /* Make this a separate argument. */
+ do_spec_1 (" ", 0, NULL);
+ }
+ }
+
+ if (only_subdir)
+ return;
+
+ if (machine_suffix)
+ {
+ if (is_directory (pl->prefix, machine_suffix, 1))
+ {
+ do_spec_1 (option, separate_options, NULL);
+ if (separate_options)
+ do_spec_1 (" ", 0, NULL);
+ do_spec_1 (pl->prefix, 1, NULL);
+ /* Remove slash from machine_suffix. */
+ if (strlen (machine_suffix) >= bufsize)
+ bufsize = strlen (machine_suffix) * 2 + 1;
+ buffer = xrealloc (buffer, bufsize);
+ strcpy (buffer, machine_suffix);
+ idx = strlen (buffer);
+ if (IS_DIR_SEPARATOR (buffer[idx - 1]))
+ buffer[idx - 1] = 0;
+ do_spec_1 (buffer, 1, NULL);
+ /* Make this a separate argument. */
+ do_spec_1 (" ", 0, NULL);
+ }
+ }
+ if (!pl->require_machine_suffix)
+ {
+ if (is_directory (pl->prefix, "", 1))
+ {
+ do_spec_1 (option, separate_options, NULL);
+ if (separate_options)
+ do_spec_1 (" ", 0, NULL);
+ /* Remove slash from pl->prefix. */
+ if (strlen (pl->prefix) >= bufsize)
+ bufsize = strlen (pl->prefix) * 2 + 1;
+ buffer = xrealloc (buffer, bufsize);
+ strcpy (buffer, pl->prefix);
+ idx = strlen (buffer);
+ if (IS_DIR_SEPARATOR (buffer[idx - 1]))
+ buffer[idx - 1] = 0;
+ do_spec_1 (buffer, 1, NULL);
+ /* Make this a separate argument. */
+ do_spec_1 (" ", 0, NULL);
+ }
+ }
+ }
+
/* Process the sub-spec SPEC as a portion of a larger spec.
This is like processing a whole spec except that we do
not initialize at the beginning and we do not supply a
*************** do_spec_1 (const char *spec, int inswitc
*** 4497,4606 ****
case 'D':
{
struct prefix_list *pl = startfile_prefixes.plist;
- size_t bufsize = 100;
- char *buffer = xmalloc (bufsize);
- int idx;
for (; pl; pl = pl->next)
{
#ifdef RELATIVE_PREFIX_NOT_LINKDIR
! /* Used on systems which record the specified -L dirs
! and use them to search for dynamic linking. */
! /* Relative directories always come from -B,
! and it is better not to use them for searching
! at run time. In particular, stage1 loses. */
! if (!IS_ABSOLUTE_PATH (pl->prefix))
! continue;
#endif
! /* Try subdirectory if there is one. */
! if (multilib_dir != NULL
! || (pl->os_multilib && multilib_os_dir != NULL))
! {
! const char *multi_dir;
!
! multi_dir = pl->os_multilib ? multilib_os_dir
! : multilib_dir;
! if (machine_suffix && multilib_dir)
! {
! if (strlen (pl->prefix) + strlen (machine_suffix)
! >= bufsize)
! bufsize = (strlen (pl->prefix)
! + strlen (machine_suffix)) * 2 + 1;
! buffer = xrealloc (buffer, bufsize);
! strcpy (buffer, pl->prefix);
! strcat (buffer, machine_suffix);
! if (is_directory (buffer, multilib_dir, 1))
! {
! do_spec_1 ("-L", 0, NULL);
! #ifdef SPACE_AFTER_L_OPTION
! do_spec_1 (" ", 0, NULL);
! #endif
! do_spec_1 (buffer, 1, NULL);
! do_spec_1 (multilib_dir, 1, NULL);
! /* Make this a separate argument. */
! do_spec_1 (" ", 0, NULL);
! }
! }
! if (!pl->require_machine_suffix)
! {
! if (is_directory (pl->prefix, multi_dir, 1))
! {
! do_spec_1 ("-L", 0, NULL);
! #ifdef SPACE_AFTER_L_OPTION
! do_spec_1 (" ", 0, NULL);
! #endif
! do_spec_1 (pl->prefix, 1, NULL);
! do_spec_1 (multi_dir, 1, NULL);
! /* Make this a separate argument. */
! do_spec_1 (" ", 0, NULL);
! }
! }
! }
! if (machine_suffix)
! {
! if (is_directory (pl->prefix, machine_suffix, 1))
! {
! do_spec_1 ("-L", 0, NULL);
! #ifdef SPACE_AFTER_L_OPTION
! do_spec_1 (" ", 0, NULL);
! #endif
! do_spec_1 (pl->prefix, 1, NULL);
! /* Remove slash from machine_suffix. */
! if (strlen (machine_suffix) >= bufsize)
! bufsize = strlen (machine_suffix) * 2 + 1;
! buffer = xrealloc (buffer, bufsize);
! strcpy (buffer, machine_suffix);
! idx = strlen (buffer);
! if (IS_DIR_SEPARATOR (buffer[idx - 1]))
! buffer[idx - 1] = 0;
! do_spec_1 (buffer, 1, NULL);
! /* Make this a separate argument. */
! do_spec_1 (" ", 0, NULL);
! }
! }
! if (!pl->require_machine_suffix)
! {
! if (is_directory (pl->prefix, "", 1))
! {
! do_spec_1 ("-L", 0, NULL);
! #ifdef SPACE_AFTER_L_OPTION
! do_spec_1 (" ", 0, NULL);
! #endif
! /* Remove slash from pl->prefix. */
! if (strlen (pl->prefix) >= bufsize)
! bufsize = strlen (pl->prefix) * 2 + 1;
! buffer = xrealloc (buffer, bufsize);
! strcpy (buffer, pl->prefix);
! idx = strlen (buffer);
! if (IS_DIR_SEPARATOR (buffer[idx - 1]))
! buffer[idx - 1] = 0;
! do_spec_1 (buffer, 1, NULL);
! /* Make this a separate argument. */
! do_spec_1 (" ", 0, NULL);
! }
! }
}
- free (buffer);
}
break;
--- 4604,4625 ----
case 'D':
{
struct prefix_list *pl = startfile_prefixes.plist;
for (; pl; pl = pl->next)
{
+ const char *no_suffix_multilib_dir;
+
+ no_suffix_multilib_dir = pl->os_multilib ? multilib_os_dir
+ : multilib_dir;
+ /* Do not separate options, include non-multilibbed variant. */
+ do_spec_path (pl, "-L",
#ifdef RELATIVE_PREFIX_NOT_LINKDIR
! 1,
! #else
! 0,
#endif
! 0, 0, multilib_dir, no_suffix_multilib_dir);
}
}
break;
*************** do_spec_1 (const char *spec, int inswitc
*** 4852,4864 ****
}
for (; pl; pl = pl->next)
! {
! do_spec_1 ("-isystem", 1, NULL);
! /* Make this a separate argument. */
! do_spec_1 (" ", 0, NULL);
! do_spec_1 (pl->prefix, 1, NULL);
! do_spec_1 (" ", 0, NULL);
! }
}
break;
--- 4871,4878 ----
}
for (; pl; pl = pl->next)
! /* Separate options, don't include non-suffixed variant. */
! do_spec_path (pl, "-isystem", 0, 1, 1, "include", "include");
}
break;
diff -cp gcc-backup/gcc/system.h gcc/gcc/system.h
*** gcc-backup/gcc/system.h Fri Apr 30 18:28:51 2004
--- gcc/gcc/system.h Fri Apr 30 20:16:17 2004
*************** typedef char _Bool;
*** 641,647 ****
FINAL_REG_PARM_STACK_SPACE MAYBE_REG_PARM_STACK_SPACE \
TRADITIONAL_PIPELINE_INTERFACE DFA_PIPELINE_INTERFACE \
DBX_OUTPUT_STANDARD_TYPES BUILTIN_SETJMP_FRAME_VALUE \
! SUNOS4_SHARED_LIBRARIES
/* Hooks that are no longer used. */
#pragma GCC poison LANG_HOOKS_FUNCTION_MARK LANG_HOOKS_FUNCTION_FREE \
--- 641,647 ----
FINAL_REG_PARM_STACK_SPACE MAYBE_REG_PARM_STACK_SPACE \
TRADITIONAL_PIPELINE_INTERFACE DFA_PIPELINE_INTERFACE \
DBX_OUTPUT_STANDARD_TYPES BUILTIN_SETJMP_FRAME_VALUE \
! SUNOS4_SHARED_LIBRARIES SPACE_AFTER_L_OPTION
/* Hooks that are no longer used. */
#pragma GCC poison LANG_HOOKS_FUNCTION_MARK LANG_HOOKS_FUNCTION_FREE \