OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gcc-4.2.2/] [gcc/] [tlink.c] - Diff between revs 154 and 816

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 154 Rev 816
/* Scan linker error messages for missing template instantiations and provide
/* Scan linker error messages for missing template instantiations and provide
   them.
   them.
 
 
   Copyright (C) 1995, 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2007
   Copyright (C) 1995, 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2007
   Free Software Foundation, Inc.
   Free Software Foundation, Inc.
   Contributed by Jason Merrill (jason@cygnus.com).
   Contributed by Jason Merrill (jason@cygnus.com).
 
 
This file is part of GCC.
This file is part of GCC.
 
 
GCC is free software; you can redistribute it and/or modify it under
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
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3, or (at your option) any later
Software Foundation; either version 3, or (at your option) any later
version.
version.
 
 
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
for more details.
for more details.
 
 
You should have received a copy of the GNU General Public License
You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3.  If not see
along with GCC; see the file COPYING3.  If not see
<http://www.gnu.org/licenses/>.  */
<http://www.gnu.org/licenses/>.  */
 
 
#include "config.h"
#include "config.h"
#include "system.h"
#include "system.h"
#include "coretypes.h"
#include "coretypes.h"
#include "tm.h"
#include "tm.h"
#include "intl.h"
#include "intl.h"
#include "obstack.h"
#include "obstack.h"
#include "hashtab.h"
#include "hashtab.h"
#include "demangle.h"
#include "demangle.h"
#include "collect2.h"
#include "collect2.h"
 
 
#define MAX_ITERATIONS 17
#define MAX_ITERATIONS 17
 
 
/* Defined in the automatically-generated underscore.c.  */
/* Defined in the automatically-generated underscore.c.  */
extern int prepends_underscore;
extern int prepends_underscore;
 
 
static int tlink_verbose;
static int tlink_verbose;
 
 
static char initial_cwd[MAXPATHLEN + 1];
static char initial_cwd[MAXPATHLEN + 1];


/* Hash table boilerplate for working with htab_t.  We have hash tables
/* Hash table boilerplate for working with htab_t.  We have hash tables
   for symbol names, file names, and demangled symbols.  */
   for symbol names, file names, and demangled symbols.  */
 
 
