+ // Add any symbols named with -u options to the symbol table.
+ symtab->add_undefined_symbols_from_command_line(layout);
+
+ // If garbage collection was chosen, relocs have been read and processed
+ // at this point by pre_middle_tasks. Layout can then be done for all
+ // objects.
+ if (parameters->options().gc_sections())
+ {
+ // Find the start symbol if any.
+ Symbol* start_sym;
+ if (parameters->options().entry())
+ start_sym = symtab->lookup(parameters->options().entry());
+ else
+ start_sym = symtab->lookup("_start");
+ if (start_sym != NULL)
+ {
+ bool is_ordinary;
+ unsigned int shndx = start_sym->shndx(&is_ordinary);
+ if (is_ordinary)
+ {
+ symtab->gc()->worklist().push(
+ Section_id(start_sym->object(), shndx));
+ }
+ }
+ // Symbols named with -u should not be considered garbage.
+ symtab->gc_mark_undef_symbols(layout);
+ gold_assert(symtab->gc() != NULL);
+ // Do a transitive closure on all references to determine the worklist.
+ symtab->gc()->do_transitive_closure();
+ }
+
+ // 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)
+ {
+ Task_lock_obj<Object> tlo(task, *p);
+ (*p)->layout(symtab, layout, NULL);
+ }
+ }
+
+ // Layout deferred objects due to plugins.
+ if (parameters->options().has_plugins())
+ {
+ Plugin_manager* plugins = parameters->options().plugins();
+ gold_assert(plugins != NULL);
+ plugins->layout_deferred_objects();
+ }
+
+ 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)
+ {
+ // Update the value of output_section stored in rd.
+ Read_relocs_data* rd = (*p)->get_relocs_data();
+ for (Read_relocs_data::Relocs_list::iterator q = rd->relocs.begin();
+ q != rd->relocs.end();
+ ++q)
+ {
+ q->output_section = (*p)->output_section(q->data_shndx);
+ q->needs_special_offset_handling =
+ (*p)->is_output_section_offset_invalid(q->data_shndx);
+ }
+ }
+ }
+