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