typedef struct symbol_hash_entry
typedef struct symbol_hash_entry
{
{
  const char *key;
  const char *key;
  struct file_hash_entry *file;
  struct file_hash_entry *file;
  int chosen;
  int chosen;
  int tweaking;
  int tweaking;
  int tweaked;
  int tweaked;
} symbol;
} symbol;
 
 
typedef struct file_hash_entry
typedef struct file_hash_entry
{
{
  const char *key;
  const char *key;
  const char *args;
  const char *args;
  const char *dir;
  const char *dir;
  const char *main;
  const char *main;
  int tweaking;
  int tweaking;
} file;
} file;
 
 
typedef struct demangled_hash_entry
typedef struct demangled_hash_entry
{
{
  const char *key;
  const char *key;
  const char *mangled;
  const char *mangled;
} demangled;
} demangled;
 
 
/* Hash and comparison functions for these hash tables.  */
/* Hash and comparison functions for these hash tables.  */
 
 
static int hash_string_eq (const void *, const void *);
static int hash_string_eq (const void *, const void *);
static hashval_t hash_string_hash (const void *);
static hashval_t hash_string_hash (const void *);
 
 
static int
static int
hash_string_eq (const void *s1_p, const void *s2_p)
hash_string_eq (const void *s1_p, const void *s2_p)
{
{
  const char *const *s1 = (const char *const *) s1_p;
  const char *const *s1 = (const char *const *) s1_p;
  const char *s2 = (const char *) s2_p;
  const char *s2 = (const char *) s2_p;
  return strcmp (*s1, s2) == 0;
  return strcmp (*s1, s2) == 0;
}
}
 
 
static hashval_t
static hashval_t
hash_string_hash (const void *s_p)
hash_string_hash (const void *s_p)
{
{
  const char *const *s = (const char *const *) s_p;
  const char *const *s = (const char *const *) s_p;
  return (*htab_hash_string) (*s);
  return (*htab_hash_string) (*s);
}
}
 
 
static htab_t symbol_table;
static htab_t symbol_table;
 
 
static struct symbol_hash_entry * symbol_hash_lookup (const char *, int);
static struct symbol_hash_entry * symbol_hash_lookup (const char *, int);
static struct file_hash_entry * file_hash_lookup (const char *);
static struct file_hash_entry * file_hash_lookup (const char *);
static struct demangled_hash_entry *demangled_hash_lookup (const char *, int);
static struct demangled_hash_entry *demangled_hash_lookup (const char *, int);
static void symbol_push (symbol *);
static void symbol_push (symbol *);
static symbol * symbol_pop (void);
static symbol * symbol_pop (void);
static void file_push (file *);
static void file_push (file *);
static file * file_pop (void);
static file * file_pop (void);
static void tlink_init (void);
static void tlink_init (void);
static int tlink_execute (const char *, char **, const char *, const char *);
static int tlink_execute (const char *, char **, const char *, const char *);
static char * frob_extension (const char *, const char *);
static char * frob_extension (const char *, const char *);
static char * obstack_fgets (FILE *, struct obstack *);
static char * obstack_fgets (FILE *, struct obstack *);
static char * tfgets (FILE *);
static char * tfgets (FILE *);
static char * pfgets (FILE *);
static char * pfgets (FILE *);
static void freadsym (FILE *, file *, int);
static void freadsym (FILE *, file *, int);
static void read_repo_file (file *);
static void read_repo_file (file *);
static void maybe_tweak (char *, file *);
static void maybe_tweak (char *, file *);
static int recompile_files (void);
static int recompile_files (void);
static int read_repo_files (char **);
static int read_repo_files (char **);
static void demangle_new_symbols (void);
static void demangle_new_symbols (void);
static int scan_linker_output (const char *);
static int scan_linker_output (const char *);
 
 
/* Look up an entry in the symbol hash table.  */
/* Look up an entry in the symbol hash table.  */
 
 
static struct symbol_hash_entry *
static struct symbol_hash_entry *
symbol_hash_lookup (const char *string, int create)
symbol_hash_lookup (const char *string, int create)
{
{
  void **e;
  void **e;
  e = htab_find_slot_with_hash (symbol_table, string,
  e = htab_find_slot_with_hash (symbol_table, string,
                                (*htab_hash_string) (string),
                                (*htab_hash_string) (string),
                                create ? INSERT : NO_INSERT);
                                create ? INSERT : NO_INSERT);
  if (e == NULL)
  if (e == NULL)
    return NULL;
    return NULL;
  if (*e == NULL)
  if (*e == NULL)
    {
    {
      struct symbol_hash_entry *v;
      struct symbol_hash_entry *v;
      *e = v = XCNEW (struct symbol_hash_entry);
      *e = v = XCNEW (struct symbol_hash_entry);
      v->key = xstrdup (string);
      v->key = xstrdup (string);
    }
    }
  return *e;
  return *e;
}
}
 
 
static htab_t file_table;
static htab_t file_table;
 
 
/* Look up an entry in the file hash table.  */
/* Look up an entry in the file hash table.  */
 
 
static struct file_hash_entry *
static struct file_hash_entry *
file_hash_lookup (const char *string)
file_hash_lookup (const char *string)
{
{
  void **e;
  void **e;
  e = htab_find_slot_with_hash (file_table, string,
  e = htab_find_slot_with_hash (file_table, string,
                                (*htab_hash_string) (string),
                                (*htab_hash_string) (string),
                                INSERT);
                                INSERT);
  if (*e == NULL)
  if (*e == NULL)
    {
    {
      struct file_hash_entry *v;
      struct file_hash_entry *v;
      *e = v = XCNEW (struct file_hash_entry);
      *e = v = XCNEW (struct file_hash_entry);
      v->key = xstrdup (string);
      v->key = xstrdup (string);
    }
    }
  return *e;
  return *e;
}
}
 
 
static htab_t demangled_table;
static htab_t demangled_table;
 
 
/* Look up an entry in the demangled name hash table.  */
/* Look up an entry in the demangled name hash table.  */
 
 
static struct demangled_hash_entry *
static struct demangled_hash_entry *
demangled_hash_lookup (const char *string, int create)
demangled_hash_lookup (const char *string, int create)
{
{
  void **e;
  void **e;
  e = htab_find_slot_with_hash (demangled_table, string,
  e = htab_find_slot_with_hash (demangled_table, string,
                                (*htab_hash_string) (string),
                                (*htab_hash_string) (string),
                                create ? INSERT : NO_INSERT);
                                create ? INSERT : NO_INSERT);
  if (e == NULL)
  if (e == NULL)
    return NULL;
    return NULL;
  if (*e == NULL)
  if (*e == NULL)
    {
    {
      struct demangled_hash_entry *v;
      struct demangled_hash_entry *v;
      *e = v = XCNEW (struct demangled_hash_entry);
      *e = v = XCNEW (struct demangled_hash_entry);
      v->key = xstrdup (string);
      v->key = xstrdup (string);
    }
    }
  return *e;
  return *e;
}
}


