1 // ld.c -- linker main function
11 #include "workqueue.h"
12 #include "dirsearch.h"
21 const char* program_name;
24 gold_exit(bool status)
26 exit(status ? EXIT_SUCCESS : EXIT_FAILURE);
30 gold_fatal(const char* msg, bool perrno)
32 fprintf(stderr, "%s: ", program_name);
36 fprintf(stderr, "%s\n", msg);
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));
58 } // End namespace gold.
65 // Queue up the initial set of tasks for this link job.
68 queue_initial_tasks(const General_options& options,
69 const Dirsearch& search_path,
70 const Command_line::Input_argument_list& inputs,
71 Workqueue* workqueue, Input_objects* input_objects,
75 gold_fatal(_("no input files"), false);
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();
86 Task_token* next_blocker = new Task_token();
87 next_blocker->add_blocker();
88 workqueue->queue(new Read_symbols(options, input_objects, symtab,
89 search_path, *p, this_blocker,
91 this_blocker = next_blocker;
94 workqueue->queue(new Layout_task(options, input_objects, this_blocker));
97 } // end anonymous namespace.
100 main(int argc, char** argv)
102 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
103 setlocale (LC_MESSAGES, "");
105 #if defined (HAVE_SETLOCALE)
106 setlocale (LC_CTYPE, "");
108 bindtextdomain (PACKAGE, LOCALEDIR);
109 textdomain (PACKAGE);
111 gold::program_name = argv[0];
113 // Handle the command line options.
114 gold::Command_line command_line;
115 command_line.process(argc - 1, argv + 1);
118 gold::Workqueue workqueue(command_line.options());
120 // The list of input objects.
121 Input_objects input_objects;
126 // Get the search path from the -L options.
127 Dirsearch search_path;
128 search_path.add(&workqueue, command_line.options().search_path());
130 // Queue up the first set of tasks.
131 queue_initial_tasks(command_line.options(), search_path,
132 command_line.inputs(), &workqueue, &input_objects,
135 // Run the main task processing loop.
138 gold::gold_exit(true);