GCC Middle and Back End API Reference
tlink.c File Reference
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "tm.h"
#include "intl.h"
#include "obstack.h"
#include "hashtab.h"
#include "demangle.h"
#include "collect2.h"
#include "filenames.h"
#include "diagnostic-core.h"
#include "vec.h"
Include dependency graph for tlink.c:

Data Structures

struct  symbol_hash_entry
struct  file_hash_entry
struct  demangled_hash_entry
struct  symbol_stack_entry
struct  file_stack_entry

Macros

#define TARGET_64BIT   TARGET_64BIT_DEFAULT
#define MAX_ITERATIONS   17

Typedefs

typedef struct symbol_hash_entry symbol
typedef struct file_hash_entry file
typedef const char * str
typedef struct demangled_hash_entry demangled

Functions

static int hash_string_eq (const void *, const void *)
static hashval_t hash_string_hash (const void *)
static int hash_string_eq ()
static hashval_t hash_string_hash ()
static struct symbol_hash_entrysymbol_hash_lookup (const char *, int)
static struct file_hash_entryfile_hash_lookup (const char *)
static struct
demangled_hash_entry
demangled_hash_lookup (const char *, int)
static void symbol_push (symbol *)
static symbolsymbol_pop (void)
static void file_push (file *)
static filefile_pop (void)
static void tlink_init (void)
static int tlink_execute (const char *, char **, const char *, const char *)
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 *)
static struct symbol_hash_entrysymbol_hash_lookup ()
static struct file_hash_entryfile_hash_lookup ()
static struct
demangled_hash_entry
demangled_hash_lookup ()
static void symbol_push ()
static void file_push ()
static char * frob_extension ()
static char * obstack_fgets ()
static char * tfgets ()
static char * pfgets ()
static void freadsym ()
static void read_repo_file ()
static void maybe_tweak ()
static int read_repo_files ()
static bool start_tweaking ()
static int scan_linker_output ()
void do_tlink ()

Variables

int prepends_underscore
static int tlink_verbose
static char * initial_cwd
static htab_t symbol_table
static htab_t file_table
static htab_t demangled_table
struct obstack symbol_stack_obstack
struct symbol_stack_entrysymbol_stack
struct obstack file_stack_obstack
struct file_stack_entryfile_stack

Macro Definition Documentation

#define MAX_ITERATIONS   17
#define TARGET_64BIT   TARGET_64BIT_DEFAULT

Scan linker error messages for missing template instantiations and provide them.

Copyright (C) 1995-2013 Free Software Foundation, Inc. Contributed by Jason Merrill (jason.nosp@m.@cyg.nosp@m.nus.c.nosp@m.om).

This file is part of GCC.

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 Software Foundation; either version 3, or (at your option) any later version.

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.

You should have received a copy of the GNU General Public License along with GCC; see the file COPYING3. If not see http://www.gnu.org/licenses/. TARGET_64BIT may be defined to use driver specific functionality.


Typedef Documentation

typedef struct file_hash_entry file
typedef const char* str
typedef struct symbol_hash_entry symbol

Hash table boilerplate for working with htab_t. We have hash tables for symbol names, file names, and demangled symbols.


Function Documentation

static void demangle_new_symbols ( )
static

Add the demangled forms of any new symbols to the hash table.

static struct demangled_hash_entry* demangled_hash_lookup ( const char *  ,
int   
)
staticread
static struct demangled_hash_entry* demangled_hash_lookup ( )
staticread

Look up an entry in the demangled name hash table.

References demangled_hash_entry::key.

void do_tlink ( )

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.

Until collect does a better job of figuring out which are object files, assume that everything on the command line could be.

     We have just successfully produced an output file, so assume that we
     may unlink it if need be for now on.   
static struct file_hash_entry* file_hash_lookup ( const char *  )
staticread
static struct file_hash_entry* file_hash_lookup ( )
staticread

Look up an entry in the file hash table.

References file_hash_entry::key.

static file * file_pop ( void  )
static
static void file_push ( file )
static
static void file_push ( )
static
static void freadsym ( FILE *  ,
file ,
int   
)
static
static void freadsym ( )
static

Real tlink code. 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 is offered, chosen or provided if CHOSEN is 0, 1 or 2, respectively.

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

We didn't have this symbol already, so we choose this file.

     We want this file; cast aside any pretender.   
