tlink.c 18.5 KB
Newer Older
1 2 3
/* Scan linker error messages for missing template instantiations and provide
   them.

4
   Copyright (C) 1995, 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2007, 2008
5
   Free Software Foundation, Inc.
6 7
   Contributed by Jason Merrill (jason@cygnus.com).

8
This file is part of GCC.
9

10 11
GCC is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
12
Software Foundation; either version 3, or (at your option) any later
13
version.
14

15 16 17 18
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
for more details.
19 20

You should have received a copy of the GNU General Public License
21 22
along with GCC; see the file COPYING3.  If not see
<http://www.gnu.org/licenses/>.  */
23 24

#include "config.h"
25
#include "system.h"
26 27
#include "coretypes.h"
#include "tm.h"
28
#include "intl.h"
29 30
#include "obstack.h"
#include "hashtab.h"
31
#include "demangle.h"
32
#include "collect2.h"
33
#include "libiberty.h"
34 35 36 37 38 39 40

#define MAX_ITERATIONS 17

/* Defined in the automatically-generated underscore.c.  */
extern int prepends_underscore;

static int tlink_verbose;
41

42
static char *initial_cwd;
43

44
/* Hash table boilerplate for working with htab_t.  We have hash tables
Jason Merrill committed
45
   for symbol names, file names, and demangled symbols.  */
46 47 48

typedef struct symbol_hash_entry
{
49
  const char *key;
50 51 52 53 54 55 56 57
  struct file_hash_entry *file;
  int chosen;
  int tweaking;
  int tweaked;
} symbol;

typedef struct file_hash_entry
{
58
  const char *key;
59 60 61 62 63 64 65 66
  const char *args;
  const char *dir;
  const char *main;
  int tweaking;
} file;

typedef struct demangled_hash_entry
{
67
  const char *key;
68 69 70
  const char *mangled;
} demangled;

71 72
/* Hash and comparison functions for these hash tables.  */

73 74
static int hash_string_eq (const void *, const void *);
static hashval_t hash_string_hash (const void *);
75 76

static int
77
hash_string_eq (const void *s1_p, const void *s2_p)
78
{
Kazu Hirata committed
79 80
  const char *const *s1 = (const char *const *) s1_p;
  const char *s2 = (const char *) s2_p;
81 82 83 84
  return strcmp (*s1, s2) == 0;
}

static hashval_t
85
hash_string_hash (const void *s_p)
86
{
Kazu Hirata committed
87
  const char *const *s = (const char *const *) s_p;
88 89 90 91
  return (*htab_hash_string) (*s);
}

static htab_t symbol_table;
92

93 94 95 96 97 98 99 100
static struct symbol_hash_entry * symbol_hash_lookup (const char *, int);
static struct file_hash_entry * file_hash_lookup (const char *);
static struct demangled_hash_entry *demangled_hash_lookup (const char *, int);
static void symbol_push (symbol *);
static symbol * symbol_pop (void);
static void file_push (file *);
static file * file_pop (void);
static void tlink_init (void);
101
static int tlink_execute (const char *, char **, const char *, const char *);
102 103 104 105 106 107 108 109 110 111 112
static char * frob_extension (const char *, const char *);
static char * obstack_fgets (FILE *, struct obstack *);
static char * tfgets (FILE *);
static char * pfgets (FILE *);
static void freadsym (FILE *, file *, int);
static void read_repo_file (file *);
static void maybe_tweak (char *, file *);
static int recompile_files (void);
static int read_repo_files (char **);
static void demangle_new_symbols (void);
static int scan_linker_output (const char *);
Kaveh R. Ghazi committed
113

Jason Merrill committed
114 115
/* Look up an entry in the symbol hash table.  */

116
static struct symbol_hash_entry *
117
symbol_hash_lookup (const char *string, int create)
118
{
119
  void **e;
120
  e = htab_find_slot_with_hash (symbol_table, string,
Kazu Hirata committed
121
				(*htab_hash_string) (string),
122 123 124 125
				create ? INSERT : NO_INSERT);
  if (e == NULL)
    return NULL;
  if (*e == NULL)
126
    {
127
      struct symbol_hash_entry *v;
128
      *e = v = XCNEW (struct symbol_hash_entry);
129
      v->key = xstrdup (string);
130
    }
131
  return (struct symbol_hash_entry *) *e;
132 133
}