/* Stack code.  */
/* Stack code.  */
 
 
struct symbol_stack_entry
struct symbol_stack_entry
{
{
  symbol *value;
  symbol *value;
  struct symbol_stack_entry *next;
  struct symbol_stack_entry *next;
};
};
struct obstack symbol_stack_obstack;
struct obstack symbol_stack_obstack;
struct symbol_stack_entry *symbol_stack;
struct symbol_stack_entry *symbol_stack;
 
 
struct file_stack_entry
struct file_stack_entry
{
{
  file *value;
  file *value;
  struct file_stack_entry *next;
  struct file_stack_entry *next;
};
};
struct obstack file_stack_obstack;
struct obstack file_stack_obstack;
struct file_stack_entry *file_stack;
struct file_stack_entry *file_stack;
 
 
static void
static void
symbol_push (symbol *p)
symbol_push (symbol *p)
{
{
  struct symbol_stack_entry *ep = obstack_alloc
  struct symbol_stack_entry *ep = obstack_alloc
    (&symbol_stack_obstack, sizeof (struct symbol_stack_entry));
    (&symbol_stack_obstack, sizeof (struct symbol_stack_entry));
  ep->value = p;
  ep->value = p;
  ep->next = symbol_stack;
  ep->next = symbol_stack;
  symbol_stack = ep;
  symbol_stack = ep;
}
}
 
 
static symbol *
static symbol *
symbol_pop (void)
symbol_pop (void)
{
{
  struct symbol_stack_entry *ep = symbol_stack;
  struct symbol_stack_entry *ep = symbol_stack;
  symbol *p;
  symbol *p;
  if (ep == NULL)
  if (ep == NULL)
    return NULL;
    return NULL;
  p = ep->value;
  p = ep->value;
  symbol_stack = ep->next;
  symbol_stack = ep->next;
  obstack_free (&symbol_stack_obstack, ep);
  obstack_free (&symbol_stack_obstack, ep);
  return p;
  return p;
}
}
 
 
static void
static void
file_push (file *p)
file_push (file *p)
{
{
  struct file_stack_entry *ep;
  struct file_stack_entry *ep;
 
 
  if (p->tweaking)
  if (p->tweaking)
    return;
    return;
 
 
  ep = obstack_alloc
  ep = obstack_alloc
    (&file_stack_obstack, sizeof (struct file_stack_entry));
    (&file_stack_obstack, sizeof (struct file_stack_entry));
  ep->value = p;
  ep->value = p;
  ep->next = file_stack;
  ep->next = file_stack;
  file_stack = ep;
  file_stack = ep;
  p->tweaking = 1;
  p->tweaking = 1;
}
}
 
 
static file *
static file *
file_pop (void)
file_pop (void)
{
{
  struct file_stack_entry *ep = file_stack;
  struct file_stack_entry *ep = file_stack;
  file *p;
  file *p;
  if (ep == NULL)
  if (ep == NULL)
    return NULL;
    return NULL;
  p = ep->value;
  p = ep->value;
  file_stack = ep->next;
  file_stack = ep->next;
  obstack_free (&file_stack_obstack, ep);
  obstack_free (&file_stack_obstack, ep);
  p->tweaking = 0;
  p->tweaking = 0;
  return p;
  return p;
}
}


/* Other machinery.  */
/* Other machinery.  */
 
 
/* Initialize the tlink machinery.  Called from do_tlink.  */
/* Initialize the tlink machinery.  Called from do_tlink.  */
 
 
static void
static void
tlink_init (void)
tlink_init (void)
{
{
  const char *p;
  const char *p;
 
 
  symbol_table = htab_create (500, hash_string_hash, hash_string_eq,
  symbol_table = htab_create (500, hash_string_hash, hash_string_eq,
                              NULL);
                              NULL);
  file_table = htab_create (500, hash_string_hash, hash_string_eq,
  file_table = htab_create (500, hash_string_hash, hash_string_eq,
                            NULL);
                            NULL);
  demangled_table = htab_create (500, hash_string_hash, hash_string_eq,
  demangled_table = htab_create (500, hash_string_hash, hash_string_eq,
                                 NULL);
                                 NULL);
 
 
  obstack_begin (&symbol_stack_obstack, 0);
  obstack_begin (&symbol_stack_obstack, 0);
  obstack_begin (&file_stack_obstack, 0);
  obstack_begin (&file_stack_obstack, 0);
 
 
  p = getenv ("TLINK_VERBOSE");
  p = getenv ("TLINK_VERBOSE");
  if (p)
  if (p)
    tlink_verbose = atoi (p);
    tlink_verbose = atoi (p);
  else
  else
    {
    {
      tlink_verbose = 1;
      tlink_verbose = 1;
      if (vflag)
      if (vflag)
        tlink_verbose = 2;
        tlink_verbose = 2;
      if (debug)
      if (debug)
        tlink_verbose = 3;
        tlink_verbose = 3;
    }
    }
 
 
  getcwd (initial_cwd, sizeof (initial_cwd));
  getcwd (initial_cwd, sizeof (initial_cwd));
}
}
 
 
static int
static int
tlink_execute (const char *prog, char **argv, const char *outname,
tlink_execute (const char *prog, char **argv, const char *outname,
               const char *errname)
               const char *errname)
{
{
  struct pex_obj *pex;
  struct pex_obj *pex;
 
 
  pex = collect_execute (prog, argv, outname, errname);
  pex = collect_execute (prog, argv, outname, errname);
  return collect_wait (prog, pex);
  return collect_wait (prog, pex);
}
}
 
 
static char *
static char *
frob_extension (const char *s, const char *ext)
frob_extension (const char *s, const char *ext)
{
{
  const char *p = strrchr (s, '/');
  const char *p = strrchr (s, '/');
  if (! p)
  if (! p)
    p = s;
    p = s;
  p = strrchr (p, '.');
  p = strrchr (p, '.');
  if (! p)
  if (! p)
    p = s + strlen (s);
    p = s + strlen (s);
 
 
  obstack_grow (&temporary_obstack, s, p - s);
  obstack_grow (&temporary_obstack, s, p - s);
  return obstack_copy0 (&temporary_obstack, ext, strlen (ext));
  return obstack_copy0 (&temporary_obstack, ext, strlen (ext));
}
}
 
 
static char *
static char *
obstack_fgets (FILE *stream, struct obstack *ob)
obstack_fgets (FILE *stream, struct obstack *ob)
{
{
  int c;
  int c;
  while ((c = getc (stream)) != EOF && c != '\n')
  while ((c = getc (stream)) != EOF && c != '\n')
    obstack_1grow (ob, c);
    obstack_1grow (ob, c);
  if (obstack_object_size (ob) == 0)
  if (obstack_object_size (ob) == 0)
    return NULL;
    return NULL;
  obstack_1grow (ob, '\0');
  obstack_1grow (ob, '\0');
  return XOBFINISH (ob, char *);
  return XOBFINISH (ob, char *);
}
}
 
 
static char *
static char *
tfgets (FILE *stream)
tfgets (FILE *stream)
{
{
  return obstack_fgets (stream, &temporary_obstack);
  return obstack_fgets (stream, &temporary_obstack);
}
}
 
 
static char *
static char *
pfgets (FILE *stream)
pfgets (FILE *stream)
{
{
  return xstrdup (tfgets (stream));
  return xstrdup (tfgets (stream));
}
}


