|
GCC Middle and Back End API Reference
|
#include "config.h"#include "system.h"#include "coretypes.h"#include "intl.h"#include "diagnostic.h"#include "obstack.h"#include "opts.h"#include "options.h"#include "simple-object.h"#include "lto-section-names.h"#include "collect-utils.h"#include "opts-diagnostic.h"#include "opt-suggestions.h"#include "opts-jobserver.h"#include "lto-ltrans-cache.h"
Data Structures | |
| class | lto_diagnostic_option_id_manager |
Macros | |
| #define | INCLUDE_STRING |
| #define | INCLUDE_ARRAY |
| #define | INCLUDE_MAP |
| #define | INCLUDE_VECTOR |
| #define | OFFLOAD_TARGET_NAMES_ENV "OFFLOAD_TARGET_NAMES" |
| #define | OFFLOAD_TARGET_DEFAULT_ENV "OFFLOAD_TARGET_DEFAULT" |
| #define | TARGET_EXECUTABLE_SUFFIX "" |
| #define | DUMPBASE_SUFFIX "ltrans18446744073709551615" |
Enumerations | |
| enum | lto_mode_d { LTO_MODE_NONE , LTO_MODE_LTO , LTO_MODE_WHOPR } |
Functions | |
| static void ** | free_array_of_ptrs (void **ptr, unsigned n) |
| void | tool_cleanup (bool) |
| static void | lto_wrapper_cleanup (void) |
| void | maybe_unlink (const char *file) |
| static vec< cl_decoded_option > | get_options_from_collect_gcc_options (const char *collect_gcc, const char *collect_gcc_options) |
| static int | find_option (vec< cl_decoded_option > &options, size_t opt_index, unsigned start=0) |
| static int | find_option (vec< cl_decoded_option > &options, cl_decoded_option *option) |
| static void | merge_flto_options (vec< cl_decoded_option > &decoded_options, cl_decoded_option *foption, bool force) |
| static void | merge_and_complain (vec< cl_decoded_option > &decoded_options, vec< cl_decoded_option > fdecoded_options, vec< cl_decoded_option > decoded_cl_options) |
| static unsigned | parse_env_var (const char *str, char ***pvalues, const char *append) |
| static void | append_compiler_options (obstack *argv_obstack, vec< cl_decoded_option > opts) |
| static void | append_diag_options (obstack *argv_obstack, vec< cl_decoded_option > opts) |
| static void | append_linker_options (obstack *argv_obstack, vec< cl_decoded_option > opts) |
| static void | append_offload_options (obstack *argv_obstack, const char *target, vec< cl_decoded_option > options) |
| static int | access_check (const char *name, int mode) |
| static const char * | compile_offload_image (const char *target, const char *compiler_path, unsigned in_argc, char *in_argv[], vec< cl_decoded_option > compiler_opts, vec< cl_decoded_option > linker_opts, char **filename) |
| static void | compile_images_for_offload_targets (unsigned in_argc, char *in_argv[], vec< cl_decoded_option > compiler_opts, vec< cl_decoded_option > linker_opts) |
| static void | copy_file (const char *dest, const char *src) |
| static void | find_crtoffloadtable (int save_tempssave_temps, bool pie_or_shared, const char *dumppfx) |
| static bool | find_and_merge_options (int fd, off_t file_offset, const char *prefix, vec< cl_decoded_option > decoded_cl_options, bool first, vec< cl_decoded_option > *opts, const char *collect_gcc) |
| const char * | debug_objcopy (const char *infile, bool rename) |
| int | cmp_priority (const void *a, const void *b) |
| static void | init_num_threads (void) |
| void | print_lto_docs_link () |
| static bool | make_exists (void) |
| static void | run_gcc (unsigned argc, char *argv[]) |
| int | main (int argc, char *argv[]) |
Variables | |
| static enum lto_mode_d | lto_mode = LTO_MODE_NONE |
| static char * | ltrans_output_file |
| static char * | flto_out |
| static unsigned int | nr |
| static int * | ltrans_priorities |
| static char ** | input_names |
| static char const ** | output_names |
| static char ** | offload_names |
| static char * | offload_objects_file_name |
| static char * | makefile |
| static unsigned int | num_deb_objs |
| static const char ** | early_debug_object_names |
| static bool | xassembler_options_error = false |
| const char | tool_name [] = "lto-wrapper" |
| static unsigned long | nthreads_var = 0 |
| #define DUMPBASE_SUFFIX "ltrans18446744073709551615" |
Template of LTRANS dumpbase suffix.
Referenced by run_gcc().
| #define INCLUDE_ARRAY |
| #define INCLUDE_MAP |
| #define INCLUDE_STRING |
Wrapper to call lto. Used by collect2 and the linker plugin. Copyright (C) 2009-2026 Free Software Foundation, Inc. Factored out of collect2 by Rafael Espindola <espindola@google.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/>.
This program is passed a gcc, a list of gcc arguments and a list of object files containing IL. It scans the argument list to check if we are in whopr mode or not modifies the arguments and needed and prints a list of output files on stdout. Example: $ lto-wrapper gcc/xgcc -B gcc a.o b.o -o test -flto The above will print something like /tmp/ccwbQ8B2.lto.o If WHOPR is used instead, more than one file might be produced ./ccXj2DTk.lto.ltrans.o ./ccCJuXGv.lto.ltrans.o
| #define INCLUDE_VECTOR |
| #define OFFLOAD_TARGET_DEFAULT_ENV "OFFLOAD_TARGET_DEFAULT" |
Referenced by compile_offload_image().
| #define OFFLOAD_TARGET_NAMES_ENV "OFFLOAD_TARGET_NAMES" |
Environment variable, used for passing the names of offload targets from GCC driver to lto-wrapper.
Referenced by compile_images_for_offload_targets().
| #define TARGET_EXECUTABLE_SUFFIX "" |
By default there is no special suffix for target executables.
| enum lto_mode_d |
|
static |
Check whether NAME can be accessed in MODE. This is like access, except that it never considers directories to be executable.
References access_check(), S_ISDIR, and X_OK.
Referenced by access_check(), compile_offload_image(), and find_crtoffloadtable().
|
static |
Append options OPTS from lto or offload_lto sections to ARGV_OBSTACK.
References append_compiler_options(), cl_decoded_option::canonical_option, cl_decoded_option::canonical_option_num_elements, cl_options, CL_TARGET, cl_option::flags, i, cl_decoded_option::opt_index, and xassembler_options_error.
Referenced by append_compiler_options(), compile_offload_image(), and run_gcc().
|
static |
Append diag options in OPTS to ARGV_OBSTACK.
References append_diag_options(), cl_decoded_option::canonical_option, cl_decoded_option::canonical_option_num_elements, i, and cl_decoded_option::opt_index.
Referenced by append_diag_options(), and compile_offload_image().
|
static |
Append linker options OPTS to ARGV_OBSTACK.
References append_linker_options(), cl_decoded_option::canonical_option, cl_decoded_option::canonical_option_num_elements, CL_COMMON, CL_DRIVER, cl_options, CL_TARGET, cl_option::flags, i, cl_decoded_option::opt_index, and cl_decoded_option::value.
Referenced by append_linker_options(), and run_gcc().
|
static |
Extract options for TARGET offload compiler from OPTIONS and append them to ARGV_OBSTACK.
References append_offload_options(), cl_decoded_option::arg, gcc_assert, i, NULL, and cl_decoded_option::opt_index.
Referenced by append_offload_options(), and compile_offload_image().
| int cmp_priority | ( | const void * | a, |
| const void * | b ) |
Helper for qsort: compare priorities for parallel compilation.
References a, b, and cmp_priority().
Referenced by cmp_priority(), and run_gcc().
|
static |
The main routine dealing with offloading. The routine builds a target image for each offload target. IN_ARGC and IN_ARGV specify options and input object files. As all of them could contain target sections, we pass them all to target compilers.
References compile_images_for_offload_targets(), compile_offload_image(), fatal_error(), free(), free_array_of_ptrs(), i, input_location, NULL, offload_names, OFFLOAD_TARGET_NAMES_ENV, and parse_env_var().
Referenced by compile_images_for_offload_targets(), and run_gcc().
|
static |
Prepare a target image for offload TARGET, using mkoffload tool from COMPILER_PATH. Return the name of the resultant object file.
References access_check(), append_compiler_options(), append_diag_options(), append_offload_options(), compile_offload_image(), dumppfx, fatal_error(), fork_execute(), free_array_of_ptrs(), i, input_location, NULL, OFFLOAD_TARGET_DEFAULT_ENV, parse_env_var(), verbose, and X_OK.
Referenced by compile_images_for_offload_targets(), and compile_offload_image().
|
static |
Copy a file from SRC to DEST.
References copy_file(), fatal_error(), fopen, and input_location.
Referenced by copy_file(), and find_crtoffloadtable().
| const char * debug_objcopy | ( | const char * | infile, |
| bool | rename ) |
Copy early debug info sections from INFILE to a new file whose name is returned. Return NULL on error.
References debug_objcopy(), fatal_error(), NULL, O_BINARY, O_RDONLY, and PRIi64.
Referenced by debug_objcopy(), and run_gcc().
|
static |
A subroutine of run_gcc. Examine the open file FD for lto sections with name prefix PREFIX, at FILE_OFFSET, and store any options we find in OPTS. Return true if we found a matching section, false otherwise. COLLECT_GCC holds the value of the environment variable with the same name.
References find_and_merge_options(), free(), get_options_from_collect_gcc_options(), merge_and_complain(), and SEEK_SET.
Referenced by find_and_merge_options(), and run_gcc().
|
static |
Find the crtoffloadtable.o file in LIBRARY_PATH, make copy and pass name of the copy to the linker.
References access_check(), copy_file(), dumppfx, fatal_error(), find_crtoffloadtable(), free_array_of_ptrs(), i, input_location, NULL, parse_env_var(), and R_OK.
Referenced by find_crtoffloadtable(), and run_gcc().
|
static |
References find_option(), and cl_decoded_option::opt_index.
|
static |
Find option in OPTIONS based on OPT_INDEX, starting at START. -1 value is returned if the option is not present.
References find_option(), and i.
Referenced by find_option(), find_option(), merge_and_complain(), and merge_flto_options().
|
static |
Auxiliary function that frees elements of PTR and PTR itself. N is number of elements to be freed. If PTR is NULL, nothing is freed. If an element is NULL, subsequent elements are not freed.
References free(), free_array_of_ptrs(), i, and NULL.
Referenced by compile_images_for_offload_targets(), compile_offload_image(), find_crtoffloadtable(), free_array_of_ptrs(), run_gcc(), and tool_cleanup().
|
static |
Create decoded options from the COLLECT_GCC and COLLECT_GCC_OPTIONS environment.
References CL_DRIVER, decode_cmdline_options_to_array(), free(), get_options_from_collect_gcc_options(), i, NULL, and parse_options_from_collect_gcc_options().
Referenced by find_and_merge_options(), get_options_from_collect_gcc_options(), and run_gcc().
|
static |
At startup, determine the default number of threads. It would seem this should be related to the number of cpus online.
References free(), i, init_num_threads(), nthreads_var, and NULL.
Referenced by init_num_threads(), and run_gcc().
|
static |
References lto_wrapper_cleanup(), and utils_cleanup().
Referenced by lto_wrapper_cleanup(), and main().
| int main | ( | int | argc, |
| char * | argv[] ) |
|
static |
Test that a make command is present and working, return true if so.
References make_exists(), and NULL.
Referenced by make_exists(), and run_gcc().
| void maybe_unlink | ( | const char * | file | ) |
Unlink a temporary LTRANS file unless requested otherwise.
Unlink FILE unless we are debugging or this is the output_file and we may not unlink it.
References errno, fatal_error(), file_exists(), input_location, may_unlink_output_file, maybe_unlink(), notice(), output_file, and verbose.
Referenced by main(), maybe_unlink(), maybe_unlink(), maybe_unlink_list(), run_gcc(), and tool_cleanup().
|
static |
Try to merge and complain about options FDECODED_OPTIONS when applied on top of DECODED_OPTIONS.
References cl_decoded_option::arg, CF_BRANCH, CF_CHECK, CF_FULL, CF_NONE, CF_RETURN, cl_options, CL_TARGET, fatal_error(), find_option(), cl_option::flags, gcc_unreachable, i, input_location, MAX, merge_and_complain(), merge_flto_options(), NULL, cl_decoded_option::opt_index, cl_decoded_option::orig_option_with_args_text, cl_decoded_option::value, warning(), and xassembler_options_error.
Referenced by find_and_merge_options(), and merge_and_complain().
|
static |
Merge -flto FOPTION into vector of DECODED_OPTIONS. If FORCE is true then FOPTION overrides previous settings.
References cl_decoded_option::arg, find_option(), and merge_flto_options().
Referenced by merge_and_complain(), merge_flto_options(), and run_gcc().
|
static |
Parse STR, saving found tokens into PVALUES and return their number. Tokens are assumed to be delimited by ':'. If APPEND is non-null, append it to every token we find.
References i, NULL, and parse_env_var().
Referenced by compile_images_for_offload_targets(), compile_offload_image(), find_crtoffloadtable(), and parse_env_var().
| void print_lto_docs_link | ( | ) |
Print link to -flto documentation with a hint message.
References diagnostics::context::get_option_url(), global_dc, inform(), print_lto_docs_link(), and UNKNOWN_LOCATION.
Referenced by print_lto_docs_link(), and run_gcc().
|
static |
Execute gcc. ARGC is the number of arguments. ARGV contains the arguments.
References ltrans_file_cache::add_to_cache(), append_compiler_options(), append_linker_options(), cl_decoded_option::arg, cmp_priority(), collect_execute(), compile_images_for_offload_targets(), ltrans_file_cache::creation_lock, debug_objcopy(), ltrans_file_cache::deletion_lock, diagnostic_color_init(), diagnostic_urls_init(), DIR_SEPARATOR, do_wait(), DUMPBASE_SUFFIX, dumppfx, early_debug_object_names, jobserver_info::error_msg, fatal_error(), find_and_merge_options(), find_crtoffloadtable(), flto_out, fopen, fork_execute(), fputc(), free(), free_array_of_ptrs(), gcc_assert, ltrans_file_cache::get_item(), get_options_from_collect_gcc_options(), global_dc, HOST_BIT_BUCKET, i, init_num_threads(), ltrans_file_cache::item::input, input_location, input_names, jobserver_info::is_active, ltrans_file_cache::load_cache(), ltrans_file_cache::item::lock, lockfile::lock_read(), lockfile::lock_write(), lockfile::lockfile_supported(), lto_mode, LTO_MODE_LTO, LTO_MODE_WHOPR, LTO_SECTION_NAME_PREFIX, ltrans_output_file, ltrans_priorities, make_exists(), makefile, maybe_unlink(), merge_flto_options(), nr, nthreads_var, NULL, num_deb_objs, O_BINARY, O_RDONLY, offload_names, offload_objects_file_name, OFFLOAD_SECTION_NAME_PREFIX, cl_decoded_option::opt_index, ltrans_file_cache::item::output, output_names, prepend_xassembler_to_collect_as_options(), PRIi64, print_lto_docs_link(), qsort, read_collect_gcc_options(), run_gcc(), ltrans_file_cache::save_cache(), diagnostics::context::set_show_highlight_colors(), startswith(), TARGET_EXECUTABLE_SUFFIX, temporary_obstack, ltrans_file_cache::try_prune(), lockfile::unlock(), cl_decoded_option::value, verbose, vNULL, W_OK, and warning().
| void tool_cleanup | ( | bool | from_signal | ) |
Delete tempfiles. Called from utils_cleanup.
Called by utils_cleanup.
Delete tempfiles and exit function.
References c_file, early_debug_object_names, flto_out, free_array_of_ptrs(), i, input_names, lto_o_files, ltrans_output_file, makefile, maybe_unlink(), maybe_unlink_list(), nr, num_deb_objs, o_file, offload_names, offload_objects_file_name, output_names, tool_cleanup(), and verbose.
Referenced by collect_atexit(), tool_cleanup(), and utils_cleanup().
|
static |
Referenced by run_gcc(), and tool_cleanup().
|
static |
Referenced by run_gcc(), and tool_cleanup().
|
static |
Referenced by run_gcc(), and tool_cleanup().
|
static |
Current LTO mode.
Referenced by run_gcc().
|
static |
Referenced by run_gcc(), and tool_cleanup().
|
static |
Referenced by run_gcc().
|
static |
Referenced by run_gcc(), and tool_cleanup().
|
static |
Referenced by run_gcc(), and tool_cleanup().
|
static |
Number of CPUs that can be used for parallel LTRANS phase.
Referenced by init_num_threads(), and run_gcc().
|
static |
Referenced by run_gcc(), and tool_cleanup().
|
static |
Referenced by compile_images_for_offload_targets(), run_gcc(), and tool_cleanup().
|
static |
Referenced by run_gcc(), and tool_cleanup().
|
static |
Referenced by run_gcc(), and tool_cleanup().
| const char tool_name[] = "lto-wrapper" |
Provided by the tool itself.
The name of the tool, printed in error messages.
Referenced by diagnostic_finish_va(), diagnostic_finish_via_msg_buf(), and read_collect_gcc_options().
Referenced by append_compiler_options(), and merge_and_complain().