GCC Middle and Back End API Reference
collect2.c File Reference

Data Structures

struct  id
struct  head
struct  lto_object
struct  lto_object_list

Typedefs

typedef int scanfilter

Enumerations

enum  lto_mode_d {
  LTO_MODE_NONE, LTO_MODE_LTO, LTO_MODE_WHOPR, LTO_MODE_NONE,
  LTO_MODE_LTO, LTO_MODE_WHOPR
}
enum  symkind {
  SYM_REGULAR = 0, SYM_CTOR = 1, SYM_DTOR = 2, SYM_INIT = 3,
  SYM_FINI = 4, SYM_DWEH = 5
}
enum  scanpass {
  PASS_FIRST, PASS_OBJ, PASS_LIB, PASS_SECOND,
  PASS_LTOINFO
}
enum  scanfilter_masks {
  SCAN_NOTHING = 0, SCAN_CTOR = 1 << SYM_CTOR, SCAN_DTOR = 1 << SYM_DTOR, SCAN_INIT = 1 << SYM_INIT,
  SCAN_FINI = 1 << SYM_FINI, SCAN_DWEH = 1 << SYM_DWEH, SCAN_ALL = ~0
}

Functions

static symkind is_ctor_dtor (const char *)
static void handler (int)
static void do_wait (const char *, struct pex_obj *)
static void fork_execute (const char *, char **)
static void maybe_unlink (const char *)
static void maybe_unlink_list (char **)
static void add_to_list (struct head *, const char *)
static int extract_init_priority (const char *)
static void sort_ids (struct head *)
static void write_list (FILE *, const char *, struct id *)
static void dump_list (FILE *, const char *, struct id *)
static void dump_prefix_list (FILE *, const char *, struct prefix_list *)
static void write_list_with_asm (FILE *, const char *, struct id *)
static void write_c_file (FILE *, const char *)
static void write_c_file_stat (FILE *, const char *)
static void write_c_file_glob (FILE *, const char *)
static void scan_libraries (const char *)
static int is_in_list (const char *, struct id *)
static void write_aix_file (FILE *, struct id *)
static char * resolve_lib_name (const char *)
static char * extract_string (const char **)
static void post_ld_pass (bool)
static void process_args (int *argcp, char **argv)
static void scan_prog_file (const char *, scanpass, scanfilter)
static void collect_atexit ()
void notice ()
void notice_translated ()
static void handler ()
int file_exists ()
static char * extract_string ()
void dump_ld_file ()
static symkind is_ctor_dtor ()
static void add_lto_object ()
static void maybe_run_lto_and_relink (char **lto_ld_argv, char **object_lst, const char **object, bool force)
int main ()
int collect_wait ()
static void do_wait ()
struct pex_obj * collect_execute (const char *prog, char **argv, const char *outname, const char *errname, int flags)
static void fork_execute ()
static void maybe_unlink ()
static void maybe_unlink_list ()
static void add_to_list ()
static int extract_init_priority ()
static void sort_ids ()
static void write_list ()
static int is_in_list ()
static void dump_list ()
static void dump_prefix_list ()
static void write_list_with_asm ()
static void write_c_file_stat ()
static void write_c_file_glob ()
static void write_c_file ()
static void write_aix_file ()
static bool maybe_lto_object_file ()
static void scan_libraries ()
static int ignore_library (const char *)
static int ignore_library ()
char * ldgetname (LDFILE *, GCC_SYMENT *)
static char * resolve_lib_name ()
static void do_dsymutil (const char *output_file)

Variables