134 135
static htab_t file_table;

Jason Merrill committed
136 137
/* Look up an entry in the file hash table.  */

138
static struct file_hash_entry *
139
file_hash_lookup (const char *string)
140
{
141
  void **e;
142
  e = htab_find_slot_with_hash (file_table, string,
Kazu Hirata committed
143
				(*htab_hash_string) (string),
144 145
				INSERT);
  if (*e == NULL)
146
    {
147
      struct file_hash_entry *v;
148
      *e = v = XCNEW (struct file_hash_entry);
149
      v->key = xstrdup (string);
150
    }
151
  return (struct file_hash_entry *) *e;
152 153
}

154 155
static htab_t demangled_table;

Jason Merrill committed
156 157
/* Look up an entry in the demangled name hash table.  */

158
static struct demangled_hash_entry *
159
demangled_hash_lookup (const char *string, int create)
160
{
161
  void **e;
162
  e = htab_find_slot_with_hash (demangled_table, string,
Kazu Hirata committed
163
				(*htab_hash_string) (string),
164 165 166 167 168 169
				create ? INSERT : NO_INSERT);
  if (e == NULL)
    return NULL;
  if (*e == NULL)
    {
      struct demangled_hash_entry *v;
170
      *e = v = XCNEW (struct demangled_hash_entry);
171 172
      v->key = xstrdup (string);
    }
173
  return (struct demangled_hash_entry *) *e;
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
}

/* Stack code.  */

struct symbol_stack_entry
{
  symbol *value;
  struct symbol_stack_entry *next;
};
struct obstack symbol_stack_obstack;
struct symbol_stack_entry *symbol_stack;

struct file_stack_entry
{
  file *value;
  struct file_stack_entry *next;
};
struct obstack file_stack_obstack;
struct file_stack_entry *file_stack;

static void
195
symbol_push (symbol *p)
196
{
197 198
  struct symbol_stack_entry *ep
    = XOBNEW (&symbol_stack_obstack, struct symbol_stack_entry);
199 200 201 202 203 204
  ep->value = p;
  ep->next = symbol_stack;
  symbol_stack = ep;
}

static symbol *
205
symbol_pop (void)
206 207 208 209 210 211 212 213 214 215 216 217
{
  struct symbol_stack_entry *ep = symbol_stack;
  symbol *p;
  if (ep == NULL)
    return NULL;
  p = ep->value;
  symbol_stack = ep->next;
  obstack_free (&symbol_stack_obstack, ep);
  return p;
}

static void
218
file_push (file *p)
219 220 221 222 223 224
{
  struct file_stack_entry *ep;

  if (p->tweaking)
    return;

225
  ep = XOBNEW (&file_stack_obstack, struct file_stack_entry);
226 227 228 229 230 231 232
  ep->value = p;
  ep->next = file_stack;
  file_stack = ep;
  p->tweaking = 1;
}

static file *
233
file_pop (void)
234 235 236 237 238 239 240 241 242 243 244 245 246 247
{
  struct file_stack_entry *ep = file_stack;
  file *p;
  if (ep == NULL)
    return NULL;
  p = ep->value;
  file_stack = ep->next;
  obstack_free (&file_stack_obstack, ep);
  p->tweaking = 0;
  return p;
}

/* Other machinery.  */

Jason Merrill committed
248 249
/* Initialize the tlink machinery.  Called from do_tlink.  */

250
static void
251
tlink_init (void)
252
{
253
  const char *p;
254

255 256 257 258 259 260
  symbol_table = htab_create (500, hash_string_hash, hash_string_eq,
			      NULL);
  file_table = htab_create (500, hash_string_hash, hash_string_eq,
			    NULL);
  demangled_table = htab_create (500, hash_string_hash, hash_string_eq,
				 NULL);
261

262 263 264 265 266 267 268 269 270 271 272 273 274 275
  obstack_begin (&symbol_stack_obstack, 0);
  obstack_begin (&file_stack_obstack, 0);

  p = getenv ("TLINK_VERBOSE");
  if (p)
    tlink_verbose = atoi (p);
  else
    {
      tlink_verbose = 1;
      if (vflag)
	tlink_verbose = 2;
      if (debug)
	tlink_verbose = 3;
    }
276

277
  initial_cwd = getpwd ();
278 279 280
}

