1 // ld.c -- linker main function
11 #include "workqueue.h"
12 #include "dirsearch.h"
20 const char* program_name;
23 gold_exit(bool status)
25 exit(status ? EXIT_SUCCESS : EXIT_FAILURE);
29 gold_fatal(const char* msg, bool perrno)
31 fprintf(stderr, "%s: ", program_name);
35 fprintf(stderr, "%s\n", msg);
42 // We are out of memory, so try hard to print a reasonable message.
43 // Note that we don't try to translate this message, since the
44 // translation process itself will require memory.
45 write(2, program_name, strlen(program_name));
46 const char* const s = ": out of memory\n";
47 write(2, s, strlen(s));
57 } // End namespace gold.
64 // Queue up the initial set of tasks for this link job.
67 queue_initial_tasks(const General_options& options,
68 const Dirsearch& search_path,
69 const Command_line::Input_argument_list& inputs,
70 Workqueue* workqueue, Object_list* input_objects,
74 gold_fatal(_("no input files"), false);
76 // Read the input files. We have to add the symbols to the symbol
77 // table in order. We do this by creating a separate blocker for
78 // each input file. We associate the blocker with the following
79 // input file, to give us a convenient place to delete it.
80 Task_token* this_blocker = NULL;
81 for (Command_line::Input_argument_list::const_iterator p = inputs.begin();
85 Task_token* next_blocker = new Task_token();
86 next_blocker->add_blocker();
87 workqueue->queue(new Read_symbols(options, input_objects, symtab,
88 search_path, *p, this_blocker,
90 this_blocker = next_blocker;
93 workqueue->queue(new Layout_task(options, input_objects, this_blocker));
96 } // end anonymous namespace.
99 main(int argc, char** argv)
101 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
102 setlocale (LC_MESSAGES, "");
104 #if defined (HAVE_SETLOCALE)
105 setlocale (LC_CTYPE, "");
107 bindtextdomain (PACKAGE, LOCALEDIR);
108 textdomain (PACKAGE);
110 gold::program_name = argv[0];
112 // Handle the command line options.
113 gold::Command_line command_line;
114 command_line.process(argc - 1, argv + 1);
117 gold::Workqueue workqueue(command_line.options());
119 // The list of input objects.
120 Object_list input_objects;
125 // Get the search path from the -L options.
126 Dirsearch search_path;
127 search_path.add(&workqueue, command_line.options().search_path());
129 // Queue up the first set of tasks.
130 queue_initial_tasks(command_line.options(), search_path,
131 command_line.inputs(), &workqueue, &input_objects,
134 // Run the main task processing loop.
137 gold::gold_exit(true);