int do_collecting = 1
int no_demangle
bool vflag
static int rflag
static int strip_flag
static int export_flag
static int aix64_flag
static int aixrtl_flag
static enum lto_mode_d lto_mode = LTO_MODE_NONE
bool debug
bool helpflag
static int shared_obj
static const char * c_file
static const char * o_file
static const char * export_file
static char ** lto_o_files
const char * ldout
const char * lderrout
static const char * output_file
static const char * nm_file_name
static const char * ldd_file_name
static const char * strip_file_name
const char * c_file_name
static char * initname
static char * fininame
static struct head constructors
static struct head destructors
static struct head exports
static struct head frame_tables
static bool at_file_supplied
static char * response_file
struct obstack temporary_obstack
char * temporary_firstobj
static const char * target_system_root = TARGET_SYSTEM_ROOT
bool may_unlink_output_file = false
static struct head libs
static struct path_prefix cmdline_lib_dirs
static struct path_prefix libpath_lib_dirs
static struct path_prefixlibpaths [3]
static struct lto_object_list lto_objects
static struct path_prefix cpath path
static const char *const target_machine = TARGET_MACHINE
static long sequence_number = 0
static const char *const aix_std_libs []
static int flag_dsym = false
static int flag_idsym = false

Typedef Documentation

typedef int scanfilter
This type is used for parameters and variables which hold
   combinations of the flags in enum scanfilter_masks.   

Enumeration Type Documentation

enum lto_mode_d
Enumerator:
LTO_MODE_NONE 
LTO_MODE_LTO 
LTO_MODE_WHOPR 
LTO_MODE_NONE 
LTO_MODE_LTO 
LTO_MODE_WHOPR 
... and which kinds of symbols are to be considered.   
Enumerator:
SCAN_NOTHING 
SCAN_CTOR 
SCAN_DTOR 
SCAN_INIT 
SCAN_FINI 
SCAN_DWEH 
SCAN_ALL 
enum scanpass
Enumerations describing which pass this is for scanning the
   program file ...   
Enumerator:
PASS_FIRST 
PASS_OBJ 
PASS_LIB 
PASS_SECOND 
PASS_LTOINFO 
enum symkind
Special kinds of symbols that a name may denote.   
Enumerator:
SYM_REGULAR 
SYM_CTOR 
SYM_DTOR 
SYM_INIT 
SYM_FINI 
SYM_DWEH 

Function Documentation

static void add_lto_object ( )
static
Search for NAME using prefix list PPREFIX.  We only look for executable
   files.

   Return 0 if not found, otherwise return its name, allocated with malloc.   
Add an entry for the object file NAME to object file list LIST.
   New entries are added at the end of the list. The original pointer
   value of NAME is preserved, i.e., no string copy is performed.   

References lto_object_list::first, lto_object_list::last, lto_object::name, and lto_object::next.

Referenced by scan_prog_file().

static void add_to_list ( struct head ,
const char *   
)
static
static void add_to_list ( )
static
Add a name to a linked list.   

References head::first, free(), head::last, id::name, id::next, head::number, id::sequence, sequence_number, and strlen().

static void collect_atexit ( )
static
Delete tempfiles and exit function.   

References c_file, dump_ld_file(), export_file, lderrout, ldout, lto_o_files, maybe_unlink(), maybe_unlink_list(), o_file, and response_file.

Referenced by main().

struct pex_obj* collect_execute ( const char *  prog,
char **  argv,
const char *  outname,
const char *  errname,
int  flags 
)
read
Execute a program, and wait for the reply.   

References at_file_supplied, debug, errno, fatal_error(), free(), notice(), response_file, and vflag.

Referenced by do_dsymutil(), fork_execute(), maybe_run_lto_and_relink(), run_gcc(), and tlink_execute().

int collect_wait ( )
Wait for a process to finish, and exit if a nonzero status is found.   

References error(), fatal_error(), and strsignal().

Referenced by do_wait(), fork_execute(), run_gcc(), and tlink_execute().

static void do_dsymutil ( const char *  output_file)
static

References collect_execute(), do_wait(), and output_file.

Referenced by post_ld_pass().

static void do_wait ( const char *  ,
struct pex_obj *   
)
static
static void do_wait ( )
static
void dump_ld_file ( )
static void dump_list ( FILE *  ,
const char *  ,
struct id  
)
static

Referenced by main().

static void dump_list ( )
static
Added for debugging purpose.   

