// gold.cc -- main linker functions
-// Copyright 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
+// Copyright 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
// Written by Ian Lance Taylor <iant@google.com>.
// This file is part of gold.
#include "reloc.h"
#include "defstd.h"
#include "plugin.h"
+#include "gc.h"
+#include "icf.h"
+#include "incremental.h"
namespace gold
{
thread_count = cmdline.number_of_input_files();
workqueue->set_thread_count(thread_count);
+ if (cmdline.options().incremental())
+ {
+ Incremental_checker incremental_checker(
+ parameters->options().output_file_name(),
+ layout->incremental_inputs());
+ if (incremental_checker.can_incrementally_link_output_file())
+ {
+ // TODO: remove when incremental linking implemented.
+ printf("Incremental linking might be possible "
+ "(not implemented yet)\n");
+ }
+ // TODO: If we decide on an incremental build, fewer tasks
+ // should be scheduled.
+ }
+
// 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
// each input file. We associate the blocker with the following
}
if (parameters->options().relocatable()
- && parameters->options().gc_sections())
- gold_error(_("cannot mix -r with garbage collection"));
+ && (parameters->options().gc_sections()
+ || parameters->options().icf_enabled()))
+ gold_error(_("cannot mix -r with --gc-sections or --icf"));
- if (parameters->options().gc_sections())
+ if (parameters->options().gc_sections()
+ || parameters->options().icf_enabled())
{
workqueue->queue(new Task_function(new Gc_runner(options,
- input_objects,
+ input_objects,
symtab,
layout,
mapfile),
}
}
-// Queue up a set of tasks to be done before queueing the middle set
-// of tasks. This is only necessary when garbage collection
+// Queue up a set of tasks to be done before queueing the middle set
+// of tasks. This is only necessary when garbage collection
// (--gc-sections) of unused sections is desired. The relocs are read
// and processed here early to determine the garbage sections before the
// relocs can be scanned in later tasks.
{
// We can read and process the relocations in any order.
blocker->add_blocker();
- workqueue->queue(new Read_relocs(options, symtab, layout, *p,
- symtab_lock, blocker));
+ workqueue->queue(new Read_relocs(symtab, layout, *p, symtab_lock,
+ blocker));
}
Task_token* this_blocker = new Task_token(true);
start_sym = symtab->lookup(parameters->options().entry());
else
start_sym = symtab->lookup("_start");
- if (start_sym !=NULL)
+ if (start_sym != NULL)
{
bool is_ordinary;
unsigned int shndx = start_sym->shndx(&is_ordinary);
gold_assert(symtab->gc() != NULL);
// Do a transitive closure on all references to determine the worklist.
symtab->gc()->do_transitive_closure();
- // Call do_layout again to determine the output_sections for all
- // referenced input sections.
+ }
+
+ // If identical code folding (--icf) is chosen it makes sense to do it
+ // only after garbage collection (--gc-sections) as we do not want to
+ // be folding sections that will be garbage.
+ if (parameters->options().icf_enabled())
+ {
+ symtab->icf()->find_identical_sections(input_objects, symtab);
+ }
+
+ // Call Object::layout for the second time to determine the
+ // output_sections for all referenced input sections. When
+ // --gc-sections or --icf is turned on, Object::layout is
+ // called twice. It is called the first time when the
+ // symbols are added.
+ if (parameters->options().gc_sections()
+ || parameters->options().icf_enabled())
+ {
for (Input_objects::Relobj_iterator p = input_objects->relobj_begin();
p != input_objects->relobj_end();
++p)
(*p)->layout(symtab, layout, NULL);
}
}
+
// Layout deferred objects due to plugins.
if (parameters->options().has_plugins())
{
gold_assert(plugins != NULL);
plugins->layout_deferred_objects();
}
- if (parameters->options().gc_sections())
+
+ if (parameters->options().gc_sections()
+ || parameters->options().icf_enabled())
{
for (Input_objects::Relobj_iterator p = input_objects->relobj_begin();
p != input_objects->relobj_end();
// pass an empty archive to the linker and get an empty object file
// out. In order to do this we need to use a default target.
if (input_objects->number_of_input_objects() == 0)
- set_parameters_target(¶meters->default_target());
+ parameters_force_valid_target();
int thread_count = options.thread_count_middle();
if (thread_count == 0)
workqueue->set_thread_count(thread_count);
// Now we have seen all the input files.
- const bool doing_static_link = (!input_objects->any_dynamic()
- && !parameters->options().shared());
+ const bool doing_static_link =
+ (!input_objects->any_dynamic()
+ && !parameters->options().output_is_position_independent());
set_parameters_doing_static_link(doing_static_link);
if (!doing_static_link && options.is_static())
{
gold_fatal(_("cannot use non-ELF output format with dynamic object %s"),
(*input_objects->dynobj_begin())->name().c_str());
+ if (parameters->options().relocatable())
+ {
+ Input_objects::Relobj_iterator p = input_objects->relobj_begin();
+ if (p != input_objects->relobj_end())
+ {
+ bool uses_split_stack = (*p)->uses_split_stack();
+ for (++p; p != input_objects->relobj_end(); ++p)
+ {
+ if ((*p)->uses_split_stack() != uses_split_stack)
+ gold_fatal(_("cannot mix split-stack '%s' and "
+ "non-split-stack '%s' when using -r"),
+ (*input_objects->relobj_begin())->name().c_str(),
+ (*p)->name().c_str());
+ }
+ }
+ }
+
if (is_debugging_enabled(DEBUG_SCRIPT))
layout->script_options()->print(stderr);
// TODO: if this is too slow, do this as a task, rather than inline.
symtab->detect_odr_violations(task, options.output_file_name());
+ // Do the --no-undefined-version check.
+ if (!parameters->options().undefined_version())
+ {
+ Script_options* so = layout->script_options();
+ so->version_script_info()->check_unmatched_names(symtab);
+ }
+
+ // Create any automatic note sections.
+ layout->create_notes();
+
// Create any output sections required by any linker script.
layout->create_script_sections();
// If doing garbage collection, the relocations have already been read.
// Otherwise, read and scan the relocations.
- if (parameters->options().gc_sections())
+ if (parameters->options().gc_sections()
+ || parameters->options().icf_enabled())
{
for (Input_objects::Relobj_iterator p = input_objects->relobj_begin();
p != input_objects->relobj_end();
++p)
{
blocker->add_blocker();
- workqueue->queue(new Scan_relocs(options, symtab, layout, *p,
- (*p)->get_relocs_data(),symtab_lock, blocker));
+ workqueue->queue(new Scan_relocs(symtab, layout, *p,
+ (*p)->get_relocs_data(),
+ symtab_lock, blocker));
}
}
else
// relocations. That task will in turn queue a task to wait
// until it can write to the symbol table.
blocker->add_blocker();
- workqueue->queue(new Read_relocs(options, symtab, layout, *p,
- symtab_lock, blocker));
+ workqueue->queue(new Read_relocs(symtab, layout, *p, symtab_lock,
+ blocker));
}
}
if (input_sections_blocker != NULL)
input_sections_blocker->add_blocker();
final_blocker->add_blocker();
- workqueue->queue(new Relocate_task(options, symtab, layout, *p, of,
+ workqueue->queue(new Relocate_task(symtab, layout, *p, of,
input_sections_blocker,
output_sections_blocker,
final_blocker));