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