References id::name, and id::next.

static void dump_prefix_list ( FILE *  ,
const char *  ,
struct prefix_list  
)
static
static void dump_prefix_list ( )
static
static int extract_init_priority ( const char *  )
static

Referenced by sort_ids().

static int extract_init_priority ( )
static
Grab the init priority number from an init function name that
   looks like "_GLOBAL_.I.12345.foo".   
static char* extract_string ( const char **  )
static

Referenced by main().

static char* extract_string ( )
static
Parse a reasonable subset of shell quoting syntax.   

References temporary_obstack.

int file_exists ( )
static void fork_execute ( const char *  ,
char **   
)
static

Referenced by main(), and maybe_run_lto_and_relink().

static void fork_execute ( )
static

References collect_execute(), and do_wait().

static void handler ( )
static
static int ignore_library ( const char *  )
static
This function checks the filename and returns 1
   if this name matches the location of a standard AIX library.   
static int ignore_library ( )
static

References strlen(), and target_system_root.

static symkind is_ctor_dtor ( const char *  )
static

Referenced by scan_prog_file().

static symkind is_ctor_dtor ( )
static
Return the kind of symbol denoted by name S.   

References len, names, SYM_CTOR, SYM_DTOR, SYM_DWEH, SYM_FINI, SYM_INIT, and SYM_REGULAR.

static int is_in_list ( const char *  ,
struct id  
)
static
static int is_in_list ( )
static
This function is really used only on AIX, but may be useful.   

References id::name, and id::next.

char* ldgetname ( LDFILE ,
GCC_SYMENT *   
)
static bool maybe_lto_object_file ( )
static
Check to make sure the file is an LTO object file.   

Referenced by scan_prog_file().

static void maybe_run_lto_and_relink ( char **  lto_ld_argv,
char **  object_lst,
const char **  object,
bool  force 
)
static
Perform a link-time recompilation and relink if any of the object
   files contain LTO info.  The linker command line LTO_LD_ARGV
   represents the linker command that would produce a final executable
   without the use of LTO. OBJECT_LST is a vector of object file names
   appearing in LTO_LD_ARGV that are to be considered for link-time
   recompilation, where OBJECT is a pointer to the last valid element.
   (This awkward convention avoids an impedance mismatch with the
   usage of similarly-named variables in main().)  The elements of
   OBJECT_LST must be identical, i.e., pointer equal, to the
   corresponding arguments in LTO_LD_ARGV.

   Upon entry, at least one linker run has been performed without the
   use of any LTO info that might be present.  Any recompilations
   necessary for template instantiations have been performed, and
   initializer/finalizer tables have been created if needed and
   included in the linker command line LTO_LD_ARGV. If any of the
   object files contain LTO info, we run the LTO back end on all such
   files, and perform the final link with the LTO back end output
   substituted for the LTO-optimized files.  In some cases, a final
   link with all link-time generated code has already been performed,
   so there is no need to relink if no LTO info is found.  In other
   cases, our caller has not produced the final executable, and is
   relying on us to perform the required link whether LTO info is
   present or not.  In that case, the FORCE argument should be true.
   Note that the linker command line argument LTO_LD_ARGV passed into
   this function may be modified in place.   

References collect_execute(), do_wait(), fatal_error(), lto_object_list::first, fork_execute(), free(), getenv(), lto_o_files, lto_objects, maybe_unlink_list(), lto_object::name, lto_object::next, PASS_LTOINFO, post_ld_pass(), SCAN_ALL, scan_prog_file(), temporary_firstobj, and temporary_obstack.

Referenced by main().

static void maybe_unlink ( const char *  )
static
static void maybe_unlink ( )
static
Unlink FILE unless we are debugging or this is the output_file
   and we may not unlink it.   

References debug, may_unlink_output_file, notice(), and output_file.

static void maybe_unlink_list ( char **  )
static
static void maybe_unlink_list ( )
static
Call maybe_unlink on the NULL-terminated list, FILE_LIST.   

