2006-09-29 H.J. Lu <hongjiu.lu@intel.com>
[deliverable/binutils-gdb.git] / gold / gold.cc
CommitLineData
bae7f79e
ILT
1// ld.c -- linker main function
2
3#include "gold.h"
4
5#include <cstdlib>
6#include <cstdio>
7#include <cstring>
8#include <unistd.h>
9
10#include "options.h"
11#include "workqueue.h"
12#include "dirsearch.h"
13#include "readsyms.h"
14bfc3f5 14#include "symtab.h"
54dc6425 15#include "object.h"
a2fb1b05 16#include "layout.h"
bae7f79e
ILT
17
18namespace gold
19{
20
21const char* program_name;
22
23void
24gold_exit(bool status)
25{
26 exit(status ? EXIT_SUCCESS : EXIT_FAILURE);
27}
28
29void
30gold_fatal(const char* msg, bool perrno)
31{
32 fprintf(stderr, "%s: ", program_name);
33 if (perrno)
34 perror(msg);
35 else
36 fprintf(stderr, "%s\n", msg);
37 gold_exit(false);
38}
39
40void
41gold_nomem()
42{
43 // We are out of memory, so try hard to print a reasonable message.
44 // Note that we don't try to translate this message, since the
45 // translation process itself will require memory.
46 write(2, program_name, strlen(program_name));
47 const char* const s = ": out of memory\n";
48 write(2, s, strlen(s));
49 gold_exit(false);
50}
51
52void
53gold_unreachable()
54{
55 abort();
56}
57
58} // End namespace gold.
59
60namespace
61{
62
63using namespace gold;
64
65// Queue up the initial set of tasks for this link job.
66
67void
68queue_initial_tasks(const General_options& options,
69 const Dirsearch& search_path,
70 const Command_line::Input_argument_list& inputs,
54dc6425 71 Workqueue* workqueue, Input_objects* input_objects,
a2fb1b05 72 Symbol_table* symtab)
bae7f79e
ILT
73{
74 if (inputs.empty())
75 gold_fatal(_("no input files"), false);
76
77 // Read the input files. We have to add the symbols to the symbol
78 // table in order. We do this by creating a separate blocker for
79 // each input file. We associate the blocker with the following
80 // input file, to give us a convenient place to delete it.
81 Task_token* this_blocker = NULL;
82 for (Command_line::Input_argument_list::const_iterator p = inputs.begin();
83 p != inputs.end();
84 ++p)
85 {
86 Task_token* next_blocker = new Task_token();
87 next_blocker->add_blocker();
a2fb1b05
ILT
88 workqueue->queue(new Read_symbols(options, input_objects, symtab,
89 search_path, *p, this_blocker,
90 next_blocker));
bae7f79e
ILT
91 this_blocker = next_blocker;
92 }
93
75f65a3e
ILT
94 workqueue->queue(new Layout_task(options, input_objects, symtab,
95 this_blocker));
bae7f79e
ILT
96}
97
98} // end anonymous namespace.
99
100int
101main(int argc, char** argv)
102{
103#if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
104 setlocale (LC_MESSAGES, "");
105#endif
106#if defined (HAVE_SETLOCALE)
107 setlocale (LC_CTYPE, "");
108#endif
109 bindtextdomain (PACKAGE, LOCALEDIR);
110 textdomain (PACKAGE);
111
112 gold::program_name = argv[0];
113
114 // Handle the command line options.
115 gold::Command_line command_line;
116 command_line.process(argc - 1, argv + 1);
117
118 // The work queue.
119 gold::Workqueue workqueue(command_line.options());
120
a2fb1b05 121 // The list of input objects.
54dc6425 122 Input_objects input_objects;
a2fb1b05 123
bae7f79e 124 // The symbol table.
14bfc3f5 125 Symbol_table symtab;
bae7f79e
ILT
126
127 // Get the search path from the -L options.
128 Dirsearch search_path;
129 search_path.add(&workqueue, command_line.options().search_path());
130
131 // Queue up the first set of tasks.
132 queue_initial_tasks(command_line.options(), search_path,
a2fb1b05
ILT
133 command_line.inputs(), &workqueue, &input_objects,
134 &symtab);
bae7f79e
ILT
135
136 // Run the main task processing loop.
137 workqueue.process();
138
139 gold::gold_exit(true);
140}
This page took 0.032051 seconds and 4 git commands to generate.