Commit 7223feb0 by Doug Evans

collect2.c (our_file_name, [...]): deleted.

        * collect2.c (our_file_name, last_file_name): deleted.
        (our_file_names): New variable.
        (is_in_prefix_list): New function.
        (find_a_file): Call is_in_prefix_list.
        (main): Make COLLECT_NAMES a list of our invocations.
        If we've invoked ourselves, try again with ld_file_name.

From-SVN: r5262
parent cb61f66f
...@@ -551,8 +551,45 @@ static char *target_machine = TARGET_MACHINE; ...@@ -551,8 +551,45 @@ static char *target_machine = TARGET_MACHINE;
/* Names under which we were executed. Never return one of those files in our /* Names under which we were executed. Never return one of those files in our
searches. */ searches. */
static char *our_file_name, *last_file_name; static struct path_prefix our_file_names;
/* Determine if STRING is in PPREFIX.
This utility is currently only used to look up file names. Prefix lists
record directory names. This matters to us because the latter has a
trailing slash, so I've added a flag to handle both. */
static int
is_in_prefix_list (pprefix, string, filep)
struct path_prefix *pprefix;
char *string;
int filep;
{
struct prefix_list *pl;
if (filep)
{
int len = strlen (string);
for (pl = pprefix->plist; pl; pl = pl->next)
{
if (strncmp (pl->prefix, string, len) == 0
&& strcmp (pl->prefix + len, "/") == 0)
return 1;
}
}
else
{
for (pl = pprefix->plist; pl; pl = pl->next)
{
if (strcmp (pl->prefix, string) == 0)
return 1;
}
}
return 0;
}
/* Search for NAME using prefix list PPREFIX. We only look for executable /* Search for NAME using prefix list PPREFIX. We only look for executable
files. files.
...@@ -588,8 +625,7 @@ find_a_file (pprefix, name) ...@@ -588,8 +625,7 @@ find_a_file (pprefix, name)
{ {
strcpy (temp, pl->prefix); strcpy (temp, pl->prefix);
strcat (temp, name); strcat (temp, name);
if (strcmp (temp, our_file_name) != 0 if (! is_in_prefix_list (&our_file_names, temp, 1)
&& ! (last_file_name != 0 && strcmp (temp, last_file_name) == 0)
/* This is a kludge, but there seems no way around it. */ /* This is a kludge, but there seems no way around it. */
&& strcmp (temp, "./ld") != 0 && strcmp (temp, "./ld") != 0
&& access (temp, X_OK) == 0) && access (temp, X_OK) == 0)
...@@ -599,8 +635,7 @@ find_a_file (pprefix, name) ...@@ -599,8 +635,7 @@ find_a_file (pprefix, name)
/* Some systems have a suffix for executable files. /* Some systems have a suffix for executable files.
So try appending that. */ So try appending that. */
strcat (temp, EXECUTABLE_SUFFIX); strcat (temp, EXECUTABLE_SUFFIX);
if (strcmp (temp, our_file_name) != 0 if (! is_in_prefix_list (&our_file_names, temp, 1)
&& ! (last_file_name != 0 && strcmp (temp, last_file_name) == 0)
&& access (temp, X_OK) == 0) && access (temp, X_OK) == 0)
return temp; return temp;
#endif #endif
...@@ -716,6 +751,7 @@ main (argc, argv) ...@@ -716,6 +751,7 @@ main (argc, argv)
FILE *outf; FILE *outf;
char *ld_file_name; char *ld_file_name;
char *c_file_name; char *c_file_name;
char *collect_names;
char *p; char *p;
char **c_argv; char **c_argv;
char **c_ptr; char **c_ptr;
...@@ -733,23 +769,31 @@ main (argc, argv) ...@@ -733,23 +769,31 @@ main (argc, argv)
vflag = 1; vflag = 1;
#endif #endif
our_file_name = argv[0];
output_file = "a.out"; output_file = "a.out";
/* We must check that we do not call ourselves in an infinite /* We must check that we do not call ourselves in an infinite
recursion loop. We save the name used for us in the COLLECT_NAME recursion loop. We save the name used for us in the COLLECT_NAMES
environment variable, first getting the previous value. environment variable, first getting the previous value.
To be fully safe, we need to maintain a list of names that name In practice, collect will rarely invoke itself. This can happen now
been used, but, in practice, two names are enough. */ that we are no longer called gld. A perfect example is when running
gcc in a build directory that has been installed. When looking for
ld's, we'll find our installed version and believe that's the real ld. */
last_file_name = getenv ("COLLECT_NAME"); collect_names = (char *) getenv ("COLLECT_NAMES");
p = (char *) xmalloc (strlen (our_file_name) + strlen ("COLLECT_NAME=") + 1); p = (char *) xmalloc (strlen ("COLLECT_NAMES=")
sprintf (p, "COLLECT_NAME=%s", our_file_name); + (collect_names ? strlen (collect_names) + 1 : 0)
+ strlen (argv[0]) + 1);
if (collect_names != 0)
sprintf (p, "COLLECT_NAMES=%s%c%s",
collect_names, PATH_SEPARATOR, argv[0]);
else
sprintf (p, "COLLECT_NAMES=%s", argv[0]);
putenv (p); putenv (p);
prefix_from_env ("COLLECT_NAMES", &our_file_names);
p = (char *) getenv ("COLLECT_GCC_OPTIONS"); p = (char *) getenv ("COLLECT_GCC_OPTIONS");
if (p) if (p)
while (*p) while (*p)
...@@ -873,6 +917,18 @@ main (argc, argv) ...@@ -873,6 +917,18 @@ main (argc, argv)
if (ld_file_name == 0) if (ld_file_name == 0)
ld_file_name = find_a_file (&path, full_ld_suffix); ld_file_name = find_a_file (&path, full_ld_suffix);
/* If we've invoked ourselves, try again with LD_FILE_NAME. */
if (collect_names != 0)
{
if (ld_file_name != 0)
{
argv[0] = ld_file_name;
execvp (argv[0], argv);
}
fatal ("cannot find `ld'");
}
nm_file_name = find_a_file (&cpath, gnm_suffix); nm_file_name = find_a_file (&cpath, gnm_suffix);
if (nm_file_name == 0) if (nm_file_name == 0)
nm_file_name = find_a_file (&path, full_gnm_suffix); nm_file_name = find_a_file (&path, full_gnm_suffix);
...@@ -1038,6 +1094,10 @@ main (argc, argv) ...@@ -1038,6 +1094,10 @@ main (argc, argv)
fprintf (stderr, "o_file = %s\n", fprintf (stderr, "o_file = %s\n",
(o_file ? o_file : "not found")); (o_file ? o_file : "not found"));
ptr = getenv ("COLLECT_NAMES");
if (ptr)
fprintf (stderr, "COLLECT_NAMES = %s\n", ptr);
ptr = getenv ("COLLECT_GCC_OPTIONS"); ptr = getenv ("COLLECT_GCC_OPTIONS");
if (ptr) if (ptr)
fprintf (stderr, "COLLECT_GCC_OPTIONS = %s\n", ptr); fprintf (stderr, "COLLECT_GCC_OPTIONS = %s\n", ptr);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment