// common.cc -- handle common symbols for gold
-// Copyright 2006, 2007, 2008 Free Software Foundation, Inc.
+// Copyright (C) 2006-2020 Free Software Foundation, Inc.
// Written by Ian Lance Taylor <iant@google.com>.
// This file is part of gold.
// Allocate_commons_task methods.
-// This task allocates the common symbols. We need a lock on the
-// symbol table.
+// This task allocates the common symbols. We arrange to run it
+// before anything else which needs to access the symbol table.
Task_token*
Allocate_commons_task::is_runnable()
{
- if (!this->symtab_lock_->is_writable())
- return this->symtab_lock_;
return NULL;
}
-// Return the locks we hold: one on the symbol table, and one blocker.
+// Release a blocker.
void
Allocate_commons_task::locks(Task_locker* tl)
{
tl->add(this, this->blocker_);
- tl->add(this, this->symtab_lock_);
}
// Allocate the common symbols.
Mapfile* mapfile,
Sort_commons_order sort_order)
{
- typedef typename Sized_symbol<size>::Value_type Value_type;
- typedef typename Sized_symbol<size>::Size_type Size_type;
-
// We've kept a list of all the common symbols. But the symbol may
// have been resolved to a defined symbol by now. And it may be a
// forwarder. First remove all non-common symbols.
gold_unreachable();
}
- Output_data_space *poc = new Output_data_space(addralign, ds_name);
- Output_section *os = layout->add_output_section_data(name,
- elfcpp::SHT_NOBITS,
- flags, poc, false,
- false, false, false);
+ Output_data_space* poc;
+ Output_section* os;
+
+ if (!parameters->incremental_update())
+ {
+ poc = new Output_data_space(addralign, ds_name);
+ os = layout->add_output_section_data(name, elfcpp::SHT_NOBITS, flags,
+ poc, ORDER_INVALID, false);
+ }
+ else
+ {
+ // When doing an incremental update, we need to allocate each common
+ // directly from the output section's free list.
+ poc = NULL;
+ os = layout->find_output_section(name);
+ }
+
if (os != NULL)
{
if (commons_section_type == COMMONS_SMALL)
Symbol* sym = *p;
if (sym == NULL)
break;
+
+ // Because we followed forwarding symbols above, but we didn't
+ // do it reliably before adding symbols to the list, it is
+ // possible for us to have the same symbol on the list twice.
+ // This can happen in the horrible case where a program defines
+ // a common symbol with the same name as a versioned libc
+ // symbol. That will show up here as a symbol which has already
+ // been allocated and is therefore no longer a common symbol.
+ if (!sym->is_common())
+ continue;
+
Sized_symbol<size>* ssym = this->get_sized_symbol<size>(sym);
// Record the symbol in the map file now, before we change its
if (mapfile != NULL)
mapfile->report_allocate_common(sym, ssym->symsize());
- off = align_address(off, ssym->value());
- ssym->allocate_common(poc, off);
- off += ssym->symsize();
+ if (poc != NULL)
+ {
+ off = align_address(off, ssym->value());
+ ssym->allocate_common(poc, off);
+ off += ssym->symsize();
+ }
+ else
+ {
+ // For an incremental update, allocate from the free list.
+ off = os->allocate(ssym->symsize(), ssym->value());
+ if (off == -1)
+ gold_fallback(_("out of patch space in section %s; "
+ "relink with --incremental-full"),
+ os->name());
+ ssym->allocate_common(os, off);
+ }
}
- poc->set_current_data_size(off);
+ if (poc != NULL)
+ poc->set_current_data_size(off);
commons->clear();
}