static int
281 282
tlink_execute (const char *prog, char **argv, const char *outname,
	       const char *errname)
283
{
284 285
  struct pex_obj *pex;

286
  pex = collect_execute (prog, argv, outname, errname, PEX_LAST | PEX_SEARCH);
287
  return collect_wait (prog, pex);
Kazu Hirata committed
288
}
289 290

static char *
291
frob_extension (const char *s, const char *ext)
292
{
293
  const char *p = strrchr (s, '/');
294 295
  if (! p)
    p = s;
296
  p = strrchr (p, '.');
297 298 299 300
  if (! p)
    p = s + strlen (s);

  obstack_grow (&temporary_obstack, s, p - s);
301
  return (char *) obstack_copy0 (&temporary_obstack, ext, strlen (ext));
302 303 304
}

static char *
305
obstack_fgets (FILE *stream, struct obstack *ob)
306 307 308 309 310 311 312
{
  int c;
  while ((c = getc (stream)) != EOF && c != '\n')
    obstack_1grow (ob, c);
  if (obstack_object_size (ob) == 0)
    return NULL;
  obstack_1grow (ob, '\0');
313
  return XOBFINISH (ob, char *);
314 315 316
}

static char *
317
tfgets (FILE *stream)
318 319 320 321 322
{
  return obstack_fgets (stream, &temporary_obstack);
}

static char *
323
pfgets (FILE *stream)
324
{
Geoffrey Keating committed
325
  return xstrdup (tfgets (stream));
326 327 328 329
}

/* Real tlink code.  */

Jason Merrill committed
330 331
/* Subroutine of read_repo_file.  We are reading the repo file for file F,
   which is coming in on STREAM, and the symbol that comes next in STREAM
332
   is offered, chosen or provided if CHOSEN is 0, 1 or 2, respectively.
Jason Merrill committed
333 334 335

   XXX "provided" is unimplemented, both here and in the compiler.  */

336
static void
337
freadsym (FILE *stream, file *f, int chosen)
338 339 340 341
{
  symbol *sym;

  {
342
    const char *name = tfgets (stream);
343 344 345 346 347
    sym = symbol_hash_lookup (name, true);
  }

  if (sym->file == NULL)
    {
Jason Merrill committed
348 349
      /* We didn't have this symbol already, so we choose this file.  */

350 351 352 353 354 355
      symbol_push (sym);
      sym->file = f;
      sym->chosen = chosen;
    }
  else if (chosen)
    {
Jason Merrill committed
356 357
      /* We want this file; cast aside any pretender.  */

358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373
      if (sym->chosen && sym->file != f)
	{
	  if (sym->chosen == 1)
	    file_push (sym->file);
	  else
	    {
	      file_push (f);
	      f = sym->file;
	      chosen = sym->chosen;
	    }
	}
      sym->file = f;
      sym->chosen = chosen;
    }
}

Jason Merrill committed
374 375
/* Read in the repo file denoted by F, and record all its information.  */

376
static void
377
read_repo_file (file *f)
378 379
{
  char c;
380
  FILE *stream = fopen (f->key, "r");
381 382

  if (tlink_verbose >= 2)
383
    fprintf (stderr, _("collect: reading %s\n"), f->key);
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416

  while (fscanf (stream, "%c ", &c) == 1)
    {
      switch (c)
	{
	case 'A':
	  f->args = pfgets (stream);
	  break;
	case 'D':
	  f->dir = pfgets (stream);
	  break;
	case 'M':
	  f->main = pfgets (stream);
	  break;
	case 'P':
	  freadsym (stream, f, 2);
	  break;
	case 'C':
	  freadsym (stream, f, 1);
	  break;
	case 'O':
	  freadsym (stream, f, 0);
	  break;
	}
      obstack_free (&temporary_obstack, temporary_firstobj);
    }
  fclose (stream);
  if (f->args == NULL)
    f->args = getenv ("COLLECT_GCC_OPTIONS");
  if (f->dir == NULL)
    f->dir = ".";
}

Jason Merrill committed
417 418 419 420 421
/* We might want to modify LINE, which is a symbol line from file F.  We do
   this if either we saw an error message referring to the symbol in
   question, or we have already allocated the symbol to another file and
   this one wants to emit it as well.  */

