GCC Middle and Back End API Reference
|
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "tm.h"
#include "filenames.h"
#include "file-find.h"
#include "simple-object.h"
#include "lto-section-names.h"
#include "collect2.h"
#include "collect2-aix.h"
#include "collect-utils.h"
#include "diagnostic.h"
#include "demangle.h"
#include "obstack.h"
#include "intl.h"
#include "version.h"
Data Structures | |
struct | id |
struct | head |
struct | lto_object |
struct | lto_object_list |
Macros | |
#define | TARGET_64BIT TARGET_64BIT_DEFAULT |
#define | LIBRARY_PATH_ENV "LIBRARY_PATH" |
#define | COLLECT |
#define | OBJECT_FORMAT_NONE |
#define | NM_FLAGS "-n" |
#define | NAME__MAIN "__main" |
#define | DEFAULT_INIT_PRIORITY 65535 |
#define | COLLECT_SHARED_INIT_FUNC(STREAM, FUNC) |
#define | COLLECT_SHARED_FINI_FUNC(STREAM, FUNC) |
#define | SHLIB_SUFFIX ".so" |
#define | DO_COLLECT_EXPORT_LIST 0 |
Typedefs | |
typedef int | scanfilter |
Enumerations | |
enum | lto_mode_d { 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 , SYM_AIXI = 6 , SYM_AIXD = 7 } |
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_AIXI = 1 << SYM_AIXI , SCAN_AIXD = 1 << SYM_AIXD , SCAN_ALL = ~0 } |
Functions | |
static symkind | is_ctor_dtor (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 | 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 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) |
void | tool_cleanup (bool from_signal) |
static void | collect_atexit (void) |
void | notice_translated (const char *cmsgid,...) |
int | file_exists (const char *name) |
static void | add_lto_object (struct lto_object_list *list, const char *name) |
static void | maybe_run_lto_and_relink (char **lto_ld_argv, char **object_lst, const char **object, bool force) |
static void | do_link (char **ld_argv, const char *atsuffix) |
int | main (int argc, char **argv) |
void | maybe_unlink (const char *file) |
static int | has_lto_section (void *data, const char *name, off_t offset, off_t length) |
static bool | is_lto_object_file (const char *prog_name) |
Variables | |
int | do_collecting = 0 |
int | no_demangle |
static int | rflag |
static int | strip_flag |
static enum lto_mode_d | lto_mode = LTO_MODE_NONE |
bool | helpflag |
static int | shared_obj |
static int | static_obj |
static const char * | c_file |
static const char * | o_file |
static char ** | lto_o_files |
static const char * | output_file |
static const char * | nm_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 | frame_tables |
bool | at_file_supplied |
struct obstack | temporary_obstack |
char * | temporary_firstobj |
static const char * | target_system_root = "" |
bool | may_unlink_output_file = false |
static struct lto_object_list | lto_objects |
const char | tool_name [] = "collect2" |
static struct path_prefix cpath | path |
static long | sequence_number = 0 |
#define COLLECT |
#define COLLECT_SHARED_FINI_FUNC | ( | STREAM, | |
FUNC ) |
Referenced by write_c_file_stat().
#define COLLECT_SHARED_INIT_FUNC | ( | STREAM, | |
FUNC ) |
Referenced by write_c_file_stat().
#define DEFAULT_INIT_PRIORITY 65535 |
This must match tree.h.
Referenced by asan_finish_file(), build_gcov_exit_decl(), build_init_ctor(), decl_fini_priority_insert(), decl_fini_priority_lookup(), decl_init_priority_insert(), decl_init_priority_lookup(), default_named_section_asm_out_constructor(), default_named_section_asm_out_destructor(), extract_init_priority(), get_elf_initfini_array_priority_section(), cgraph_node::get_fini_priority(), symtab_node::get_init_priority(), ipa_lower_emutls(), symtab_node::priority_info(), cgraph_node::set_fini_priority(), and symtab_node::set_init_priority().
#define DO_COLLECT_EXPORT_LIST 0 |
Cook up an always defined indication of whether we proceed the "EXPORT_LIST" way.
Referenced by main().
#define LIBRARY_PATH_ENV "LIBRARY_PATH" |
Referenced by main(), and driver::maybe_run_linker().
#define NAME__MAIN "__main" |
Some systems use __main in a way incompatible with its use in gcc, in these cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to give the same symbol without quotes for an alternative entry point.
Referenced by write_c_file_glob().
#define NM_FLAGS "-n" |
Default flags to pass to nm.
Referenced by scan_prog_file().
#define OBJECT_FORMAT_NONE |
On certain systems, we have code that works by scanning the object file directly. But this code uses system-specific header files and library functions, so turn it off in a cross-compiler. Likewise, the names of the utilities are not correct for a cross-compiler; we have to hope that cross-versions are in the proper directories.
If we cannot use a special method, use the ordinary one: run nm to find what symbols are present. In a cross-compiler, this means you need a cross nm, but that is not quite as unpleasant as special headers.
#define SHLIB_SUFFIX ".so" |
Referenced by write_c_file_stat().
#define TARGET_64BIT TARGET_64BIT_DEFAULT |
Collect static initialization info into data structures that can be traversed by C++ initialization and finalization routines. Copyright (C) 1992-2024 Free Software Foundation, Inc. Contributed by Chris Smith (csmith@convex.com). Heavily modified by Michael Meissner (meissner@cygnus.com), Per Bothner (bothner@cygnus.com), and John Gilmore (gnu@cygnus.com). 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/>.
Build tables of static constructors and destructors and run ld.
TARGET_64BIT may be defined to use driver specific functionality.
typedef int scanfilter |
This type is used for parameters and variables which hold combinations of the flags in enum scanfilter_masks.
enum lto_mode_d |
enum scanfilter_masks |
enum scanpass |
enum symkind |
|
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, lto_object::next, and NULL.
Referenced by scan_prog_file().
|
static |
Add a name to a linked list.
References head::first, free(), head::last, id::name, id::next, head::number, id::sequence, and sequence_number.
Referenced by main(), and scan_prog_file().
|
static |
References tool_cleanup().
Referenced by main().
|
static |
Entry point for linker invoation. Called from main in collect2.cc. LD_ARGV is an array of arguments for the linker.
References at_file_supplied, collect_execute(), collect_wait(), error(), may_unlink_output_file, and NULL.
Referenced by main().
|
static |
Grab the init priority number from an init function name that looks like "_GLOBAL_.I.12345.foo".
References DEFAULT_INIT_PRIORITY, INT_MIN, is_ctor_dtor(), id::name, SYM_AIXD, and SYM_AIXI.
Referenced by sort_ids().
|
static |
Parse a reasonable subset of shell quoting syntax.
References temporary_obstack.
Referenced by main().
int file_exists | ( | const char * | name | ) |
References R_OK.
Referenced by maybe_unlink().
|
static |
Check to make sure the file is an LTO object file.
References LTO_SECTION_NAME_PREFIX, id::name, OFFLOAD_SECTION_NAME_PREFIX, and startswith().
Referenced by is_lto_object_file().
|
static |
Return the kind of symbol denoted by name S.
References names, NULL, SYM_AIXD, SYM_AIXI, SYM_CTOR, SYM_DTOR, SYM_DWEH, SYM_FINI, SYM_INIT, and SYM_REGULAR.
Referenced by extract_init_priority(), and scan_prog_file().
|
static |
References fatal_error(), has_lto_section(), LTO_SEGMENT_NAME, O_BINARY, and O_RDONLY.
Referenced by scan_prog_file().
int main | ( | int | argc, |
char ** | argv ) |
Main program.
We define main() to call toplev::main(), which is defined in toplev.cc. We do this in a separate file in order to allow the language front-end to define a different main(), if it so desires.
References add_prefix(), add_to_list(), at_file_supplied, c_file, c_file_name, collect_atexit(), CONST_CAST2, constructors, debug, destructors, diagnostic_initialize(), DO_COLLECT_EXPORT_LIST, do_collecting, do_link(), dumppfx, error(), extract_string(), fatal_error(), find_a_file(), find_file_set_debug(), fininame, fopen, fork_execute(), frame_tables, gcc_init_libintl, global_dc, helpflag, HOST_EXECUTABLE_SUFFIX, i, initname, input_location, LIBRARY_PATH_ENV, lto_mode, LTO_MODE_LTO, LTO_MODE_NONE, LTO_MODE_WHOPR, maybe_run_lto_and_relink(), maybe_unlink(), id::name, id::next, ngettext, nm_file_name, no_demangle, notice(), notice_translated(), NULL, head::number, o_file, output_file, PASS_FIRST, PASS_OBJ, PASS_SECOND, post_ld_pass(), prefix_from_env(), process_args(), progname, rflag, SCAN_ALL, SCAN_NOTHING, scan_prog_file(), setup_signals(), shared_obj, sort_ids(), startswith(), static_obj, strip_file_name, strip_flag, target_machine, target_system_root, temporary_firstobj, temporary_obstack, verbose, write_c_file(), and X_OK.
|
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 at_file_supplied, collect_execute(), CONST_CAST2, do_wait(), end(), fatal_error(), lto_object_list::first, fork_execute(), free(), gcc_assert, i, input_location, lto_o_files, lto_objects, maybe_unlink_list(), lto_object::name, lto_object::next, NULL, PASS_LTOINFO, post_ld_pass(), SCAN_ALL, scan_prog_file(), temporary_firstobj, and temporary_obstack.
Referenced by main().
void maybe_unlink | ( | const char * | file | ) |
Unlink FILE unless we are debugging or this is the output_file and we may not unlink it.
Referenced by main(), maybe_unlink_list(), and tool_cleanup().
|
static |
Call maybe_unlink on the NULL-terminated list, FILE_LIST.
References maybe_unlink().
Referenced by maybe_run_lto_and_relink(), and tool_cleanup().
void notice_translated | ( | const char * | cmsgid, |
... ) |
Notify user of a non-error, without translating the format string.
References ap, and vfprintf().
Referenced by main().
|
static |
Referenced by main(), and maybe_run_lto_and_relink().
|
static |
Referenced by main(), and ref_maybe_used_by_call_p_1().
|
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.
References _, add_lto_object(), add_to_list(), CONST_CAST2, constructors, debug, destructors, do_wait(), end(), errno, fatal_error(), frame_tables, HOST_BIT_BUCKET, input_location, is_ctor_dtor(), is_lto_object_file(), lto_objects, nm_file_name, NM_FLAGS, NULL, 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 verbose.
Referenced by main(), and maybe_run_lto_and_relink().
|
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, NULL, id::sequence, and sequence_number.
Referenced by main().
void tool_cleanup | ( | bool | from_signal | ) |
Delete tempfiles and exit function.
Referenced by collect_atexit().
|
static |
References id::name, shared_obj, write_c_file_glob(), and write_c_file_stat().
Referenced by main().
|
static |
Write the constructor/destructor tables.
References constructors, destructors, head::first, frame_tables, NAME__MAIN, head::number, write_list(), and write_list_with_asm().
Referenced by write_c_file().
|
static |
Write out the constructor and destructor tables statically (for a shared object), along with the functions to execute them.
References COLLECT_SHARED_FINI_FUNC, COLLECT_SHARED_INIT_FUNC, constructors, debug, destructors, fininame, head::first, frame_tables, free(), initname, notice(), NULL, head::number, output_file, r, shared_obj, SHLIB_SUFFIX, write_list(), and write_list_with_asm().
Referenced by write_c_file().
|
static |
Write: `prefix', the names on list LIST, `suffix'.
References id::next, and id::sequence.
Referenced by write_c_file_glob(), and write_c_file_stat().
|
static |
Added for debugging purpose.
References id::name, id::next, and id::sequence.
Referenced by write_c_file_glob(), and write_c_file_stat().
bool at_file_supplied |
Referenced by do_link(), driver::expand_at_files(), driver::finalize(), main(), and maybe_run_lto_and_relink().
|
static |
Referenced by main(), and tool_cleanup().
const char* c_file_name |
Referenced by main().
|
static |
Referenced by main(), scan_prog_file(), write_c_file_glob(), and write_c_file_stat().
|
static |
Referenced by main(), scan_prog_file(), write_c_file_glob(), and write_c_file_stat().
int do_collecting = 0 |
Referenced by main().
|
static |
Referenced by main(), and write_c_file_stat().
|
static |
Referenced by main(), scan_prog_file(), write_c_file_glob(), and write_c_file_stat().
|
static |
Referenced by main(), and write_c_file_stat().
|
static |
Current LTO mode.
Referenced by main().
|
static |
Referenced by maybe_run_lto_and_relink(), and tool_cleanup().
|
static |
Referenced by maybe_run_lto_and_relink(), and scan_prog_file().
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_link(), and maybe_unlink().
|
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 main().
|
static |
Referenced by main(), and tool_cleanup().
|
static |
|
static |
We maintain two prefix lists: one from COMPILER_PATH environment variable and one from the PATH variable.
Referenced by add_env_var_paths(), add_path(), base_of_path(), check_reduction_path(), diagnostic_execution_path_release(), jt_state::dump(), file_at_path(), get_cycles_count(), get_loop_hot_path(), get_range_query(), is_directory(), fwd_jt_path_registry::lookup_redirection_data(), fwd_jt_path_registry::mark_threaded_blocks(), match_rtx(), matches_main_base(), read_state(), returning_call_p(), hybrid_jt_simplifier::simplify(), and vect_is_simple_reduction().
|
static |
Referenced by main().
|
static |
Referenced by add_to_list(), and sort_ids().
|
static |
Referenced by main(), write_c_file(), and write_c_file_stat().
|
static |
Referenced by main().
|
static |
Referenced by main().
|
static |
Referenced by main().
|
static |
A string that must be prepended to a target OS path in order to find it on the host system.
Referenced by driver::finalize(), main(), driver::maybe_print_and_exit(), and driver::set_up_specs().
char* temporary_firstobj |
Referenced by main(), and maybe_run_lto_and_relink().
struct obstack temporary_obstack |
Referenced by extract_string(), lto_write_options(), main(), maybe_run_lto_and_relink(), and run_gcc().
const char tool_name[] = "collect2" |
Provided by the tool itself.
The name of the tool, printed in error messages.