/* Real tlink code.  */
/* Real tlink code.  */
 
 
/* Subroutine of read_repo_file.  We are reading the repo file for file F,
/* 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
   which is coming in on STREAM, and the symbol that comes next in STREAM
   is offered, chosen or provided if CHOSEN is 0, 1 or 2, respectively.
   is offered, chosen or provided if CHOSEN is 0, 1 or 2, respectively.
 
 
   XXX "provided" is unimplemented, both here and in the compiler.  */
   XXX "provided" is unimplemented, both here and in the compiler.  */
 
 
static void
static void
freadsym (FILE *stream, file *f, int chosen)
freadsym (FILE *stream, file *f, int chosen)
{
{
  symbol *sym;
  symbol *sym;
 
 
  {
  {
    const char *name = tfgets (stream);
    const char *name = tfgets (stream);
    sym = symbol_hash_lookup (name, true);
    sym = symbol_hash_lookup (name, true);
  }
  }
 
 
  if (sym->file == NULL)
  if (sym->file == NULL)
    {
    {
      /* We didn't have this symbol already, so we choose this file.  */
      /* We didn't have this symbol already, so we choose this file.  */
 
 
      symbol_push (sym);
      symbol_push (sym);
      sym->file = f;
      sym->file = f;
      sym->chosen = chosen;
      sym->chosen = chosen;
    }
    }
  else if (chosen)
  else if (chosen)
    {
    {
      /* We want this file; cast aside any pretender.  */
      /* We want this file; cast aside any pretender.  */
 
 
      if (sym->chosen && sym->file != f)
      if (sym->chosen && sym->file != f)
        {
        {
          if (sym->chosen == 1)
          if (sym->chosen == 1)
            file_push (sym->file);
            file_push (sym->file);
          else
          else
            {
            {
              file_push (f);
              file_push (f);
              f = sym->file;
              f = sym->file;
              chosen = sym->chosen;
              chosen = sym->chosen;
            }
            }
        }
        }
      sym->file = f;
      sym->file = f;
      sym->chosen = chosen;
      sym->chosen = chosen;
    }
    }
}
}
 
 
/* Read in the repo file denoted by F, and record all its information.  */
/* Read in the repo file denoted by F, and record all its information.  */
 
 
static void
static void
read_repo_file (file *f)
read_repo_file (file *f)
{
{
  char c;
  char c;
  FILE *stream = fopen (f->key, "r");
  FILE *stream = fopen (f->key, "r");
 
 
  if (tlink_verbose >= 2)
  if (tlink_verbose >= 2)
    fprintf (stderr, _("collect: reading %s\n"), f->key);
    fprintf (stderr, _("collect: reading %s\n"), f->key);
 
 
  while (fscanf (stream, "%c ", &c) == 1)
  while (fscanf (stream, "%c ", &c) == 1)
    {
    {
      switch (c)
      switch (c)
        {
        {
        case 'A':
        case 'A':
          f->args = pfgets (stream);
          f->args = pfgets (stream);
          break;
          break;
        case 'D':
        case 'D':
          f->dir = pfgets (stream);
          f->dir = pfgets (stream);
          break;
          break;
        case 'M':
        case 'M':
          f->main = pfgets (stream);
          f->main = pfgets (stream);
          break;
          break;
        case 'P':
        case 'P':
          freadsym (stream, f, 2);
          freadsym (stream, f, 2);
          break;
          break;
        case 'C':
        case 'C':
          freadsym (stream, f, 1);
          freadsym (stream, f, 1);
          break;
          break;
        case 'O':
        case 'O':
          freadsym (stream, f, 0);
          freadsym (stream, f, 0);
          break;
          break;
        }
        }
      obstack_free (&temporary_obstack, temporary_firstobj);
      obstack_free (&temporary_obstack, temporary_firstobj);
    }
    }
  fclose (stream);
  fclose (stream);
  if (f->args == NULL)
  if (f->args == NULL)
    f->args = getenv ("COLLECT_GCC_OPTIONS");
    f->args = getenv ("COLLECT_GCC_OPTIONS");
  if (f->dir == NULL)
  if (f->dir == NULL)
    f->dir = ".";
    f->dir = ".";
}
}
 
 
/* We might want to modify LINE, which is a symbol line from file F.  We do
/* 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
   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
   question, or we have already allocated the symbol to another file and
   this one wants to emit it as well.  */
   this one wants to emit it as well.  */
 
 
