Commit | Line | Data |
---|---|---|
5a6f7e2d ILT |
1 | // main.cc -- gold main function. |
2 | ||
e5756efb | 3 | // Copyright 2006, 2007, 2008 Free Software Foundation, Inc. |
6cb15b7f ILT |
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 | ||
e5756efb | 30 | #include "script.h" |
5a6f7e2d | 31 | #include "options.h" |
7e1edb90 | 32 | #include "parameters.h" |
75f2446e | 33 | #include "errors.h" |
5a6f7e2d ILT |
34 | #include "dirsearch.h" |
35 | #include "workqueue.h" | |
36 | #include "object.h" | |
37 | #include "symtab.h" | |
38 | #include "layout.h" | |
39 | ||
40 | using namespace gold; | |
41 | ||
42 | int | |
43 | main(int argc, char** argv) | |
44 | { | |
45 | #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES) | |
46 | setlocale (LC_MESSAGES, ""); | |
47 | #endif | |
48 | #if defined (HAVE_SETLOCALE) | |
49 | setlocale (LC_CTYPE, ""); | |
50 | #endif | |
51 | bindtextdomain (PACKAGE, LOCALEDIR); | |
52 | textdomain (PACKAGE); | |
53 | ||
54 | program_name = argv[0]; | |
55 | ||
75f2446e ILT |
56 | Errors errors(program_name); |
57 | ||
3c2fafa5 ILT |
58 | // Initialize the global parameters, to let random code get to the |
59 | // errors object. | |
60 | initialize_parameters(&errors); | |
61 | ||
e5756efb ILT |
62 | // Options which may be set by the command line or by linker |
63 | // scripts. | |
64 | Script_options script_options; | |
65 | ||
5a6f7e2d | 66 | // Handle the command line options. |
e5756efb | 67 | Command_line command_line(&script_options); |
5a6f7e2d | 68 | command_line.process(argc - 1, argv + 1); |
e44fcf3b ILT |
69 | |
70 | long start_time = 0; | |
71 | if (command_line.options().print_stats()) | |
72 | start_time = get_run_time(); | |
73 | ||
3c2fafa5 ILT |
74 | // Store some options in the globally accessible parameters. |
75 | set_parameters_from_options(&command_line.options()); | |
5a6f7e2d ILT |
76 | |
77 | // The work queue. | |
78 | Workqueue workqueue(command_line.options()); | |
79 | ||
80 | // The list of input objects. | |
81 | Input_objects input_objects; | |
82 | ||
6d013333 ILT |
83 | // The symbol table. We're going to guess here how many symbols |
84 | // we're going to see based on the number of input files. Even when | |
85 | // this is off, it means at worse we don't quite optimize hashtable | |
86 | // resizing as well as we could have (perhap using more memory). | |
87 | Symbol_table symtab(command_line.number_of_input_files() * 1024); | |
5a6f7e2d ILT |
88 | |
89 | // The layout object. | |
e5756efb | 90 | Layout layout(command_line.options(), &script_options); |
5a6f7e2d ILT |
91 | |
92 | // Get the search path from the -L options. | |
93 | Dirsearch search_path; | |
ad2d6943 | 94 | search_path.initialize(&workqueue, &command_line.options().search_path()); |
5a6f7e2d ILT |
95 | |
96 | // Queue up the first set of tasks. | |
97 | queue_initial_tasks(command_line.options(), search_path, | |
98 | command_line, &workqueue, &input_objects, | |
99 | &symtab, &layout); | |
100 | ||
101 | // Run the main task processing loop. | |
17a1d0a9 | 102 | workqueue.process(0); |
5a6f7e2d | 103 | |
e44fcf3b ILT |
104 | if (command_line.options().print_stats()) |
105 | { | |
106 | long run_time = get_run_time() - start_time; | |
107 | fprintf(stderr, _("%s: total run time: %ld.%06ld seconds\n"), | |
108 | program_name, run_time / 1000000, run_time % 1000000); | |
109 | #ifdef HAVE_MALLINFO | |
110 | struct mallinfo m = mallinfo(); | |
111 | fprintf(stderr, _("%s: total space allocated by malloc: %d bytes\n"), | |
112 | program_name, m.arena); | |
113 | #endif | |
114 | File_read::print_stats(); | |
115 | fprintf(stderr, _("%s: output file size: %lld bytes\n"), | |
116 | program_name, static_cast<long long>(layout.output_file_size())); | |
abaa3995 | 117 | symtab.print_stats(); |
ad8f37d1 | 118 | layout.print_stats(); |
e44fcf3b ILT |
119 | } |
120 | ||
75f2446e | 121 | gold_exit(errors.error_count() == 0); |
5a6f7e2d | 122 | } |