static char* frob_extension ( const char *  ,
const char *   
)
static
static char* frob_extension ( )
static

References NULL.

static int hash_string_eq ( const void *  ,
const void *   
)
static

Hash and comparison functions for these hash tables.

static int hash_string_eq ( )
static
static hashval_t hash_string_hash ( const void *  )
static
static hashval_t hash_string_hash ( )
static
static void maybe_tweak ( char *  ,
file  
)
static

Referenced by recompile_files().

static void maybe_tweak ( )
static

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.

static char* obstack_fgets ( FILE *  ,
struct obstack  
)
static

Referenced by obstack_fgets().

static char* obstack_fgets ( )
static
static char* pfgets ( FILE *  )
static
static char* pfgets ( )
static
static void read_repo_file ( file )
static
static void read_repo_file ( )
static

Read in the repo file denoted by F, and record all its information.

static int read_repo_files ( char **  )
static
static int read_repo_files ( )
static

The first phase of processing: determine which object files have .rpo files associated with them, and read in the information.

Don't bother trying for ld flags.

static int recompile_files ( )
static

Update the repo files for each of the object files we have adjusted and recompile.

     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.   
     Build a null-terminated argv array suitable for
     tlink_execute().  Manipulate arguments on the arg_stack while
     building argv on the temporary_obstack.   
         Arguments are delimited by single-quotes.  Find the
         opening quote.   
         Find the closing quote.   
         Replace '\'' with '.  This is how set_collect_gcc_options
         encodes a single-quote.   

References maybe_tweak().

static int scan_linker_output ( const char *  )
static
static int scan_linker_output ( )
static

Step through the output of the linker, in the file named FNAME, and adjust the settings for each symbol encountered.

     On darwin9, we might have to skip " in " lines as well.   
     Try the first word on the line.   
     Some SVR4 linkers produce messages like
     ld: 0711-317 ERROR: Undefined symbol: .g__t3foo1Zi
       Try a mangled name in quotes.   
         On darwin9, we look for "foo" referenced from:\n\(.* in .*\n\)*   
             We have to remember that we found a symbol to tweak.   
             We actually want to start from the first word on the
             line.   
             Since the format is multiline, we have to skip
             following lines with " in ".   
         First try `GNU style'.   
         Then try "double quotes".   
         Then try 'single quotes'.   
           Then try entire line.   
             Don't let the strstr's below see the demangled name; we
             might get spurious matches.   
             powerpc64-linux references .foo when calling function foo.   
         We need to check for certain error keywords here, or we would
         mistakenly use GNU ld's "In function `foo':" message.   
         We found a demangled name.  If this is the name of a
         constructor or destructor, there can be several mangled names
         that match it, so choose or unchoose all of them.  If some are
         chosen and some not, leave the later ones that don't match
         alone for now; either this will cause the link to succeed, or
         on the next attempt we will switch all of them the other way
         and that will cause it to succeed.   
               Mismatch.   
             Avoid an error about re-tweaking when we guess wrong in
             the case of mismatch.   
static bool start_tweaking ( )
static

We want to tweak symbol SYM. Return true if all is well, false on error.

static struct symbol_hash_entry* symbol_hash_lookup ( const char *  ,
int   
)
staticread

Referenced by pfgets().

static struct symbol_hash_entry* symbol_hash_lookup ( )
staticread

Look up an entry in the symbol hash table.

References symbol_hash_entry::key.

static symbol * symbol_pop ( void  )
static
static void symbol_push ( symbol )
static
static void symbol_push ( )
static
static char* tfgets ( FILE *  )
static

Referenced by pfgets().

static char* tfgets ( )
static
static int tlink_execute ( const char *  prog,
char **  argv,
const char *  outname,
const char *  errname 
)
static

References temporary_obstack.

static void tlink_init ( )
static

Other machinery. Initialize the tlink machinery. Called from do_tlink.


Variable Documentation

htab_t demangled_table
static
struct file_stack_entry* file_stack
struct obstack file_stack_obstack
htab_t file_table
static
char* initial_cwd
static
int prepends_underscore

Defined in the automatically-generated underscore.c.

struct symbol_stack_entry* symbol_stack

Referenced by symbol_push().

struct obstack symbol_stack_obstack

Referenced by symbol_push().

htab_t symbol_table
static
int tlink_verbose
static