Commit | Line | Data |
---|---|---|
5a6f7e2d ILT |
1 | // main.cc -- gold main function. |
2 | ||
6cb15b7f ILT |
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 | ||
5a6f7e2d ILT |
23 | #include "gold.h" |
24 | ||
e44fcf3b ILT |
25 | #ifdef HAVE_MALLINFO |
26 | #include <malloc.h> | |
27 | #endif | |
28 | #include "libiberty.h" | |
29 | ||
5a6f7e2d | 30 | #include "options.h" |
7e1edb90 | 31 | #include "parameters.h" |
5a6f7e2d ILT |
32 | #include "dirsearch.h" |
33 | #include "workqueue.h" | |
34 | #include "object.h" | |
35 | #include "symtab.h" | |
36 | #include "layout.h" | |
37 | ||
38 | using namespace gold; | |
39 | ||
40 | int | |
41 | main(int argc, char** argv) | |
42 | { | |
43 | #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES) | |
44 | setlocale (LC_MESSAGES, ""); | |
45 | #endif | |
46 | #if defined (HAVE_SETLOCALE) | |
47 | setlocale (LC_CTYPE, ""); | |
48 | #endif | |
49 | bindtextdomain (PACKAGE, LOCALEDIR); | |
50 | textdomain (PACKAGE); | |
51 | ||
52 | program_name = argv[0]; | |
53 | ||
54 | // Handle the command line options. | |
55 | Command_line command_line; | |
56 | command_line.process(argc - 1, argv + 1); | |
e44fcf3b ILT |
57 | |
58 | long start_time = 0; | |
59 | if (command_line.options().print_stats()) | |
60 | start_time = get_run_time(); | |
61 | ||
7e1edb90 | 62 | initialize_parameters(&command_line.options()); |
5a6f7e2d ILT |
63 | |
64 | // The work queue. | |
65 | Workqueue workqueue(command_line.options()); | |
66 | ||
67 | // The list of input objects. | |
68 | Input_objects input_objects; | |
69 | ||
70 | // The symbol table. | |
71 | Symbol_table symtab; | |
72 | ||
73 | // The layout object. | |
74 | Layout layout(command_line.options()); | |
75 | ||
76 | // Get the search path from the -L options. | |
77 | Dirsearch search_path; | |
ad2d6943 | 78 | search_path.initialize(&workqueue, &command_line.options().search_path()); |
5a6f7e2d ILT |
79 | |
80 | // Queue up the first set of tasks. | |
81 | queue_initial_tasks(command_line.options(), search_path, | |
82 | command_line, &workqueue, &input_objects, | |
83 | &symtab, &layout); | |
84 | ||
85 | // Run the main task processing loop. | |
86 | workqueue.process(); | |
87 | ||
e44fcf3b ILT |
88 | if (command_line.options().print_stats()) |
89 | { | |
90 | long run_time = get_run_time() - start_time; | |
91 | fprintf(stderr, _("%s: total run time: %ld.%06ld seconds\n"), | |
92 | program_name, run_time / 1000000, run_time % 1000000); | |
93 | #ifdef HAVE_MALLINFO | |
94 | struct mallinfo m = mallinfo(); | |
95 | fprintf(stderr, _("%s: total space allocated by malloc: %d bytes\n"), | |
96 | program_name, m.arena); | |
97 | #endif | |
98 | File_read::print_stats(); | |
99 | fprintf(stderr, _("%s: output file size: %lld bytes\n"), | |
100 | program_name, static_cast<long long>(layout.output_file_size())); | |
101 | } | |
102 | ||
5a6f7e2d ILT |
103 | gold_exit(true); |
104 | } |