static void
static void
maybe_tweak (char *line, file *f)
maybe_tweak (char *line, file *f)
{
{
  symbol *sym = symbol_hash_lookup (line + 2, false);
  symbol *sym = symbol_hash_lookup (line + 2, false);
 
 
  if ((sym->file == f && sym->tweaking)
  if ((sym->file == f && sym->tweaking)
      || (sym->file != f && line[0] == 'C'))
      || (sym->file != f && line[0] == 'C'))
    {
    {
      sym->tweaking = 0;
      sym->tweaking = 0;
      sym->tweaked = 1;
      sym->tweaked = 1;
 
 
      if (line[0] == 'O')
      if (line[0] == 'O')
        line[0] = 'C';
        line[0] = 'C';
      else
      else
        line[0] = 'O';
        line[0] = 'O';
    }
    }
}
}
 
 
/* Update the repo files for each of the object files we have adjusted and
/* Update the repo files for each of the object files we have adjusted and
   recompile.  */
   recompile.  */
 
 
static int
static int
recompile_files (void)
recompile_files (void)
{
{
  file *f;
  file *f;
 
 
  putenv (xstrdup ("COMPILER_PATH="));
  putenv (xstrdup ("COMPILER_PATH="));
  putenv (xstrdup ("LIBRARY_PATH="));
  putenv (xstrdup ("LIBRARY_PATH="));
 
 
  while ((f = file_pop ()) != NULL)
  while ((f = file_pop ()) != NULL)
    {
    {
      char *line;
      char *line;
      const char *p, *q;
      const char *p, *q;
      char **argv;
      char **argv;
      struct obstack arg_stack;
      struct obstack arg_stack;
      FILE *stream = fopen (f->key, "r");
      FILE *stream = fopen (f->key, "r");
      const char *const outname = frob_extension (f->key, ".rnw");
      const char *const outname = frob_extension (f->key, ".rnw");
      FILE *output = fopen (outname, "w");
      FILE *output = fopen (outname, "w");
 
 
      while ((line = tfgets (stream)) != NULL)
      while ((line = tfgets (stream)) != NULL)
        {
        {
          switch (line[0])
          switch (line[0])
            {
            {
            case 'C':
            case 'C':
            case 'O':
            case 'O':
              maybe_tweak (line, f);
              maybe_tweak (line, f);
            }
            }
          fprintf (output, "%s\n", line);
          fprintf (output, "%s\n", line);
        }
        }
      fclose (stream);
      fclose (stream);
      fclose (output);
      fclose (output);
      /* On Windows "rename" returns -1 and sets ERRNO to EACCESS if
      /* On Windows "rename" returns -1 and sets ERRNO to EACCESS if
         the new file name already exists.  Therefore, we explicitly
         the new file name already exists.  Therefore, we explicitly
         remove the old file first.  */
         remove the old file first.  */
      if (remove (f->key) == -1)
      if (remove (f->key) == -1)
        fatal_perror ("removing .rpo file");
        fatal_perror ("removing .rpo file");
      if (rename (outname, f->key) == -1)
      if (rename (outname, f->key) == -1)
        fatal_perror ("renaming .rpo file");
        fatal_perror ("renaming .rpo file");
 
 
      if (!f->args)
      if (!f->args)
        {
        {
          error ("repository file '%s' does not contain command-line "
          error ("repository file '%s' does not contain command-line "
                 "arguments", f->key);
                 "arguments", f->key);
          return 0;
          return 0;
        }
        }
 
 
      /* Build a null-terminated argv array suitable for
      /* Build a null-terminated argv array suitable for
         tlink_execute().  Manipulate arguments on the arg_stack while
         tlink_execute().  Manipulate arguments on the arg_stack while
         building argv on the temporary_obstack.  */
         building argv on the temporary_obstack.  */
 
 
      obstack_init (&arg_stack);
      obstack_init (&arg_stack);
      obstack_ptr_grow (&temporary_obstack, c_file_name);
      obstack_ptr_grow (&temporary_obstack, c_file_name);
 
 
      for (p = f->args; *p != '\0'; p = q + 1)
      for (p = f->args; *p != '\0'; p = q + 1)
        {
        {
          /* Arguments are delimited by single-quotes.  Find the
          /* Arguments are delimited by single-quotes.  Find the
             opening quote.  */
             opening quote.  */
          p = strchr (p, '\'');
          p = strchr (p, '\'');
          if (!p)
          if (!p)
            goto done;
            goto done;
 
 
          /* Find the closing quote.  */
          /* Find the closing quote.  */
          q = strchr (p + 1, '\'');
          q = strchr (p + 1, '\'');
          if (!q)
          if (!q)
            goto done;
            goto done;
 
 
          obstack_grow (&arg_stack, p + 1, q - (p + 1));
          obstack_grow (&arg_stack, p + 1, q - (p + 1));
 
 
          /* Replace '\'' with '.  This is how set_collect_gcc_options
          /* Replace '\'' with '.  This is how set_collect_gcc_options
             encodes a single-quote.  */
             encodes a single-quote.  */
          while (q[1] == '\\' && q[2] == '\'' && q[3] == '\'')
          while (q[1] == '\\' && q[2] == '\'' && q[3] == '\'')
            {
            {
              const char *r;
              const char *r;
 
 
              r = strchr (q + 4, '\'');
              r = strchr (q + 4, '\'');
              if (!r)
              if (!r)
                goto done;
                goto done;
 
 
              obstack_grow (&arg_stack, q + 3, r - (q + 3));
              obstack_grow (&arg_stack, q + 3, r - (q + 3));
              q = r;
              q = r;
            }
            }
 
 
          obstack_1grow (&arg_stack, '\0');
          obstack_1grow (&arg_stack, '\0');
          obstack_ptr_grow (&temporary_obstack, obstack_finish (&arg_stack));
          obstack_ptr_grow (&temporary_obstack, obstack_finish (&arg_stack));
        }
        }
    done:
    done:
      obstack_ptr_grow (&temporary_obstack, f->main);
      obstack_ptr_grow (&temporary_obstack, f->main);
      obstack_ptr_grow (&temporary_obstack, NULL);
      obstack_ptr_grow (&temporary_obstack, NULL);
      argv = XOBFINISH (&temporary_obstack, char **);
      argv = XOBFINISH (&temporary_obstack, char **);
 
 
      if (tlink_verbose)
      if (tlink_verbose)
        fprintf (stderr, _("collect: recompiling %s\n"), f->main);
        fprintf (stderr, _("collect: recompiling %s\n"), f->main);
 
 
      if (chdir (f->dir) != 0
      if (chdir (f->dir) != 0
          || tlink_execute (c_file_name, argv, NULL, NULL) != 0
          || tlink_execute (c_file_name, argv, NULL, NULL) != 0
          || chdir (initial_cwd) != 0)
          || chdir (initial_cwd) != 0)
        return 0;
        return 0;
 
 
      read_repo_file (f);
      read_repo_file (f);
 
 
      obstack_free (&arg_stack, NULL);
      obstack_free (&arg_stack, NULL);
      obstack_free (&temporary_obstack, temporary_firstobj);
      obstack_free (&temporary_obstack, temporary_firstobj);
    }
    }
  return 1;
  return 1;
}
}
 
 
/* The first phase of processing: determine which object files have
/* The first phase of processing: determine which object files have
   .rpo files associated with them, and read in the information.  */
   .rpo files associated with them, and read in the information.  */
 
 