422
static void
423
maybe_tweak (char *line, file *f)
424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439
{
  symbol *sym = symbol_hash_lookup (line + 2, false);

  if ((sym->file == f && sym->tweaking)
      || (sym->file != f && line[0] == 'C'))
    {
      sym->tweaking = 0;
      sym->tweaked = 1;

      if (line[0] == 'O')
	line[0] = 'C';
      else
	line[0] = 'O';
    }
}

Jason Merrill committed
440
/* Update the repo files for each of the object files we have adjusted and
441
   recompile.  */
Jason Merrill committed
442

443
static int
444
recompile_files (void)
445 446 447
{
  file *f;

Kean Johnston committed
448 449
  putenv (xstrdup ("COMPILER_PATH="));
  putenv (xstrdup ("LIBRARY_PATH="));
Kazu Hirata committed
450

451 452
  while ((f = file_pop ()) != NULL)
    {
453 454 455 456
      char *line;
      const char *p, *q;
      char **argv;
      struct obstack arg_stack;
457 458
      FILE *stream = fopen (f->key, "r");
      const char *const outname = frob_extension (f->key, ".rnw");
459 460 461 462 463 464 465 466 467 468 469 470 471 472
      FILE *output = fopen (outname, "w");

      while ((line = tfgets (stream)) != NULL)
	{
	  switch (line[0])
	    {
	    case 'C':
	    case 'O':
	      maybe_tweak (line, f);
	    }
	  fprintf (output, "%s\n", line);
	}
      fclose (stream);
      fclose (output);
473 474 475 476 477 478 479
      /* On Windows "rename" returns -1 and sets ERRNO to EACCESS if
	 the new file name already exists.  Therefore, we explicitly
	 remove the old file first.  */
      if (remove (f->key) == -1)
	fatal_perror ("removing .rpo file");
      if (rename (outname, f->key) == -1)
	fatal_perror ("renaming .rpo file");
480

481 482
      if (!f->args)
	{
483
	  error ("repository file '%s' does not contain command-line "
484 485 486
		 "arguments", f->key);
	  return 0;
	}
487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529

      /* Build a null-terminated argv array suitable for
	 tlink_execute().  Manipulate arguments on the arg_stack while
	 building argv on the temporary_obstack.  */

      obstack_init (&arg_stack);
      obstack_ptr_grow (&temporary_obstack, c_file_name);

      for (p = f->args; *p != '\0'; p = q + 1)
	{
	  /* Arguments are delimited by single-quotes.  Find the
	     opening quote.  */
	  p = strchr (p, '\'');
	  if (!p)
	    goto done;

	  /* Find the closing quote.  */
	  q = strchr (p + 1, '\'');
	  if (!q)
	    goto done;

	  obstack_grow (&arg_stack, p + 1, q - (p + 1));

	  /* Replace '\'' with '.  This is how set_collect_gcc_options
	     encodes a single-quote.  */
	  while (q[1] == '\\' && q[2] == '\'' && q[3] == '\'')
	    {
	      const char *r;

	      r = strchr (q + 4, '\'');
	      if (!r)
		goto done;

	      obstack_grow (&arg_stack, q + 3, r - (q + 3));
	      q = r;
	    }

	  obstack_1grow (&arg_stack, '\0');
	  obstack_ptr_grow (&temporary_obstack, obstack_finish (&arg_stack));
	}
    done:
      obstack_ptr_grow (&temporary_obstack, f->main);
      obstack_ptr_grow (&temporary_obstack, NULL);
530
      argv = XOBFINISH (&temporary_obstack, char **);
531 532

      if (tlink_verbose)
533
	fprintf (stderr, _("collect: recompiling %s\n"), f->main);
534

535
      if (chdir (f->dir) != 0
536
	  || tlink_execute (c_file_name, argv, NULL, NULL) != 0
537
	  || chdir (initial_cwd) != 0)
538 539 540 541
	return 0;

      read_repo_file (f);

542
      obstack_free (&arg_stack, NULL);
543 544 545 546 547
      obstack_free (&temporary_obstack, temporary_firstobj);
    }
  return 1;
}

Jason Merrill committed
548 549 550
/* The first phase of processing: determine which object files have
   .rpo files associated with them, and read in the information.  */

