Run all error handling through an Errors object. Delete output file
[deliverable/binutils-gdb.git] / gold / main.cc
1 // main.cc -- gold main function.
2
3 // Copyright 2006, 2007 Free Software Foundation, Inc.
4 // Written by Ian Lance Taylor <iant@google.com>.
5
6 // This file is part of gold.
7
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 3 of the License, or
11 // (at your option) any later version.
12
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
17
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 // MA 02110-1301, USA.
22
23 #include "gold.h"
24
25 #ifdef HAVE_MALLINFO
26 #include <malloc.h>
27 #endif
28 #include "libiberty.h"
29
30 #include "options.h"
31 #include "parameters.h"
32 #include "errors.h"
33 #include "dirsearch.h"
34 #include "workqueue.h"
35 #include "object.h"
36 #include "symtab.h"
37 #include "layout.h"
38
39 using namespace gold;
40
41 int
42 main(int argc, char** argv)
43 {
44 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
45 setlocale (LC_MESSAGES, "");
46 #endif
47 #if defined (HAVE_SETLOCALE)
48 setlocale (LC_CTYPE, "");
49 #endif
50 bindtextdomain (PACKAGE, LOCALEDIR);
51 textdomain (PACKAGE);
52
53 program_name = argv[0];
54
55 Errors errors(program_name);
56
57 // Handle the command line options.
58 Command_line command_line;
59 command_line.process(argc - 1, argv + 1);
60
61 long start_time = 0;
62 if (command_line.options().print_stats())
63 start_time = get_run_time();
64
65 initialize_parameters(&command_line.options(), &errors);
66
67 // The work queue.
68 Workqueue workqueue(command_line.options());
69
70 // The list of input objects.
71 Input_objects input_objects;
72
73 // The symbol table.
74 Symbol_table symtab;
75
76 // The layout object.
77 Layout layout(command_line.options());
78
79 // Get the search path from the -L options.
80 Dirsearch search_path;
81 search_path.initialize(&workqueue, &command_line.options().search_path());
82
83 // Queue up the first set of tasks.
84 queue_initial_tasks(command_line.options(), search_path,
85 command_line, &workqueue, &input_objects,
86 &symtab, &layout);
87
88 // Run the main task processing loop.
89 workqueue.process();
90
91 if (command_line.options().print_stats())
92 {
93 long run_time = get_run_time() - start_time;
94 fprintf(stderr, _("%s: total run time: %ld.%06ld seconds\n"),
95 program_name, run_time / 1000000, run_time % 1000000);
96 #ifdef HAVE_MALLINFO
97 struct mallinfo m = mallinfo();
98 fprintf(stderr, _("%s: total space allocated by malloc: %d bytes\n"),
99 program_name, m.arena);
100 #endif
101 File_read::print_stats();
102 fprintf(stderr, _("%s: output file size: %lld bytes\n"),
103 program_name, static_cast<long long>(layout.output_file_size()));
104 }
105
106 gold_exit(errors.error_count() == 0);
107 }
This page took 0.032346 seconds and 5 git commands to generate.