static int
static int
read_repo_files (char **object_lst)
read_repo_files (char **object_lst)
{
{
  char **object = object_lst;
  char **object = object_lst;
 
 
  for (; *object; object++)
  for (; *object; object++)
    {
    {
      const char *p;
      const char *p;
      file *f;
      file *f;
 
 
      /* Don't bother trying for ld flags.  */
      /* Don't bother trying for ld flags.  */
      if (*object[0] == '-')
      if (*object[0] == '-')
        continue;
        continue;
 
 
      p = frob_extension (*object, ".rpo");
      p = frob_extension (*object, ".rpo");
 
 
      if (! file_exists (p))
      if (! file_exists (p))
        continue;
        continue;
 
 
      f = file_hash_lookup (p);
      f = file_hash_lookup (p);
 
 
      read_repo_file (f);
      read_repo_file (f);
    }
    }
 
 
  if (file_stack != NULL && ! recompile_files ())
  if (file_stack != NULL && ! recompile_files ())
    return 0;
    return 0;
 
 
  return (symbol_stack != NULL);
  return (symbol_stack != NULL);
}
}
 
 
/* Add the demangled forms of any new symbols to the hash table.  */
/* Add the demangled forms of any new symbols to the hash table.  */
 
 
static void
static void
demangle_new_symbols (void)
demangle_new_symbols (void)
{
{
  symbol *sym;
  symbol *sym;
 
 
  while ((sym = symbol_pop ()) != NULL)
  while ((sym = symbol_pop ()) != NULL)
    {
    {
      demangled *dem;
      demangled *dem;
      const char *p = cplus_demangle (sym->key, DMGL_PARAMS | DMGL_ANSI);
      const char *p = cplus_demangle (sym->key, DMGL_PARAMS | DMGL_ANSI);
 
 
      if (! p)
      if (! p)
        continue;
        continue;
 
 
      dem = demangled_hash_lookup (p, true);
      dem = demangled_hash_lookup (p, true);
      dem->mangled = sym->key;
      dem->mangled = sym->key;
    }
    }
}
}
 
 
/* Step through the output of the linker, in the file named FNAME, and
/* Step through the output of the linker, in the file named FNAME, and
   adjust the settings for each symbol encountered.  */
   adjust the settings for each symbol encountered.  */
 
 