551
static int
552
read_repo_files (char **object_lst)
553 554 555 556 557
{
  char **object = object_lst;

  for (; *object; object++)
    {
558
      const char *p;
559 560
      file *f;

561 562 563 564 565 566
      /* Don't bother trying for ld flags.  */
      if (*object[0] == '-')
	continue;

      p = frob_extension (*object, ".rpo");

567 568 569 570 571 572 573 574 575 576 577 578 579 580
      if (! file_exists (p))
	continue;

      f = file_hash_lookup (p);

      read_repo_file (f);
    }

  if (file_stack != NULL && ! recompile_files ())
    return 0;

  return (symbol_stack != NULL);
}

Jason Merrill committed
581 582
/* Add the demangled forms of any new symbols to the hash table.  */

583
static void
584
demangle_new_symbols (void)
585 586 587 588 589 590
{
  symbol *sym;

  while ((sym = symbol_pop ()) != NULL)
    {
      demangled *dem;
591
      const char *p = cplus_demangle (sym->key, DMGL_PARAMS | DMGL_ANSI);
592 593 594 595 596

      if (! p)
	continue;

      dem = demangled_hash_lookup (p, true);
597
      dem->mangled = sym->key;
598 599 600
    }
}

Jason Merrill committed
601 602 603
/* Step through the output of the linker, in the file named FNAME, and
   adjust the settings for each symbol encountered.  */

604
static int
605
scan_linker_output (const char *fname)
606 607 608
{
  FILE *stream = fopen (fname, "r");
  char *line;
609
  int skip_next_in_line = 0;
610 611 612 613 614 615

  while ((line = tfgets (stream)) != NULL)
    {
      char *p = line, *q;
      symbol *sym;
      int end;
616 617
      int ok = 0;

618 619 620
      /* On darwin9, we might have to skip " in " lines as well.  */
      if (skip_next_in_line
	  && strstr (p, " in "))
Mike Stump committed
621
	  continue;
622
      skip_next_in_line = 0;
Kazu Hirata committed
623

Kazu Hirata committed
624
      while (*p && ISSPACE ((unsigned char) *p))
625 626 627 628 629
	++p;

      if (! *p)
	continue;

Kazu Hirata committed
630
      for (q = p; *q && ! ISSPACE ((unsigned char) *q); ++q)
631 632 633 634 635
	;

      /* Try the first word on the line.  */
      if (*p == '.')
	++p;
636 637
      if (!strncmp (p, USER_LABEL_PREFIX, strlen (USER_LABEL_PREFIX)))
	p += strlen (USER_LABEL_PREFIX);
638 639 640 641 642

      end = ! *q;
      *q = 0;
      sym = symbol_hash_lookup (p, false);

643 644 645
      /* Some SVR4 linkers produce messages like
	 ld: 0711-317 ERROR: Undefined symbol: .g__t3foo1Zi
	 */
Kazu Hirata committed
646
      if (! sym && ! end && strstr (q + 1, "Undefined symbol: "))
647
	{
Kazu Hirata committed
648
	  char *p = strrchr (q + 1, ' ');
649 650 651
	  p++;
	  if (*p == '.')
	    p++;
652 653
	  if (!strncmp (p, USER_LABEL_PREFIX, strlen (USER_LABEL_PREFIX)))
	    p += strlen (USER_LABEL_PREFIX);
654 655 656
	  sym = symbol_hash_lookup (p, false);
	}

657
      if (! sym && ! end)
658
	/* Try a mangled name in quotes.  */
659
	{
660
	  char *oldq = q + 1;
661 662 663
	  demangled *dem = 0;
	  q = 0;

664
	  /* On darwin9, we look for "foo" referenced from:\n\(.* in .*\n\)*  */
665 666 667 668 669
	  if (strcmp (oldq, "referenced from:") == 0)
	    {
	      /* We have to remember that we found a symbol to tweak.  */
	      ok = 1;

670 671
	      /* We actually want to start from the first word on the
		 line.  */
672 673
	      oldq = p;

674 675 676
	      /* Since the format is multiline, we have to skip
		 following lines with " in ".  */
	      skip_next_in_line = 1;
677 678
	    }

679
	  /* First try `GNU style'.  */
680
	  p = strchr (oldq, '`');
681
	  if (p)
682
	    p++, q = strchr (p, '\'');
683
	  /* Then try "double quotes".  */
684 685
	  else if (p = strchr (oldq, '"'), p)
	    p++, q = strchr (p, '"');
686 687 688
	  /* Then try 'single quotes'.  */
	  else if (p = strchr (oldq, '\''), p)
	    p++, q = strchr (p, '\'');
689 690 691 692
	  else {
	    /* Then try entire line.  */
	    q = strchr (oldq, 0);
	    if (q != oldq)
Mike Stump committed
693
	      p = (char *)oldq;
694
	  }
695

696
	  if (p)
697 698 699 700 701 702 703 704 705
	    {
	      /* Don't let the strstr's below see the demangled name; we
		 might get spurious matches.  */
	      p[-1] = '\0';

	      /* powerpc64-linux references .foo when calling function foo.  */
	      if (*p == '.')
		p++;
	    }
706

707 708
	  /* We need to check for certain error keywords here, or we would
	     mistakenly use GNU ld's "In function `foo':" message.  */
709 710
	  if (q && (ok
		    || strstr (oldq, "ndefined")
Jason Merrill committed
711
		    || strstr (oldq, "nresolved")
712
		    || strstr (oldq, "nsatisfied")
713
		    || strstr (oldq, "ultiple")))
714
	    {
715 716 717 718 719
	      *q = 0;
	      dem = demangled_hash_lookup (p, false);
	      if (dem)
		sym = symbol_hash_lookup (dem->mangled, false);
	      else
Kazu Hirata committed
720
		{
721 722 723
		  if (!strncmp (p, USER_LABEL_PREFIX,
				strlen (USER_LABEL_PREFIX)))
		    p += strlen (USER_LABEL_PREFIX);
724 725
		  sym = symbol_hash_lookup (p, false);
		}
726 727 728 729
	    }
	}

      if (sym && sym->tweaked)
730
	{
731
	  error ("'%s' was assigned to '%s', but was not defined "
732 733
		 "during recompilation, or vice versa", 
		 sym->key, sym->file->key);
734 735 736
	  fclose (stream);
	  return 0;
	}
737 738 739
      if (sym && !sym->tweaking)
	{
	  if (tlink_verbose >= 2)
740
	    fprintf (stderr, _("collect: tweaking %s in %s\n"),
741
		     sym->key, sym->file->key);
742 743 744
	  sym->tweaking = 1;
	  file_push (sym->file);
	}
Kazu Hirata committed
745

746 747 748
      obstack_free (&temporary_obstack, temporary_firstobj);
    }

749
  fclose (stream);
750 751 752
  return (file_stack != NULL);
}

