/* Scan linker error messages for missing template instantiations and provide
them.
- Copyright (C) 1995, 1998 Free Software Foundation, Inc.
+ Copyright (C) 1995, 1998, 1999 Free Software Foundation, Inc.
Contributed by Jason Merrill (jason@cygnus.com).
This file is part of GNU CC.
#include "system.h"
#include "hash.h"
#include "demangle.h"
-#include "toplev.h"
#include "collect2.h"
#define MAX_ITERATIONS 17
#define obstack_chunk_alloc xmalloc
#define obstack_chunk_free free
-/* Defined in collect2.c. */
-extern int vflag, debug;
-extern char *ldout;
-extern char *c_file_name;
-extern struct obstack temporary_obstack;
-extern struct obstack permanent_obstack;
-extern char * temporary_firstobj;
-
/* Defined in the automatically-generated underscore.c. */
extern int prepends_underscore;
static void file_push PARAMS ((file *));
static file * file_pop PARAMS ((void));
static void tlink_init PARAMS ((void));
-static int tlink_execute PARAMS ((char *, char **, char *));
-static char * frob_extension PARAMS ((char *, const char *));
+static int tlink_execute PARAMS ((const char *, char **, const char *));
+static char * frob_extension PARAMS ((const char *, const char *));
static char * obstack_fgets PARAMS ((FILE *, struct obstack *));
static char * tfgets PARAMS ((FILE *));
static char * pfgets PARAMS ((FILE *));
symbol_hash_newfunc (entry, table, string)
struct hash_entry *entry;
struct hash_table *table;
- hash_table_key string;
+ hash_table_key string ATTRIBUTE_UNUSED;
{
struct symbol_hash_entry *ret = (struct symbol_hash_entry *) entry;
if (ret == NULL)
boolean create;
{
return ((struct symbol_hash_entry *)
- hash_lookup (&symbol_table, (hash_table_key) string,
+ hash_lookup (&symbol_table, (const hash_table_key) string,
create, string_copy));
}
file_hash_newfunc (entry, table, string)
struct hash_entry *entry;
struct hash_table *table;
- hash_table_key string;
+ hash_table_key string ATTRIBUTE_UNUSED;
{
struct file_hash_entry *ret = (struct file_hash_entry *) entry;
if (ret == NULL)
const char *string;
{
return ((struct file_hash_entry *)
- hash_lookup (&file_table, (hash_table_key) string, true,
+ hash_lookup (&file_table, (const hash_table_key) string, true,
string_copy));
}
demangled_hash_newfunc (entry, table, string)
struct hash_entry *entry;
struct hash_table *table;
- hash_table_key string;
+ hash_table_key string ATTRIBUTE_UNUSED;
{
struct demangled_hash_entry *ret = (struct demangled_hash_entry *) entry;
if (ret == NULL)
boolean create;
{
return ((struct demangled_hash_entry *)
- hash_lookup (&demangled_table, (hash_table_key) string,
+ hash_lookup (&demangled_table, (const hash_table_key) string,
create, string_copy));
}
\f
static void
tlink_init ()
{
- char *p;
+ const char *p;
hash_table_init (&symbol_table, symbol_hash_newfunc, string_hash,
string_compare);
static int
tlink_execute (prog, argv, redir)
- char *prog;
+ const char *prog;
char **argv;
- char *redir;
+ const char *redir;
{
collect_execute (prog, argv, redir);
return collect_wait (prog);
static char *
frob_extension (s, ext)
- char *s;
+ const char *s;
const char *ext;
{
- char *p = rindex (s, '/');
+ const char *p = rindex (s, '/');
if (! p)
p = s;
p = rindex (p, '.');
symbol *sym;
{
- char *name = tfgets (stream);
+ const char *name = tfgets (stream);
sym = symbol_hash_lookup (name, true);
}
{
char *line, *command;
FILE *stream = fopen ((char*) f->root.key, "r");
- char *outname = frob_extension ((char*) f->root.key, ".rnw");
+ const char *outname = frob_extension ((char*) f->root.key, ".rnw");
FILE *output = fopen (outname, "w");
while ((line = tfgets (stream)) != NULL)
for (; *object; object++)
{
- char *p = frob_extension (*object, ".rpo");
+ const char *p;
file *f;
+ /* Don't bother trying for ld flags. */
+ if (*object[0] == '-')
+ continue;
+
+ p = frob_extension (*object, ".rpo");
+
if (! file_exists (p))
continue;
while ((sym = symbol_pop ()) != NULL)
{
demangled *dem;
- char *p = cplus_demangle ((char*) sym->root.key,
+ const char *p = cplus_demangle ((char*) sym->root.key,
DMGL_PARAMS | DMGL_ANSI);
if (! p)
if (! sym && ! end)
/* Try a mangled name in quotes. */
{
- char *oldq = q+1;
+ const char *oldq = q+1;
demangled *dem = 0;
q = 0;
else if (p = index (oldq, '"'), p)
p++, q = index (p, '"');
- if (q)
+ /* Don't let the strstr's below see the demangled name; we
+ might get spurious matches. */
+ if (p)
+ p[-1] = '\0';
+
+ /* We need to check for certain error keywords here, or we would
+ mistakenly use GNU ld's "In function `foo':" message. */
+ if (q && (strstr (oldq, "ndefined")
+ || strstr (oldq, "nresolved")
+ || strstr (oldq, "ultiple")))
{
*q = 0;
dem = demangled_hash_lookup (p, false);
if (dem)
sym = symbol_hash_lookup (dem->mangled, false);
else
- sym = symbol_hash_lookup (p, false);
+ {
+ if (*p == '_' && prepends_underscore)
+ ++p;
+ sym = symbol_hash_lookup (p, false);
+ }
}
}
void
do_tlink (ld_argv, object_lst)
- char **ld_argv, **object_lst;
+ char **ld_argv, **object_lst ATTRIBUTE_UNUSED;
{
int exit = tlink_execute ("ld", ld_argv, ldout);