]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/tlink.c
Remove trailing white spaces.
[thirdparty/gcc.git] / gcc / tlink.c
CommitLineData
94ca3aab 1/* Scan linker error messages for missing template instantiations and provide
2 them.
3
168de4c5 4 Copyright (C) 1995, 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2007, 2008
60b8c5b3 5 Free Software Foundation, Inc.
94ca3aab 6 Contributed by Jason Merrill (jason@cygnus.com).
7
f12b58b3 8This file is part of GCC.
94ca3aab 9
f12b58b3 10GCC is free software; you can redistribute it and/or modify it under
11the terms of the GNU General Public License as published by the Free
8c4c00c1 12Software Foundation; either version 3, or (at your option) any later
f12b58b3 13version.
94ca3aab 14
f12b58b3 15GCC is distributed in the hope that it will be useful, but WITHOUT ANY
16WARRANTY; without even the implied warranty of MERCHANTABILITY or
17FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18for more details.
94ca3aab 19
20You should have received a copy of the GNU General Public License
8c4c00c1 21along with GCC; see the file COPYING3. If not see
22<http://www.gnu.org/licenses/>. */
94ca3aab 23
94ca3aab 24#include "config.h"
405711de 25#include "system.h"
805e22b2 26#include "coretypes.h"
27#include "tm.h"
6e6e5faa 28#include "intl.h"
1f3233d1 29#include "obstack.h"
30#include "hashtab.h"
94ca3aab 31#include "demangle.h"
1ae13971 32#include "collect2.h"
691f496e 33#include "libiberty.h"
94ca3aab 34
35#define MAX_ITERATIONS 17
36
94ca3aab 37/* Defined in the automatically-generated underscore.c. */
38extern int prepends_underscore;
39
40static int tlink_verbose;
05a7239a 41
691f496e 42static char *initial_cwd;
94ca3aab 43\f
1f3233d1 44/* Hash table boilerplate for working with htab_t. We have hash tables
56e06438 45 for symbol names, file names, and demangled symbols. */
94ca3aab 46
47typedef struct symbol_hash_entry
48{
1f3233d1 49 const char *key;
94ca3aab 50 struct file_hash_entry *file;
51 int chosen;
52 int tweaking;
53 int tweaked;
54} symbol;
55
56typedef struct file_hash_entry
57{
1f3233d1 58 const char *key;
94ca3aab 59 const char *args;
60 const char *dir;
61 const char *main;
62 int tweaking;
63} file;
64
65typedef struct demangled_hash_entry
66{
1f3233d1 67 const char *key;
94ca3aab 68 const char *mangled;
69} demangled;
70
1f3233d1 71/* Hash and comparison functions for these hash tables. */
72
60b8c5b3 73static int hash_string_eq (const void *, const void *);
74static hashval_t hash_string_hash (const void *);
1f3233d1 75
76static int
60b8c5b3 77hash_string_eq (const void *s1_p, const void *s2_p)
1f3233d1 78{
513b1ebe 79 const char *const *s1 = (const char *const *) s1_p;
80 const char *s2 = (const char *) s2_p;
1f3233d1 81 return strcmp (*s1, s2) == 0;
82}
83
84static hashval_t
60b8c5b3 85hash_string_hash (const void *s_p)
1f3233d1 86{
513b1ebe 87 const char *const *s = (const char *const *) s_p;
1f3233d1 88 return (*htab_hash_string) (*s);
89}
90
91static htab_t symbol_table;
94ca3aab 92
60b8c5b3 93static struct symbol_hash_entry * symbol_hash_lookup (const char *, int);
94static struct file_hash_entry * file_hash_lookup (const char *);
95static struct demangled_hash_entry *demangled_hash_lookup (const char *, int);
96static void symbol_push (symbol *);
97static symbol * symbol_pop (void);
98static void file_push (file *);
99static file * file_pop (void);
100static void tlink_init (void);
d6b5203d 101static int tlink_execute (const char *, char **, const char *, const char *);
60b8c5b3 102static char * frob_extension (const char *, const char *);
103static char * obstack_fgets (FILE *, struct obstack *);
104static char * tfgets (FILE *);
105static char * pfgets (FILE *);
106static void freadsym (FILE *, file *, int);
107static void read_repo_file (file *);
108static void maybe_tweak (char *, file *);
109static int recompile_files (void);
110static int read_repo_files (char **);
111static void demangle_new_symbols (void);
112static int scan_linker_output (const char *);
0809af09 113
56e06438 114/* Look up an entry in the symbol hash table. */
115
94ca3aab 116static struct symbol_hash_entry *
60b8c5b3 117symbol_hash_lookup (const char *string, int create)
94ca3aab 118{
b9a7cc69 119 void **e;
1f3233d1 120 e = htab_find_slot_with_hash (symbol_table, string,
513b1ebe 121 (*htab_hash_string) (string),
1f3233d1 122 create ? INSERT : NO_INSERT);
123 if (e == NULL)
124 return NULL;
125 if (*e == NULL)
94ca3aab 126 {
1f3233d1 127 struct symbol_hash_entry *v;
4c36ffe6 128 *e = v = XCNEW (struct symbol_hash_entry);
1f3233d1 129 v->key = xstrdup (string);
94ca3aab 130 }
25a1c410 131 return (struct symbol_hash_entry *) *e;
94ca3aab 132}
133
1f3233d1 134static htab_t file_table;
135
56e06438 136/* Look up an entry in the file hash table. */
137
94ca3aab 138static struct file_hash_entry *
60b8c5b3 139file_hash_lookup (const char *string)
94ca3aab 140{
b9a7cc69 141 void **e;
1f3233d1 142 e = htab_find_slot_with_hash (file_table, string,
513b1ebe 143 (*htab_hash_string) (string),
1f3233d1 144 INSERT);
145 if (*e == NULL)
94ca3aab 146 {
1f3233d1 147 struct file_hash_entry *v;
4c36ffe6 148 *e = v = XCNEW (struct file_hash_entry);
1f3233d1 149 v->key = xstrdup (string);
94ca3aab 150 }
25a1c410 151 return (struct file_hash_entry *) *e;
94ca3aab 152}
153
1f3233d1 154static htab_t demangled_table;
155
56e06438 156/* Look up an entry in the demangled name hash table. */
157
94ca3aab 158static struct demangled_hash_entry *
60b8c5b3 159demangled_hash_lookup (const char *string, int create)
94ca3aab 160{
b9a7cc69 161 void **e;
1f3233d1 162 e = htab_find_slot_with_hash (demangled_table, string,
513b1ebe 163 (*htab_hash_string) (string),
1f3233d1 164 create ? INSERT : NO_INSERT);
165 if (e == NULL)
166 return NULL;
167 if (*e == NULL)
168 {
169 struct demangled_hash_entry *v;
4c36ffe6 170 *e = v = XCNEW (struct demangled_hash_entry);
1f3233d1 171 v->key = xstrdup (string);
172 }
25a1c410 173 return (struct demangled_hash_entry *) *e;
94ca3aab 174}
175\f
176/* Stack code. */
177
178struct symbol_stack_entry
179{
180 symbol *value;
181 struct symbol_stack_entry *next;
182};
183struct obstack symbol_stack_obstack;
184struct symbol_stack_entry *symbol_stack;
185
186struct file_stack_entry
187{
188 file *value;
189 struct file_stack_entry *next;
190};
191struct obstack file_stack_obstack;
192struct file_stack_entry *file_stack;
193
194static void
60b8c5b3 195symbol_push (symbol *p)
94ca3aab 196{
25a1c410 197 struct symbol_stack_entry *ep
198 = XOBNEW (&symbol_stack_obstack, struct symbol_stack_entry);
94ca3aab 199 ep->value = p;
200 ep->next = symbol_stack;
201 symbol_stack = ep;
202}
203
204static symbol *
60b8c5b3 205symbol_pop (void)
94ca3aab 206{
207 struct symbol_stack_entry *ep = symbol_stack;
208 symbol *p;
209 if (ep == NULL)
210 return NULL;
211 p = ep->value;
212 symbol_stack = ep->next;
213 obstack_free (&symbol_stack_obstack, ep);
214 return p;
215}
216
217static void
60b8c5b3 218file_push (file *p)
94ca3aab 219{
220 struct file_stack_entry *ep;
221
222 if (p->tweaking)
223 return;
224
25a1c410 225 ep = XOBNEW (&file_stack_obstack, struct file_stack_entry);
94ca3aab 226 ep->value = p;
227 ep->next = file_stack;
228 file_stack = ep;
229 p->tweaking = 1;
230}
231
232static file *
60b8c5b3 233file_pop (void)
94ca3aab 234{
235 struct file_stack_entry *ep = file_stack;
236 file *p;
237 if (ep == NULL)
238 return NULL;
239 p = ep->value;
240 file_stack = ep->next;
241 obstack_free (&file_stack_obstack, ep);
242 p->tweaking = 0;
243 return p;
244}
245\f
246/* Other machinery. */
247
56e06438 248/* Initialize the tlink machinery. Called from do_tlink. */
249
94ca3aab 250static void
60b8c5b3 251tlink_init (void)
94ca3aab 252{
e504db4a 253 const char *p;
94ca3aab 254
1f3233d1 255 symbol_table = htab_create (500, hash_string_hash, hash_string_eq,
256 NULL);
257 file_table = htab_create (500, hash_string_hash, hash_string_eq,
258 NULL);
259 demangled_table = htab_create (500, hash_string_hash, hash_string_eq,
260 NULL);
60b8c5b3 261
94ca3aab 262 obstack_begin (&symbol_stack_obstack, 0);
263 obstack_begin (&file_stack_obstack, 0);
264
265 p = getenv ("TLINK_VERBOSE");
266 if (p)
267 tlink_verbose = atoi (p);
268 else
269 {
270 tlink_verbose = 1;
271 if (vflag)
272 tlink_verbose = 2;
273 if (debug)
274 tlink_verbose = 3;
275 }
05a7239a 276
691f496e 277 initial_cwd = getpwd ();
94ca3aab 278}
279
280static int
d6b5203d 281tlink_execute (const char *prog, char **argv, const char *outname,
282 const char *errname)
94ca3aab 283{
6e24b140 284 struct pex_obj *pex;
285
7bfefa9d 286 pex = collect_execute (prog, argv, outname, errname, PEX_LAST | PEX_SEARCH);
6e24b140 287 return collect_wait (prog, pex);
40570cc2 288}
94ca3aab 289
290static char *
60b8c5b3 291frob_extension (const char *s, const char *ext)
94ca3aab 292{
78dbff7c 293 const char *p = strrchr (s, '/');
94ca3aab 294 if (! p)
295 p = s;
78dbff7c 296 p = strrchr (p, '.');
94ca3aab 297 if (! p)
298 p = s + strlen (s);
299
300 obstack_grow (&temporary_obstack, s, p - s);
25a1c410 301 return (char *) obstack_copy0 (&temporary_obstack, ext, strlen (ext));
94ca3aab 302}
303
304static char *
60b8c5b3 305obstack_fgets (FILE *stream, struct obstack *ob)
94ca3aab 306{
307 int c;
308 while ((c = getc (stream)) != EOF && c != '\n')
309 obstack_1grow (ob, c);
310 if (obstack_object_size (ob) == 0)
311 return NULL;
312 obstack_1grow (ob, '\0');
4fac984f 313 return XOBFINISH (ob, char *);
94ca3aab 314}
315
316static char *
60b8c5b3 317tfgets (FILE *stream)
94ca3aab 318{
319 return obstack_fgets (stream, &temporary_obstack);
320}
321
322static char *
60b8c5b3 323pfgets (FILE *stream)
94ca3aab 324{
92192583 325 return xstrdup (tfgets (stream));
94ca3aab 326}
327\f
328/* Real tlink code. */
329
56e06438 330/* Subroutine of read_repo_file. We are reading the repo file for file F,
331 which is coming in on STREAM, and the symbol that comes next in STREAM
de132707 332 is offered, chosen or provided if CHOSEN is 0, 1 or 2, respectively.
56e06438 333
334 XXX "provided" is unimplemented, both here and in the compiler. */
335
94ca3aab 336static void
60b8c5b3 337freadsym (FILE *stream, file *f, int chosen)
94ca3aab 338{
339 symbol *sym;
340
341 {
e504db4a 342 const char *name = tfgets (stream);
94ca3aab 343 sym = symbol_hash_lookup (name, true);
344 }
345
346 if (sym->file == NULL)
347 {
56e06438 348 /* We didn't have this symbol already, so we choose this file. */
349
94ca3aab 350 symbol_push (sym);
351 sym->file = f;
352 sym->chosen = chosen;
353 }
354 else if (chosen)
355 {
56e06438 356 /* We want this file; cast aside any pretender. */
357
94ca3aab 358 if (sym->chosen && sym->file != f)
359 {
360 if (sym->chosen == 1)
361 file_push (sym->file);
362 else
363 {
364 file_push (f);
365 f = sym->file;
366 chosen = sym->chosen;
367 }
368 }
369 sym->file = f;
370 sym->chosen = chosen;
371 }
372}
373
56e06438 374/* Read in the repo file denoted by F, and record all its information. */
375
94ca3aab 376static void
60b8c5b3 377read_repo_file (file *f)
94ca3aab 378{
379 char c;
1f3233d1 380 FILE *stream = fopen (f->key, "r");
94ca3aab 381
382 if (tlink_verbose >= 2)
1f3233d1 383 fprintf (stderr, _("collect: reading %s\n"), f->key);
94ca3aab 384
385 while (fscanf (stream, "%c ", &c) == 1)
386 {
387 switch (c)
388 {
389 case 'A':
390 f->args = pfgets (stream);
391 break;
392 case 'D':
393 f->dir = pfgets (stream);
394 break;
395 case 'M':
396 f->main = pfgets (stream);
397 break;
398 case 'P':
399 freadsym (stream, f, 2);
400 break;
401 case 'C':
402 freadsym (stream, f, 1);
403 break;
404 case 'O':
405 freadsym (stream, f, 0);
406 break;
407 }
408 obstack_free (&temporary_obstack, temporary_firstobj);
409 }
410 fclose (stream);
411 if (f->args == NULL)
412 f->args = getenv ("COLLECT_GCC_OPTIONS");
413 if (f->dir == NULL)
414 f->dir = ".";
415}
416
56e06438 417/* We might want to modify LINE, which is a symbol line from file F. We do
418 this if either we saw an error message referring to the symbol in
419 question, or we have already allocated the symbol to another file and
420 this one wants to emit it as well. */
421
94ca3aab 422static void
60b8c5b3 423maybe_tweak (char *line, file *f)
94ca3aab 424{
425 symbol *sym = symbol_hash_lookup (line + 2, false);
426
427 if ((sym->file == f && sym->tweaking)
428 || (sym->file != f && line[0] == 'C'))
429 {
430 sym->tweaking = 0;
431 sym->tweaked = 1;
432
433 if (line[0] == 'O')
434 line[0] = 'C';
435 else
436 line[0] = 'O';
437 }
438}
439
56e06438 440/* Update the repo files for each of the object files we have adjusted and
05a7239a 441 recompile. */
56e06438 442
94ca3aab 443static int
60b8c5b3 444recompile_files (void)
94ca3aab 445{
446 file *f;
447
ce75e2bb 448 putenv (xstrdup ("COMPILER_PATH="));
449 putenv (xstrdup ("LIBRARY_PATH="));
40570cc2 450
94ca3aab 451 while ((f = file_pop ()) != NULL)
452 {
05a7239a 453 char *line;
454 const char *p, *q;
455 char **argv;
456 struct obstack arg_stack;
1f3233d1 457 FILE *stream = fopen (f->key, "r");
458 const char *const outname = frob_extension (f->key, ".rnw");
94ca3aab 459 FILE *output = fopen (outname, "w");
460
461 while ((line = tfgets (stream)) != NULL)
462 {
463 switch (line[0])
464 {
465 case 'C':
466 case 'O':
467 maybe_tweak (line, f);
468 }
469 fprintf (output, "%s\n", line);
470 }
471 fclose (stream);
472 fclose (output);
e39224c2 473 /* On Windows "rename" returns -1 and sets ERRNO to EACCESS if
474 the new file name already exists. Therefore, we explicitly
475 remove the old file first. */
476 if (remove (f->key) == -1)
477 fatal_perror ("removing .rpo file");
478 if (rename (outname, f->key) == -1)
479 fatal_perror ("renaming .rpo file");
94ca3aab 480
caa6fdce 481 if (!f->args)
482 {
1e5fcbe2 483 error ("repository file '%s' does not contain command-line "
caa6fdce 484 "arguments", f->key);
485 return 0;
486 }
05a7239a 487
488 /* Build a null-terminated argv array suitable for
489 tlink_execute(). Manipulate arguments on the arg_stack while
490 building argv on the temporary_obstack. */
491
492 obstack_init (&arg_stack);
493 obstack_ptr_grow (&temporary_obstack, c_file_name);
494
495 for (p = f->args; *p != '\0'; p = q + 1)
496 {
497 /* Arguments are delimited by single-quotes. Find the
498 opening quote. */
499 p = strchr (p, '\'');
500 if (!p)
501 goto done;
502
503 /* Find the closing quote. */
504 q = strchr (p + 1, '\'');
505 if (!q)
506 goto done;
507
508 obstack_grow (&arg_stack, p + 1, q - (p + 1));
509
510 /* Replace '\'' with '. This is how set_collect_gcc_options
511 encodes a single-quote. */
512 while (q[1] == '\\' && q[2] == '\'' && q[3] == '\'')
513 {
514 const char *r;
515
516 r = strchr (q + 4, '\'');
517 if (!r)
518 goto done;
519
520 obstack_grow (&arg_stack, q + 3, r - (q + 3));
521 q = r;
522 }
523
524 obstack_1grow (&arg_stack, '\0');
525 obstack_ptr_grow (&temporary_obstack, obstack_finish (&arg_stack));
526 }
527 done:
528 obstack_ptr_grow (&temporary_obstack, f->main);
529 obstack_ptr_grow (&temporary_obstack, NULL);
4fac984f 530 argv = XOBFINISH (&temporary_obstack, char **);
94ca3aab 531
532 if (tlink_verbose)
a4db0a1d 533 fprintf (stderr, _("collect: recompiling %s\n"), f->main);
94ca3aab 534
05a7239a 535 if (chdir (f->dir) != 0
d6b5203d 536 || tlink_execute (c_file_name, argv, NULL, NULL) != 0
05a7239a 537 || chdir (initial_cwd) != 0)
94ca3aab 538 return 0;
539
540 read_repo_file (f);
541
05a7239a 542 obstack_free (&arg_stack, NULL);
94ca3aab 543 obstack_free (&temporary_obstack, temporary_firstobj);
544 }
545 return 1;
546}
547
56e06438 548/* The first phase of processing: determine which object files have
549 .rpo files associated with them, and read in the information. */
550
94ca3aab 551static int
60b8c5b3 552read_repo_files (char **object_lst)
94ca3aab 553{
554 char **object = object_lst;
555
556 for (; *object; object++)
557 {
d823001a 558 const char *p;
94ca3aab 559 file *f;
560
d823001a 561 /* Don't bother trying for ld flags. */
562 if (*object[0] == '-')
563 continue;
564
565 p = frob_extension (*object, ".rpo");
566
94ca3aab 567 if (! file_exists (p))
568 continue;
569
570 f = file_hash_lookup (p);
571
572 read_repo_file (f);
573 }
574
575 if (file_stack != NULL && ! recompile_files ())
576 return 0;
577
578 return (symbol_stack != NULL);
579}
580
56e06438 581/* Add the demangled forms of any new symbols to the hash table. */
582
94ca3aab 583static void
60b8c5b3 584demangle_new_symbols (void)
94ca3aab 585{
586 symbol *sym;
587
588 while ((sym = symbol_pop ()) != NULL)
589 {
590 demangled *dem;
1f3233d1 591 const char *p = cplus_demangle (sym->key, DMGL_PARAMS | DMGL_ANSI);
94ca3aab 592
593 if (! p)
594 continue;
595
596 dem = demangled_hash_lookup (p, true);
1f3233d1 597 dem->mangled = sym->key;
94ca3aab 598 }
599}
600
56e06438 601/* Step through the output of the linker, in the file named FNAME, and
602 adjust the settings for each symbol encountered. */
603
94ca3aab 604static int
60b8c5b3 605scan_linker_output (const char *fname)
94ca3aab 606{
607 FILE *stream = fopen (fname, "r");
608 char *line;
d11c2189 609 int skip_next_in_line = 0;
94ca3aab 610
611 while ((line = tfgets (stream)) != NULL)
612 {
613 char *p = line, *q;
614 symbol *sym;
615 int end;
f1148292 616 int ok = 0;
617
d11c2189 618 /* On darwin9, we might have to skip " in " lines as well. */
619 if (skip_next_in_line
620 && strstr (p, " in "))
cd79e6c7 621 continue;
d11c2189 622 skip_next_in_line = 0;
40570cc2 623
513b1ebe 624 while (*p && ISSPACE ((unsigned char) *p))
94ca3aab 625 ++p;
626
627 if (! *p)
628 continue;
629
513b1ebe 630 for (q = p; *q && ! ISSPACE ((unsigned char) *q); ++q)
94ca3aab 631 ;
632
633 /* Try the first word on the line. */
634 if (*p == '.')
635 ++p;
65e49ff1 636 if (!strncmp (p, USER_LABEL_PREFIX, strlen (USER_LABEL_PREFIX)))
637 p += strlen (USER_LABEL_PREFIX);
94ca3aab 638
639 end = ! *q;
640 *q = 0;
641 sym = symbol_hash_lookup (p, false);
642
7234ad38 643 /* Some SVR4 linkers produce messages like
644 ld: 0711-317 ERROR: Undefined symbol: .g__t3foo1Zi
645 */
513b1ebe 646 if (! sym && ! end && strstr (q + 1, "Undefined symbol: "))
7234ad38 647 {
513b1ebe 648 char *p = strrchr (q + 1, ' ');
7234ad38 649 p++;
650 if (*p == '.')
651 p++;
65e49ff1 652 if (!strncmp (p, USER_LABEL_PREFIX, strlen (USER_LABEL_PREFIX)))
653 p += strlen (USER_LABEL_PREFIX);
7234ad38 654 sym = symbol_hash_lookup (p, false);
655 }
656
94ca3aab 657 if (! sym && ! end)
bd855dab 658 /* Try a mangled name in quotes. */
94ca3aab 659 {
dea3189b 660 char *oldq = q + 1;
94ca3aab 661 demangled *dem = 0;
94ca3aab 662 q = 0;
663
d11c2189 664 /* On darwin9, we look for "foo" referenced from:\n\(.* in .*\n\)* */
f1148292 665 if (strcmp (oldq, "referenced from:") == 0)
666 {
667 /* We have to remember that we found a symbol to tweak. */
668 ok = 1;
669
d11c2189 670 /* We actually want to start from the first word on the
671 line. */
f1148292 672 oldq = p;
673
d11c2189 674 /* Since the format is multiline, we have to skip
675 following lines with " in ". */
676 skip_next_in_line = 1;
f1148292 677 }
678
bd855dab 679 /* First try `GNU style'. */
78dbff7c 680 p = strchr (oldq, '`');
bd855dab 681 if (p)
78dbff7c 682 p++, q = strchr (p, '\'');
bd855dab 683 /* Then try "double quotes". */
78dbff7c 684 else if (p = strchr (oldq, '"'), p)
685 p++, q = strchr (p, '"');
168de4c5 686 /* Then try 'single quotes'. */
687 else if (p = strchr (oldq, '\''), p)
688 p++, q = strchr (p, '\'');
9511f117 689 else {
690 /* Then try entire line. */
691 q = strchr (oldq, 0);
692 if (q != oldq)
59fbfc4a 693 p = (char *)oldq;
9511f117 694 }
94ca3aab 695
53bdb86c 696 if (p)
0beb646c 697 {
698 /* Don't let the strstr's below see the demangled name; we
699 might get spurious matches. */
700 p[-1] = '\0';
701
702 /* powerpc64-linux references .foo when calling function foo. */
703 if (*p == '.')
704 p++;
705 }
53bdb86c 706
b51e1cf8 707 /* We need to check for certain error keywords here, or we would
708 mistakenly use GNU ld's "In function `foo':" message. */
f1148292 709 if (q && (ok
710 || strstr (oldq, "ndefined")
13d09b16 711 || strstr (oldq, "nresolved")
036a9f3c 712 || strstr (oldq, "nsatisfied")
b51e1cf8 713 || strstr (oldq, "ultiple")))
94ca3aab 714 {
bd855dab 715 *q = 0;
716 dem = demangled_hash_lookup (p, false);
717 if (dem)
718 sym = symbol_hash_lookup (dem->mangled, false);
719 else
40570cc2 720 {
65e49ff1 721 if (!strncmp (p, USER_LABEL_PREFIX,
722 strlen (USER_LABEL_PREFIX)))
723 p += strlen (USER_LABEL_PREFIX);
01e2144f 724 sym = symbol_hash_lookup (p, false);
725 }
94ca3aab 726 }
94ca3aab 727 }
728
729 if (sym && sym->tweaked)
30c1e454 730 {
1e5fcbe2 731 error ("'%s' was assigned to '%s', but was not defined "
48e1416a 732 "during recompilation, or vice versa",
caa6fdce 733 sym->key, sym->file->key);
30c1e454 734 fclose (stream);
735 return 0;
736 }
94ca3aab 737 if (sym && !sym->tweaking)
738 {
739 if (tlink_verbose >= 2)
a4db0a1d 740 fprintf (stderr, _("collect: tweaking %s in %s\n"),
1f3233d1 741 sym->key, sym->file->key);
94ca3aab 742 sym->tweaking = 1;
743 file_push (sym->file);
744 }
40570cc2 745
94ca3aab 746 obstack_free (&temporary_obstack, temporary_firstobj);
747 }
748
30c1e454 749 fclose (stream);
94ca3aab 750 return (file_stack != NULL);
751}
752
56e06438 753/* Entry point for tlink. Called from main in collect2.c.
754
755 Iteratively try to provide definitions for all the unresolved symbols
756 mentioned in the linker error messages.
757
758 LD_ARGV is an array of arguments for the linker.
759 OBJECT_LST is an array of object files that we may be able to recompile
760 to provide missing definitions. Currently ignored. */
761
94ca3aab 762void
60b8c5b3 763do_tlink (char **ld_argv, char **object_lst ATTRIBUTE_UNUSED)
94ca3aab 764{
d6b5203d 765 int exit = tlink_execute ("ld", ld_argv, ldout, lderrout);
94ca3aab 766
767 tlink_init ();
768
769 if (exit)
770 {
771 int i = 0;
772
773 /* Until collect does a better job of figuring out which are object
774 files, assume that everything on the command line could be. */
775 if (read_repo_files (ld_argv))
776 while (exit && i++ < MAX_ITERATIONS)
777 {
778 if (tlink_verbose >= 3)
d6b5203d 779 {
780 dump_file (ldout, stdout);
781 dump_file (lderrout, stderr);
782 }
94ca3aab 783 demangle_new_symbols ();
d6b5203d 784 if (! scan_linker_output (ldout)
785 && ! scan_linker_output (lderrout))
94ca3aab 786 break;
787 if (! recompile_files ())
788 break;
789 if (tlink_verbose)
a4db0a1d 790 fprintf (stderr, _("collect: relinking\n"));
d6b5203d 791 exit = tlink_execute ("ld", ld_argv, ldout, lderrout);
94ca3aab 792 }
793 }
794
d6b5203d 795 dump_file (ldout, stdout);
94ca3aab 796 unlink (ldout);
d6b5203d 797 dump_file (lderrout, stderr);
798 unlink (lderrout);
94ca3aab 799 if (exit)
800 {
801 error ("ld returned %d exit status", exit);
802 collect_exit (exit);
803 }
804}