Jason Merrill committed
753 754 755 756 757 758 759 760 761
/* Entry point for tlink.  Called from main in collect2.c.

   Iteratively try to provide definitions for all the unresolved symbols
   mentioned in the linker error messages.

   LD_ARGV is an array of arguments for the linker.
   OBJECT_LST is an array of object files that we may be able to recompile
     to provide missing definitions.  Currently ignored.  */

762
void
763
do_tlink (char **ld_argv, char **object_lst ATTRIBUTE_UNUSED)
764
{
765
  int exit = tlink_execute ("ld", ld_argv, ldout, lderrout);
766 767 768 769 770 771 772 773 774 775 776 777 778

  tlink_init ();

  if (exit)
    {
      int i = 0;

      /* Until collect does a better job of figuring out which are object
	 files, assume that everything on the command line could be.  */
      if (read_repo_files (ld_argv))
	while (exit && i++ < MAX_ITERATIONS)
	  {
	    if (tlink_verbose >= 3)
779 780 781 782
	      {
		dump_file (ldout, stdout);
		dump_file (lderrout, stderr);
	      }
783
	    demangle_new_symbols ();
784 785
	    if (! scan_linker_output (ldout)
		&& ! scan_linker_output (lderrout))
786 787 788 789
	      break;
	    if (! recompile_files ())
	      break;
	    if (tlink_verbose)
790
	      fprintf (stderr, _("collect: relinking\n"));
791
	    exit = tlink_execute ("ld", ld_argv, ldout, lderrout);
792 793 794
	  }
    }

795
  dump_file (ldout, stdout);
796
  unlink (ldout);
797 798
  dump_file (lderrout, stderr);
  unlink (lderrout);
799 800 801 802 803 804
  if (exit)
    {
      error ("ld returned %d exit status", exit);
      collect_exit (exit);
    }
}