// gold.cc -- main linker functions
+// Copyright 2006, 2007 Free Software Foundation, Inc.
+// Written by Ian Lance Taylor <iant@google.com>.
+
+// This file is part of gold.
+
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 3 of the License, or
+// (at your option) any later version.
+
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+// MA 02110-1301, USA.
+
#include "gold.h"
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <unistd.h>
+#include "libiberty.h"
#include "options.h"
#include "workqueue.h"
void
gold_exit(bool status)
{
+ if (!status && parameters != NULL)
+ unlink_if_ordinary(parameters->output_file_name());
exit(status ? EXIT_SUCCESS : EXIT_FAILURE);
}
-void
-gold_fatal(const char* msg, bool perrno)
-{
- fprintf(stderr, "%s: ", program_name);
- if (perrno)
- perror(msg);
- else
- fprintf(stderr, "%s\n", msg);
- gold_exit(false);
-}
-
void
gold_nomem()
{
void
do_gold_unreachable(const char* filename, int lineno, const char* function)
{
- fprintf(stderr, "%s: internal error in %s, at %s:%d\n",
+ fprintf(stderr, _("%s: internal error in %s, at %s:%d\n"),
program_name, function, filename, lineno);
gold_exit(false);
}
Workqueue* workqueue, Input_objects* input_objects,
Symbol_table* symtab, Layout* layout)
{
+ int thread_count = options.thread_count_initial();
+ if (thread_count == 0)
+ {
+ thread_count = cmdline.number_of_input_files();
+ if (thread_count == 0)
+ thread_count = 1;
+ }
+ workqueue->set_thread_count(thread_count);
+
if (cmdline.begin() == cmdline.end())
- gold_fatal(_("no input files"), false);
+ gold_fatal(_("no input files"));
// Read the input files. We have to add the symbols to the symbol
// table in order. We do this by creating a separate blocker for
Layout* layout,
Workqueue* workqueue)
{
+ int thread_count = options.thread_count_middle();
+ if (thread_count == 0)
+ {
+ thread_count = input_objects->number_of_input_objects();
+ if (thread_count == 0)
+ thread_count = 1;
+ }
+ workqueue->set_thread_count(thread_count);
+
+ // Now we have seen all the input files.
+ const bool doing_static_link = (!input_objects->any_dynamic()
+ && !parameters->output_is_shared());
+ set_parameters_doing_static_link(doing_static_link);
+ if (!doing_static_link && options.is_static())
+ {
+ // We print out just the first .so we see; there may be others.
+ gold_error(_("cannot mix -static with dynamic object %s"),
+ (*input_objects->dynobj_begin())->name().c_str());
+ }
+
// Define some sections and symbols needed for a dynamic link. This
// handles some cases we want to see before we read the relocs.
layout->create_initial_dynamic_sections(input_objects, symtab);
// bother to create a task for it.
define_standard_symbols(symtab, layout, input_objects->target());
+ // Define __start and __stop symbols for output sections where
+ // appropriate.
+ layout->define_section_symbols(symtab, input_objects->target());
+
// Read the relocations of the input files. We do this to find
// which symbols are used by relocations which require a GOT and/or
// a PLT entry, or a COPY reloc. When we implement garbage
Workqueue* workqueue,
Output_file* of)
{
+ int thread_count = options.thread_count_final();
+ if (thread_count == 0)
+ {
+ thread_count = input_objects->number_of_input_objects();
+ if (thread_count == 0)
+ thread_count = 1;
+ }
+ workqueue->set_thread_count(thread_count);
+
// Use a blocker to block the final cleanup task.
Task_token* final_blocker = new Task_token();
// Queue a task to write out everything else.
final_blocker->add_blocker();
- workqueue->queue(new Write_data_task(layout, symtab,
- input_objects->target(),
- of, final_blocker));
+ workqueue->queue(new Write_data_task(layout, symtab, of, final_blocker));
// Queue a task to close the output file. This will be blocked by
// FINAL_BLOCKER.