References maybe_unlink().

void notice ( )
Notify user of a non-error.   

Referenced by collect_execute(), main(), maybe_unlink(), scan_libraries(), and write_c_file_stat().

void notice_translated ( )
Notify user of a non-error, without translating the format string.   

Referenced by main().

static void post_ld_pass ( bool  temp_file)
static

References do_dsymutil(), and output_file.

Referenced by main(), and maybe_run_lto_and_relink().

static void process_args ( int *  argcp,
char **  argv 
)
static
static char* resolve_lib_name ( const char *  )
static

Referenced by main().

static char* resolve_lib_name ( )
static
Given a library name without "lib" prefix, this function
   returns a full library name including a path.   

References aixrtl_flag, debug, fatal_error(), file_exists(), path_prefix::max_len, prefix_list::next, path_prefix::plist, prefix_list::prefix, and strlen().

static void scan_libraries ( const char *  )
static

Referenced by main().

static void scan_libraries ( )
static
Use the List Dynamic Dependencies program to find shared libraries that
   the output file depends upon and their initialization/finalization
   routines, if any.   

References add_to_list(), debug, do_wait(), errno, error(), fatal_error(), head::first, ldd_file_name, id::name, id::next, notice(), PASS_LIB, SCAN_ALL, scan_prog_file(), and vflag.

static void scan_prog_file ( const char *  prog_name,
scanpass  which_pass,
scanfilter  filter 
)
static
Scan the name list of the loaded program for the symbols g++ uses for
   static constructors and destructors.

   The SCANPASS argument tells which collect processing pass this is for and
   the SCANFILTER argument tells which kinds of symbols to consider in this
   pass.  Symbols of a special kind not in the filter mask are considered as
   regular ones.

   The constructor table begins at __CTOR_LIST__ and contains a count of the
   number of pointers (or -1 if the constructors are built in a separate
   section by the linker), followed by the pointers to the constructor
   functions, terminated with a null pointer.  The destructor table has the
   same format, and begins at __DTOR_LIST__.   
Generic version to scan the name list of the loaded program for
   the symbols g++ uses for static constructors and destructors.   
COFF version to scan the name list of the loaded program for
   the symbols g++ uses for static constructors and destructors.   

References add_lto_object(), add_to_list(), constructors, debug, destructors, do_wait(), errno, fatal_error(), frame_tables, is_ctor_dtor(), lto_objects, maybe_lto_object_file(), nm_file_name, PASS_LIB, PASS_LTOINFO, PASS_SECOND, SCAN_CTOR, SCAN_DTOR, SCAN_DWEH, SCAN_FINI, SCAN_INIT, SYM_CTOR, SYM_DTOR, SYM_DWEH, SYM_FINI, SYM_INIT, and vflag.

Referenced by main(), maybe_run_lto_and_relink(), and scan_libraries().

static void sort_ids ( struct head )
static

Referenced by main().

static void sort_ids ( )
static
Insertion sort the ids from ctor/dtor list HEAD_PTR in descending order.
   ctors will be run from right to left, dtors from left to right.   

References extract_init_priority(), head::first, id::name, id::next, id::sequence, and sequence_number.

static void write_aix_file ( FILE *  ,
struct id  
)
static

Referenced by main().

static void write_aix_file ( )
static

References id::name, and id::next.

static void write_c_file ( FILE *  ,
const char *   
)
static

Referenced by main().

static void write_c_file ( )
static
static void write_c_file_glob ( FILE *  ,
const char *   
)
static

Referenced by write_c_file().

static void write_c_file_glob ( )
static
Write the constructor/destructor tables.   

References constructors, destructors, head::first, frame_tables, head::number, write_list(), and write_list_with_asm().

static void write_c_file_stat ( FILE *  ,
const char *   
)
static

Referenced by write_c_file().

static void write_c_file_stat ( )
static
Write out the constructor and destructor tables statically (for a shared
   object), along with the functions to execute them.   

