1 // ld.c -- linker main function
11 #include "workqueue.h"
12 #include "dirsearch.h"
22 const char* program_name;
25 gold_exit(bool status)
27 exit(status ? EXIT_SUCCESS : EXIT_FAILURE);
31 gold_fatal(const char* msg, bool perrno)
33 fprintf(stderr, "%s: ", program_name);
37 fprintf(stderr, "%s\n", msg);
44 // We are out of memory, so try hard to print a reasonable message.
45 // Note that we don't try to translate this message, since the
46 // translation process itself will require memory.
47 write(2, program_name, strlen(program_name));
48 const char* const s = ": out of memory\n";
49 write(2, s, strlen(s));
59 } // End namespace gold.
66 // Queue up the initial set of tasks for this link job.
69 queue_initial_tasks(const General_options& options,
70 const Dirsearch& search_path,
71 const Command_line::Input_argument_list& inputs,
72 Workqueue* workqueue, Input_objects* input_objects,
76 gold_fatal(_("no input files"), false);
78 // Read the input files. We have to add the symbols to the symbol
79 // table in order. We do this by creating a separate blocker for
80 // each input file. We associate the blocker with the following
81 // input file, to give us a convenient place to delete it.
82 Task_token* this_blocker = NULL;
83 for (Command_line::Input_argument_list::const_iterator p = inputs.begin();
87 Task_token* next_blocker = new Task_token();
88 next_blocker->add_blocker();
89 workqueue->queue(new Read_symbols(options, input_objects, symtab,
90 search_path, *p, this_blocker,
92 this_blocker = next_blocker;
95 workqueue->queue(new Layout_task(options, input_objects, symtab,
99 } // end anonymous namespace.
104 // Queue up the final set of tasks. This is called at the end of
108 queue_final_tasks(const General_options& options,
109 const Input_objects* input_objects,
110 const Symbol_table* symtab,
111 const Layout* layout,
112 Workqueue* workqueue,
115 // Use a blocker to block the final cleanup task.
116 Task_token* final_blocker = new Task_token();
118 // Queue a task for each input object to relocate the sections and
119 // write out the local symbols.
120 for (Input_objects::Object_list::const_iterator p = input_objects->begin();
121 p != input_objects->end();
124 final_blocker->add_blocker();
125 workqueue->queue(new Relocate_task(options, symtab, layout->sympool(),
126 *p, of, final_blocker));
129 // Queue a task to write out the symbol table.
130 final_blocker->add_blocker();
131 workqueue->queue(new Write_symbols_task(symtab, input_objects->target(),
132 layout->sympool(), of,
135 // Queue a task to write out everything else.
136 final_blocker->add_blocker();
137 workqueue->queue(new Write_data_task(layout, of, final_blocker));
139 // Queue a task to close the output file. This will be blocked by
141 workqueue->queue(new Close_task(of, final_blocker));
144 } // End namespace gold.
147 main(int argc, char** argv)
149 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
150 setlocale (LC_MESSAGES, "");
152 #if defined (HAVE_SETLOCALE)
153 setlocale (LC_CTYPE, "");
155 bindtextdomain (PACKAGE, LOCALEDIR);
156 textdomain (PACKAGE);
158 gold::program_name = argv[0];
160 // Handle the command line options.
161 gold::Command_line command_line;
162 command_line.process(argc - 1, argv + 1);
165 gold::Workqueue workqueue(command_line.options());
167 // The list of input objects.
168 Input_objects input_objects;
173 // Get the search path from the -L options.
174 Dirsearch search_path;
175 search_path.add(&workqueue, command_line.options().search_path());
177 // Queue up the first set of tasks.
178 queue_initial_tasks(command_line.options(), search_path,
179 command_line.inputs(), &workqueue, &input_objects,
182 // Run the main task processing loop.
185 gold::gold_exit(true);