1 // main.cc -- gold main function.
3 // Copyright 2006, 2007 Free Software Foundation, Inc.
4 // Written by Ian Lance Taylor <iant@google.com>.
6 // This file is part of gold.
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.
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.
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.
28 #include "libiberty.h"
31 #include "parameters.h"
33 #include "dirsearch.h"
34 #include "workqueue.h"
42 main(int argc
, char** argv
)
44 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
45 setlocale (LC_MESSAGES
, "");
47 #if defined (HAVE_SETLOCALE)
48 setlocale (LC_CTYPE
, "");
50 bindtextdomain (PACKAGE
, LOCALEDIR
);
53 program_name
= argv
[0];
55 Errors
errors(program_name
);
57 // Initialize the global parameters, to let random code get to the
59 initialize_parameters(&errors
);
61 // Handle the command line options.
62 Command_line command_line
;
63 command_line
.process(argc
- 1, argv
+ 1);
66 if (command_line
.options().print_stats())
67 start_time
= get_run_time();
69 // Store some options in the globally accessible parameters.
70 set_parameters_from_options(&command_line
.options());
73 Workqueue
workqueue(command_line
.options());
75 // The list of input objects.
76 Input_objects input_objects
;
82 Layout
layout(command_line
.options());
84 // Get the search path from the -L options.
85 Dirsearch search_path
;
86 search_path
.initialize(&workqueue
, &command_line
.options().search_path());
88 // Queue up the first set of tasks.
89 queue_initial_tasks(command_line
.options(), search_path
,
90 command_line
, &workqueue
, &input_objects
,
93 // Run the main task processing loop.
96 if (command_line
.options().print_stats())
98 long run_time
= get_run_time() - start_time
;
99 fprintf(stderr
, _("%s: total run time: %ld.%06ld seconds\n"),
100 program_name
, run_time
/ 1000000, run_time
% 1000000);
102 struct mallinfo m
= mallinfo();
103 fprintf(stderr
, _("%s: total space allocated by malloc: %d bytes\n"),
104 program_name
, m
.arena
);
106 File_read::print_stats();
107 fprintf(stderr
, _("%s: output file size: %lld bytes\n"),
108 program_name
, static_cast<long long>(layout
.output_file_size()));
111 gold_exit(errors
.error_count() == 0);