2009-01-20 Sriraman Tallam <tmsriram@google.com>
[deliverable/binutils-gdb.git] / gold / main.cc
index 6e356581701d89230750487d6dc086622517c20b..00198639aa328759e96e6af5d36510bfb53be0a2 100644 (file)
@@ -1,6 +1,6 @@
 // main.cc -- gold main function.
 
-// Copyright 2006, 2007, 2008 Free Software Foundation, Inc.
+// Copyright 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
 // Written by Ian Lance Taylor <iant@google.com>.
 
 // This file is part of gold.
 
 #include "gold.h"
 
+#include <cstdio>
+#include <cstring>
+
 #ifdef HAVE_MALLINFO
 #include <malloc.h>
 #endif
+
 #include "libiberty.h"
 
 #include "script.h"
 #include "options.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"
 
 using namespace gold;
 
@@ -145,27 +153,35 @@ main(int argc, char** argv)
 
   // Initialize the global parameters, to let random code get to the
   // errors object.
-  initialize_parameters(&errors);
-
-  // Options which may be set by the command line or by linker
-  // scripts.
-  Script_options script_options;
+  set_parameters_errors(&errors);
 
   // Handle the command line options.
-  Command_line command_line(&script_options);
-  command_line.process(argc - 1, argv + 1);
+  Command_line command_line;
+  command_line.process(argc - 1, const_cast<const char**>(argv + 1));
 
   long start_time = 0;
-  if (command_line.options().print_stats())
+  if (command_line.options().stats())
     start_time = get_run_time();
 
   // Store some options in the globally accessible parameters.
-  set_parameters_from_options(&command_line.options());
+  set_parameters_options(&command_line.options());
 
   // Do this as early as possible (since it prints a welcome message).
   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
@@ -173,8 +189,12 @@ main(int argc, char** argv)
   // permit symbols to be forced local with -r, though, as it would
   // permit some linker optimizations.  Perhaps we need yet another
   // option to control this.  FIXME.
-  if (parameters->output_is_object())
-    command_line.script_options()->version_script_info()->clear();
+  if (parameters->options().relocatable())
+    command_line.script_options().version_script_info()->clear();
+
+  // Load plugin libraries.
+  if (command_line.options().has_plugins())
+    command_line.options().plugins()->load_plugins();
 
   // The work queue.
   Workqueue workqueue(command_line.options());
@@ -182,29 +202,35 @@ main(int argc, char** argv)
   // The list of input objects.
   Input_objects input_objects;
 
+  // The Garbage Collection Object.
+  Garbage_collection gc;
+
   // 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).
   Symbol_table symtab(command_line.number_of_input_files() * 1024,
-                      command_line.options().version_script());
+                      command_line.version_script());
+
+  if (parameters->options().gc_sections())
+    symtab.set_gc(&gc);
 
   // The layout object.
-  Layout layout(command_line.options(), &script_options);
+  Layout layout(command_line.options(), &command_line.script_options());
 
   // 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().stats())
     {
       long run_time = get_run_time() - start_time;
       fprintf(stderr, _("%s: total run time: %ld.%06ld seconds\n"),
@@ -215,11 +241,27 @@ main(int argc, char** argv)
              program_name, m.arena);
 #endif
       File_read::print_stats();
+      Archive::print_stats();
       fprintf(stderr, _("%s: output file size: %lld bytes\n"),
              program_name, static_cast<long long>(layout.output_file_size()));
       symtab.print_stats();
       layout.print_stats();
     }
 
-  gold_exit(errors.error_count() == 0);
+  if (mapfile != NULL)
+    mapfile->close();
+
+  // Issue defined symbol report.
+  if (command_line.options().user_set_print_symbol_counts())
+    input_objects.print_symbol_counts(&symtab);
+
+  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());
 }
This page took 0.035211 seconds and 4 git commands to generate.