* configure.tgt: Set targ_emul to arm_wince_pe for ARM Windows CE targets.
[binutils.git] / gold / gold.cc
blobe419f9cb5efa6e468b480f0248f48510fe4f86ef
1 // ld.c -- linker main function
3 #include "gold.h"
5 #include <cstdlib>
6 #include <cstdio>
7 #include <cstring>
8 #include <unistd.h>
10 #include "options.h"
11 #include "workqueue.h"
12 #include "dirsearch.h"
13 #include "readsyms.h"
14 #include "symtab.h"
16 namespace gold
19 const char* program_name;
21 void
22 gold_exit(bool status)
24 exit(status ? EXIT_SUCCESS : EXIT_FAILURE);
27 void
28 gold_fatal(const char* msg, bool perrno)
30 fprintf(stderr, "%s: ", program_name);
31 if (perrno)
32 perror(msg);
33 else
34 fprintf(stderr, "%s\n", msg);
35 gold_exit(false);
38 void
39 gold_nomem()
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);
50 void
51 gold_unreachable()
53 abort();
56 } // End namespace gold.
58 namespace
61 using namespace gold;
63 // Queue up the initial set of tasks for this link job.
65 void
66 queue_initial_tasks(const General_options& options,
67 const Dirsearch& search_path,
68 const Command_line::Input_argument_list& inputs,
69 Workqueue* workqueue, Symbol_table* symtab)
71 if (inputs.empty())
72 gold_fatal(_("no input files"), false);
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)
83 Task_token* next_blocker = new Task_token();
84 next_blocker->add_blocker();
85 workqueue->queue(new Read_symbols(options, symtab, search_path,
86 *p, this_blocker, next_blocker));
87 this_blocker = next_blocker;
90 // workqueue->queue(new Layout(options, inputs, this_blocker));
93 } // end anonymous namespace.
95 int
96 main(int argc, char** argv)
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);
107 gold::program_name = argv[0];
109 // Handle the command line options.
110 gold::Command_line command_line;
111 command_line.process(argc - 1, argv + 1);
113 // The work queue.
114 gold::Workqueue workqueue(command_line.options());
116 // The symbol table.
117 Symbol_table symtab;
119 // Get the search path from the -L options.
120 Dirsearch search_path;
121 search_path.add(&workqueue, command_line.options().search_path());
123 // Queue up the first set of tasks.
124 queue_initial_tasks(command_line.options(), search_path,
125 command_line.inputs(), &workqueue, &symtab);
127 // Run the main task processing loop.
128 workqueue.process();
130 gold::gold_exit(true);