static int
static int
scan_linker_output (const char *fname)
scan_linker_output (const char *fname)
{
{
  FILE *stream = fopen (fname, "r");
  FILE *stream = fopen (fname, "r");
  char *line;
  char *line;
  int skip_next_in_line = 0;
  int skip_next_in_line = 0;
 
 
  while ((line = tfgets (stream)) != NULL)
  while ((line = tfgets (stream)) != NULL)
    {
    {
      char *p = line, *q;
      char *p = line, *q;
      symbol *sym;
      symbol *sym;
      int end;
      int end;
      int ok = 0;
      int ok = 0;
 
 
      /* On darwin9, we might have to skip " in " lines as well.  */
      /* On darwin9, we might have to skip " in " lines as well.  */
      if (skip_next_in_line
      if (skip_next_in_line
          && strstr (p, " in "))
          && strstr (p, " in "))
          continue;
          continue;
      skip_next_in_line = 0;
      skip_next_in_line = 0;
 
 
      while (*p && ISSPACE ((unsigned char) *p))
      while (*p && ISSPACE ((unsigned char) *p))
        ++p;
        ++p;
 
 
      if (! *p)
      if (! *p)
        continue;
        continue;
 
 
      for (q = p; *q && ! ISSPACE ((unsigned char) *q); ++q)
      for (q = p; *q && ! ISSPACE ((unsigned char) *q); ++q)
        ;
        ;
 
 
      /* Try the first word on the line.  */
      /* Try the first word on the line.  */
      if (*p == '.')
      if (*p == '.')
        ++p;
        ++p;
      if (!strncmp (p, USER_LABEL_PREFIX, strlen (USER_LABEL_PREFIX)))
      if (!strncmp (p, USER_LABEL_PREFIX, strlen (USER_LABEL_PREFIX)))
        p += strlen (USER_LABEL_PREFIX);
        p += strlen (USER_LABEL_PREFIX);
 
 
      end = ! *q;
      end = ! *q;
      *q = 0;
      *q = 0;
      sym = symbol_hash_lookup (p, false);
      sym = symbol_hash_lookup (p, false);
 
 
      /* Some SVR4 linkers produce messages like
      /* Some SVR4 linkers produce messages like
         ld: 0711-317 ERROR: Undefined symbol: .g__t3foo1Zi
         ld: 0711-317 ERROR: Undefined symbol: .g__t3foo1Zi
         */
         */
      if (! sym && ! end && strstr (q + 1, "Undefined symbol: "))
      if (! sym && ! end && strstr (q + 1, "Undefined symbol: "))
        {
        {
          char *p = strrchr (q + 1, ' ');
          char *p = strrchr (q + 1, ' ');
          p++;
          p++;
          if (*p == '.')
          if (*p == '.')
            p++;
            p++;
          if (!strncmp (p, USER_LABEL_PREFIX, strlen (USER_LABEL_PREFIX)))
          if (!strncmp (p, USER_LABEL_PREFIX, strlen (USER_LABEL_PREFIX)))
            p += strlen (USER_LABEL_PREFIX);
            p += strlen (USER_LABEL_PREFIX);
          sym = symbol_hash_lookup (p, false);
          sym = symbol_hash_lookup (p, false);
        }
        }
 
 
      if (! sym && ! end)
      if (! sym && ! end)
        /* Try a mangled name in quotes.  */
        /* Try a mangled name in quotes.  */
        {
        {
          const char *oldq = q + 1;
          const char *oldq = q + 1;
          demangled *dem = 0;
          demangled *dem = 0;
          q = 0;
          q = 0;
 
 
          /* On darwin9, we look for "foo" referenced from:\n\(.* in .*\n\)*  */
          /* On darwin9, we look for "foo" referenced from:\n\(.* in .*\n\)*  */
          if (strcmp (oldq, "referenced from:") == 0)
          if (strcmp (oldq, "referenced from:") == 0)
            {
            {
              /* We have to remember that we found a symbol to tweak.  */
              /* We have to remember that we found a symbol to tweak.  */
              ok = 1;
              ok = 1;
 
 
              /* We actually want to start from the first word on the
              /* We actually want to start from the first word on the
                 line.  */
                 line.  */
              oldq = p;
              oldq = p;
 
 
              /* Since the format is multiline, we have to skip
              /* Since the format is multiline, we have to skip
                 following lines with " in ".  */
                 following lines with " in ".  */
              skip_next_in_line = 1;
              skip_next_in_line = 1;
            }
            }
 
 
          /* First try `GNU style'.  */
          /* First try `GNU style'.  */
          p = strchr (oldq, '`');
          p = strchr (oldq, '`');
          if (p)
          if (p)
            p++, q = strchr (p, '\'');
            p++, q = strchr (p, '\'');
          /* Then try "double quotes".  */
          /* Then try "double quotes".  */
          else if (p = strchr (oldq, '"'), p)
          else if (p = strchr (oldq, '"'), p)
            p++, q = strchr (p, '"');
            p++, q = strchr (p, '"');
          else {
          else {
            /* Then try entire line.  */
            /* Then try entire line.  */
            q = strchr (oldq, 0);
            q = strchr (oldq, 0);
            if (q != oldq)
            if (q != oldq)
              p = (char *)oldq;
              p = (char *)oldq;
          }
          }
 
 
          if (p)
          if (p)
            {
            {
              /* Don't let the strstr's below see the demangled name; we
              /* Don't let the strstr's below see the demangled name; we
                 might get spurious matches.  */
                 might get spurious matches.  */
              p[-1] = '\0';
              p[-1] = '\0';
 
 
              /* powerpc64-linux references .foo when calling function foo.  */
              /* powerpc64-linux references .foo when calling function foo.  */
              if (*p == '.')
              if (*p == '.')
                p++;
                p++;
            }
            }
 
 
          /* We need to check for certain error keywords here, or we would
          /* We need to check for certain error keywords here, or we would
             mistakenly use GNU ld's "In function `foo':" message.  */
             mistakenly use GNU ld's "In function `foo':" message.  */
          if (q && (ok
          if (q && (ok
                    || strstr (oldq, "ndefined")
                    || strstr (oldq, "ndefined")
                    || strstr (oldq, "nresolved")
                    || strstr (oldq, "nresolved")
                    || strstr (oldq, "nsatisfied")
                    || strstr (oldq, "nsatisfied")
                    || strstr (oldq, "ultiple")))
                    || strstr (oldq, "ultiple")))
            {
            {
              *q = 0;
              *q = 0;
              dem = demangled_hash_lookup (p, false);
              dem = demangled_hash_lookup (p, false);
              if (dem)
              if (dem)
                sym = symbol_hash_lookup (dem->mangled, false);
                sym = symbol_hash_lookup (dem->mangled, false);
              else
              else
                {
                {
                  if (!strncmp (p, USER_LABEL_PREFIX,
                  if (!strncmp (p, USER_LABEL_PREFIX,
                                strlen (USER_LABEL_PREFIX)))
                                strlen (USER_LABEL_PREFIX)))
                    p += strlen (USER_LABEL_PREFIX);
                    p += strlen (USER_LABEL_PREFIX);
                  sym = symbol_hash_lookup (p, false);
                  sym = symbol_hash_lookup (p, false);
                }
                }
            }
            }
        }
        }
 
 
      if (sym && sym->tweaked)
      if (sym && sym->tweaked)
        {
        {
          error ("'%s' was assigned to '%s', but was not defined "
          error ("'%s' was assigned to '%s', but was not defined "
                 "during recompilation, or vice versa",
                 "during recompilation, or vice versa",
                 sym->key, sym->file->key);
                 sym->key, sym->file->key);
          fclose (stream);
          fclose (stream);
          return 0;
          return 0;
        }
        }
      if (sym && !sym->tweaking)
      if (sym && !sym->tweaking)
        {
        {
          if (tlink_verbose >= 2)
          if (tlink_verbose >= 2)
            fprintf (stderr, _("collect: tweaking %s in %s\n"),
            fprintf (stderr, _("collect: tweaking %s in %s\n"),
                     sym->key, sym->file->key);
                     sym->key, sym->file->key);
          sym->tweaking = 1;
          sym->tweaking = 1;
          file_push (sym->file);
          file_push (sym->file);
        }
        }
 
 
      obstack_free (&temporary_obstack, temporary_firstobj);
      obstack_free (&temporary_obstack, temporary_firstobj);
    }
    }
 
 
  fclose (stream);
  fclose (stream);
  return (file_stack != NULL);
  return (file_stack != NULL);
}
}
 
 
/* Entry point for tlink.  Called from main in collect2.c.
/* Entry point for tlink.  Called from main in collect2.c.
 
 
   Iteratively try to provide definitions for all the unresolved symbols
   Iteratively try to provide definitions for all the unresolved symbols
   mentioned in the linker error messages.
   mentioned in the linker error messages.
 
 
   LD_ARGV is an array of arguments for the linker.
   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
   OBJECT_LST is an array of object files that we may be able to recompile
     to provide missing definitions.  Currently ignored.  */
     to provide missing definitions.  Currently ignored.  */
 
 
