#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()))
+ gold_error(_("cannot mix -r with --gc-sections or --icf"));
- if (parameters->options().gc_sections())
+ if (parameters->options().gc_sections() || parameters->options().icf())
{
workqueue->queue(new Task_function(new Gc_runner(options,
input_objects,
}
}
-// 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.
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())
+ {
+ 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())
+ {
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())
{
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)
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());
+ // 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())
{
for (Input_objects::Relobj_iterator p = input_objects->relobj_begin();
p != input_objects->relobj_end();