X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=gold%2Fmain.cc;h=cc86352a96ca44e5fd99226795dcba2d9ed7bbfa;hb=f5a7c406b1975cde626efed526960f2cf1bdaceb;hp=2fc9439f473d3bd0ef38438ecbce3cbd695dd2da;hpb=8851eccaec28f25f56fab5ba5d8ae44f71729975;p=deliverable%2Fbinutils-gdb.git diff --git a/gold/main.cc b/gold/main.cc index 2fc9439f47..cc86352a96 100644 --- a/gold/main.cc +++ b/gold/main.cc @@ -1,6 +1,6 @@ // main.cc -- gold main function. -// Copyright 2006, 2007, 2008 Free Software Foundation, Inc. +// Copyright (C) 2006-2020 Free Software Foundation, Inc. // Written by Ian Lance Taylor . // This file is part of gold. @@ -22,20 +22,33 @@ #include "gold.h" +#include +#include + #ifdef HAVE_MALLINFO #include #endif + #include "libiberty.h" #include "script.h" #include "options.h" +#include "target-select.h" #include "parameters.h" #include "errors.h" +#include "mapfile.h" #include "dirsearch.h" #include "workqueue.h" #include "object.h" +#include "archive.h" #include "symtab.h" #include "layout.h" +#include "plugin.h" +#include "gc.h" +#include "icf.h" +#include "incremental.h" +#include "gdb-index.h" +#include "timer.h" using namespace gold; @@ -125,13 +138,13 @@ int main(int argc, char** argv) { #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES) - setlocale (LC_MESSAGES, ""); + setlocale(LC_MESSAGES, ""); #endif #if defined (HAVE_SETLOCALE) - setlocale (LC_CTYPE, ""); + setlocale(LC_CTYPE, ""); #endif - bindtextdomain (PACKAGE, LOCALEDIR); - textdomain (PACKAGE); + bindtextdomain(PACKAGE, LOCALEDIR); + textdomain(PACKAGE); program_name = argv[0]; @@ -149,11 +162,14 @@ main(int argc, char** argv) // Handle the command line options. Command_line command_line; - command_line.process(argc - 1, argv + 1); + command_line.process(argc - 1, const_cast(argv + 1)); - long start_time = 0; - if (command_line.options().print_stats()) - start_time = get_run_time(); + Timer timer; + if (command_line.options().stats()) + { + timer.start(); + set_parameters_timer(&timer); + } // Store some options in the globally accessible parameters. set_parameters_options(&command_line.options()); @@ -162,6 +178,18 @@ main(int argc, char** argv) write_debug_script(command_line.options().output_file_name(), program_name, args.c_str()); + // If the user asked for a map file, open it. + Mapfile* mapfile = NULL; + if (command_line.options().user_set_Map()) + { + mapfile = new Mapfile(); + if (!mapfile->open(command_line.options().Map())) + { + delete mapfile; + mapfile = NULL; + } + } + // The GNU linker ignores version scripts when generating // relocatable output. If we are not compatible, then we break the // Linux kernel build, which uses a linker script with -r which must @@ -178,44 +206,127 @@ main(int argc, char** argv) // The list of input objects. Input_objects input_objects; + // The Garbage Collection (GC, --gc-sections) Object. + Garbage_collection gc; + + // The Identical Code Folding (ICF, --icf) Object. + Icf icf; + // The symbol table. We're going to guess here how many symbols // we're going to see based on the number of input files. Even when // this is off, it means at worst we don't quite optimize hashtable - // resizing as well as we could have (perhap using more memory). + // resizing as well as we could have (perhaps using more memory). Symbol_table symtab(command_line.number_of_input_files() * 1024, command_line.version_script()); + if (parameters->options().gc_sections()) + symtab.set_gc(&gc); + + if (parameters->options().icf_enabled()) + symtab.set_icf(&icf); + // The layout object. - Layout layout(command_line.options(), &command_line.script_options()); + Layout layout(command_line.number_of_input_files(), + &command_line.script_options()); + + if (layout.incremental_inputs() != NULL) + layout.incremental_inputs()->report_command_line(argc, argv); + + if (parameters->options().section_ordering_file()) + layout.read_layout_from_file(); + + // Load plugin libraries. + if (command_line.options().has_plugins()) + command_line.options().plugins()->load_plugins(&layout); // Get the search path from the -L options. Dirsearch search_path; - search_path.initialize(&workqueue, &command_line.options().search_path()); + search_path.initialize(&workqueue, &command_line.options().library_path()); // Queue up the first set of tasks. queue_initial_tasks(command_line.options(), search_path, command_line, &workqueue, &input_objects, - &symtab, &layout); + &symtab, &layout, mapfile); // Run the main task processing loop. workqueue.process(0); - if (command_line.options().print_stats()) + if (command_line.options().print_output_format()) + print_output_format(); + + if (command_line.options().stats()) { - long run_time = get_run_time() - start_time; - fprintf(stderr, _("%s: total run time: %ld.%06ld seconds\n"), - program_name, run_time / 1000000, run_time % 1000000); + timer.stamp(2); + Timer::TimeStats elapsed = timer.get_pass_time(0); + fprintf(stderr, + _("%s: initial tasks run time: " \ + "(user: %ld.%06ld sys: %ld.%06ld wall: %ld.%06ld)\n"), + program_name, + elapsed.user / 1000, (elapsed.user % 1000) * 1000, + elapsed.sys / 1000, (elapsed.sys % 1000) * 1000, + elapsed.wall / 1000, (elapsed.wall % 1000) * 1000); + elapsed = timer.get_pass_time(1); + fprintf(stderr, + _("%s: middle tasks run time: " \ + "(user: %ld.%06ld sys: %ld.%06ld wall: %ld.%06ld)\n"), + program_name, + elapsed.user / 1000, (elapsed.user % 1000) * 1000, + elapsed.sys / 1000, (elapsed.sys % 1000) * 1000, + elapsed.wall / 1000, (elapsed.wall % 1000) * 1000); + elapsed = timer.get_pass_time(2); + fprintf(stderr, + _("%s: final tasks run time: " \ + "(user: %ld.%06ld sys: %ld.%06ld wall: %ld.%06ld)\n"), + program_name, + elapsed.user / 1000, (elapsed.user % 1000) * 1000, + elapsed.sys / 1000, (elapsed.sys % 1000) * 1000, + elapsed.wall / 1000, (elapsed.wall % 1000) * 1000); + elapsed = timer.get_elapsed_time(); + fprintf(stderr, + _("%s: total run time: " \ + "(user: %ld.%06ld sys: %ld.%06ld wall: %ld.%06ld)\n"), + program_name, + elapsed.user / 1000, (elapsed.user % 1000) * 1000, + elapsed.sys / 1000, (elapsed.sys % 1000) * 1000, + elapsed.wall / 1000, (elapsed.wall % 1000) * 1000); + #ifdef HAVE_MALLINFO struct mallinfo m = mallinfo(); - fprintf(stderr, _("%s: total space allocated by malloc: %d bytes\n"), - program_name, m.arena); + fprintf(stderr, _("%s: total space allocated by malloc: %lld bytes\n"), + program_name, static_cast(m.arena)); #endif File_read::print_stats(); + Archive::print_stats(); + Lib_group::print_stats(); fprintf(stderr, _("%s: output file size: %lld bytes\n"), program_name, static_cast(layout.output_file_size())); symtab.print_stats(); layout.print_stats(); + Gdb_index::print_stats(); + Free_list::print_stats(); } - gold_exit(errors.error_count() == 0); + // Issue defined symbol report. + if (command_line.options().user_set_print_symbol_counts()) + input_objects.print_symbol_counts(&symtab); + + // Output cross reference table. + if (command_line.options().cref()) + input_objects.print_cref(&symtab, + mapfile == NULL ? stdout : mapfile->file()); + + if (mapfile != NULL) + mapfile->close(); + + if (parameters->options().fatal_warnings() + && errors.warning_count() > 0 + && errors.error_count() == 0) + gold_error("treating warnings as errors"); + + // If the user used --noinhibit-exec, we force the exit status to be + // successful. This is compatible with GNU ld. + gold_exit((errors.error_count() == 0 + || parameters->options().noinhibit_exec()) + ? GOLD_OK + : GOLD_ERR); }