void
void
do_tlink (char **ld_argv, char **object_lst ATTRIBUTE_UNUSED)
do_tlink (char **ld_argv, char **object_lst ATTRIBUTE_UNUSED)
{
{
  int exit = tlink_execute ("ld", ld_argv, ldout, lderrout);
  int exit = tlink_execute ("ld", ld_argv, ldout, lderrout);
 
 
  tlink_init ();
  tlink_init ();
 
 
  if (exit)
  if (exit)
    {
    {
      int i = 0;
      int i = 0;
 
 
      /* Until collect does a better job of figuring out which are object
      /* Until collect does a better job of figuring out which are object
         files, assume that everything on the command line could be.  */
         files, assume that everything on the command line could be.  */
      if (read_repo_files (ld_argv))
      if (read_repo_files (ld_argv))
        while (exit && i++ < MAX_ITERATIONS)
        while (exit && i++ < MAX_ITERATIONS)
          {
          {
            if (tlink_verbose >= 3)
            if (tlink_verbose >= 3)
              {
              {
                dump_file (ldout, stdout);
                dump_file (ldout, stdout);
                dump_file (lderrout, stderr);
                dump_file (lderrout, stderr);
              }
              }
            demangle_new_symbols ();
            demangle_new_symbols ();
            if (! scan_linker_output (ldout)
            if (! scan_linker_output (ldout)
                && ! scan_linker_output (lderrout))
                && ! scan_linker_output (lderrout))
              break;
              break;
            if (! recompile_files ())
            if (! recompile_files ())
              break;
              break;
            if (tlink_verbose)
            if (tlink_verbose)
              fprintf (stderr, _("collect: relinking\n"));
              fprintf (stderr, _("collect: relinking\n"));
            exit = tlink_execute ("ld", ld_argv, ldout, lderrout);
            exit = tlink_execute ("ld", ld_argv, ldout, lderrout);
          }
          }
    }
    }
 
 
  dump_file (ldout, stdout);
  dump_file (ldout, stdout);
  unlink (ldout);
  unlink (ldout);
  dump_file (lderrout, stderr);
  dump_file (lderrout, stderr);
  unlink (lderrout);
  unlink (lderrout);
  if (exit)
  if (exit)
    {
    {
      error ("ld returned %d exit status", exit);
      error ("ld returned %d exit status", exit);
      collect_exit (exit);
      collect_exit (exit);
    }
    }
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.