References constructors, debug, destructors, fininame, head::first, frame_tables, free(), initname, notice(), head::number, output_file, shared_obj, strlen(), write_list(), and write_list_with_asm().

static void write_list ( FILE *  ,
const char *  ,
struct id  
)
static
static void write_list ( )
static
Write: `prefix', the names on list LIST, `suffix'.   

References id::next, and id::sequence.

static void write_list_with_asm ( FILE *  ,
const char *  ,
struct id  
)
static
static void write_list_with_asm ( )
static

References id::name, id::next, and id::sequence.


Variable Documentation

int aix64_flag
static

Referenced by main().

const char* const aix_std_libs[]
static
Initial value:
{
"/unix",
"/lib/libc.a",
"/lib/libm.a",
"/lib/libc_r.a",
"/lib/libm_r.a",
"/usr/lib/libc.a",
"/usr/lib/libm.a",
"/usr/lib/libc_r.a",
"/usr/lib/libm_r.a",
"/usr/lib/threads/libc.a",
"/usr/ccs/lib/libc.a",
"/usr/ccs/lib/libm.a",
"/usr/ccs/lib/libc_r.a",
"/usr/ccs/lib/libm_r.a",
NULL
}
Array of standard AIX libraries which should not
   be scanned for ctors/dtors.   
int aixrtl_flag
static

Referenced by main(), and resolve_lib_name().

bool at_file_supplied
static

Referenced by collect_execute(), and main().

const char* c_file
static

Referenced by collect_atexit(), handler(), and main().

const char* c_file_name

Referenced by main(), and recompile_files().

struct path_prefix cmdline_lib_dirs
static

Referenced by main().

struct head constructors
static
DEBUG_FUNCTION void debug
struct head destructors
static
int do_collecting = 1

Referenced by main().

const char* export_file
static

Referenced by collect_atexit(), handler(), and main().

int export_flag
static

Referenced by main().

struct head exports
static

Referenced by main().

char * fininame
static

Referenced by main(), and write_c_file_stat().

int flag_dsym = false
static
int flag_idsym = false
static
struct head frame_tables
static
bool helpflag

Referenced by main().

char* initname
static

Referenced by main(), and write_c_file_stat().

const char* ldd_file_name
static

Referenced by main(), and scan_libraries().

const char* lderrout
const char* ldout
struct path_prefix libpath_lib_dirs
static

Referenced by main().

struct path_prefix* libpaths[3]
static
Initial value:
struct head libs
static
Lists to keep libraries to be scanned for global constructors/destructors.   

Referenced by main().

enum lto_mode_d lto_mode = LTO_MODE_NONE
static
Current LTO mode.   

Referenced by main().

char** lto_o_files
static
struct lto_object_list lto_objects
static
bool may_unlink_output_file = false
Whether we may unlink the output file, which should be set as soon as we
   know we have successfully produced it.  This is typically useful to prevent
   blindly attempting to unlink a read-only output that the target linker
   would leave untouched.   

Referenced by do_tlink(), and maybe_unlink().

const char* nm_file_name
static

Referenced by main(), and scan_prog_file().

int no_demangle
Nonzero if we should suppress the automatic demangling of identifiers
   in linker error messages.  Set from COLLECT_NO_DEMANGLE.   

Referenced by dump_ld_file(), and main().

const char* o_file
static

Referenced by collect_atexit(), handler(), and main().

const char* output_file
static
struct path_prefix cpath path
static
char* response_file
static
int rflag
static

Referenced by main().

long sequence_number = 0
static

Referenced by add_to_list(), and sort_ids().

int shared_obj
static
const char* strip_file_name
static

Referenced by main().

int strip_flag
static

Referenced by main().

const char* const target_machine = TARGET_MACHINE
static
This is the name of the target machine.  We use it to form the name
   of the files to execute.   
static const char * target_system_root = TARGET_SYSTEM_ROOT
static
A string that must be prepended to a target OS path in order to find
   it on the host system.   

Referenced by ignore_library(), and main().