#include <algorithm>
#include "workqueue.h"
+#include "mapfile.h"
#include "layout.h"
#include "output.h"
#include "symtab.h"
void
Allocate_commons_task::run(Workqueue*)
{
- this->symtab_->allocate_commons(this->options_, this->layout_);
+ this->symtab_->allocate_commons(this->layout_, this->mapfile_);
}
// This class is used to sort the common symbol by size. We put the
const Sized_symbol<size>* psa = symtab->get_sized_symbol<size>(pa);
const Sized_symbol<size>* psb = symtab->get_sized_symbol<size>(pb);
+ // Sort by largest size first.
typename Sized_symbol<size>::Size_type sa = psa->symsize();
typename Sized_symbol<size>::Size_type sb = psb->symsize();
if (sa < sb)
return false;
- else if (sb > sa)
+ else if (sb < sa)
return true;
- // When the symbols are the same size, we sort them by alignment.
+ // When the symbols are the same size, we sort them by alignment,
+ // largest alignment first.
typename Sized_symbol<size>::Value_type va = psa->value();
typename Sized_symbol<size>::Value_type vb = psb->value();
if (va < vb)
return false;
- else if (vb > va)
+ else if (vb < va)
return true;
// Otherwise we stabilize the sort by sorting by name.
// Allocate the common symbols.
void
-Symbol_table::allocate_commons(const General_options& options, Layout* layout)
+Symbol_table::allocate_commons(Layout* layout, Mapfile* mapfile)
{
if (parameters->target().get_size() == 32)
{
#if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_32_BIG)
- this->do_allocate_commons<32>(options, layout);
+ this->do_allocate_commons<32>(layout, mapfile);
#else
gold_unreachable();
#endif
else if (parameters->target().get_size() == 64)
{
#if defined(HAVE_TARGET_64_LITTLE) || defined(HAVE_TARGET_64_BIG)
- this->do_allocate_commons<64>(options, layout);
+ this->do_allocate_commons<64>(layout, mapfile);
#else
gold_unreachable();
#endif
template<int size>
void
-Symbol_table::do_allocate_commons(const General_options&,
- Layout* layout)
+Symbol_table::do_allocate_commons(Layout* layout, Mapfile* mapfile)
+{
+ this->do_allocate_commons_list<size>(layout, false, &this->commons_,
+ mapfile);
+ this->do_allocate_commons_list<size>(layout, true, &this->tls_commons_,
+ mapfile);
+}
+
+// Allocate the common symbols in a list. IS_TLS indicates whether
+// these are TLS common symbols.
+
+template<int size>
+void
+Symbol_table::do_allocate_commons_list(Layout* layout, bool is_tls,
+ Commons_type* commons,
+ Mapfile* mapfile)
{
typedef typename Sized_symbol<size>::Value_type Value_type;
typedef typename Sized_symbol<size>::Size_type Size_type;
// forwarder. First remove all non-common symbols.
bool any = false;
uint64_t addralign = 0;
- for (Commons_type::iterator p = this->commons_.begin();
- p != this->commons_.end();
+ for (Commons_type::iterator p = commons->begin();
+ p != commons->end();
++p)
{
Symbol* sym = *p;
// Sort the common symbols by size, so that they pack better into
// memory.
- std::sort(this->commons_.begin(), this->commons_.end(),
+ std::sort(commons->begin(), commons->end(),
Sort_commons<size>(this));
- // Place them in a newly allocated .bss section.
+ // Place them in a newly allocated BSS section.
- Output_data_space *poc = new Output_data_space(addralign);
+ Output_data_space *poc = new Output_data_space(addralign,
+ (is_tls
+ ? "** tls common"
+ : "** common"));
- layout->add_output_section_data(".bss", elfcpp::SHT_NOBITS,
- elfcpp::SHF_WRITE | elfcpp::SHF_ALLOC,
- poc);
+ const char* name = ".bss";
+ elfcpp::Elf_Xword flags = elfcpp::SHF_WRITE | elfcpp::SHF_ALLOC;
+ if (is_tls)
+ {
+ name = ".tbss";
+ flags |= elfcpp::SHF_TLS;
+ }
+ layout->add_output_section_data(name, elfcpp::SHT_NOBITS, flags, poc);
// Allocate them all.
off_t off = 0;
- for (Commons_type::iterator p = this->commons_.begin();
- p != this->commons_.end();
+ for (Commons_type::iterator p = commons->begin();
+ p != commons->end();
++p)
{
Symbol* sym = *p;
if (sym == NULL)
break;
Sized_symbol<size>* ssym = this->get_sized_symbol<size>(sym);
+
+ // Record the symbol in the map file now, before we change its
+ // value. Pass the size in separately so that we don't have to
+ // templatize the map code, which is not performance sensitive.
+ if (mapfile != NULL)
+ mapfile->report_allocate_common(sym, ssym->symsize());
+
off = align_address(off, ssym->value());
ssym->allocate_common(poc, off);
off += ssym->symsize();
poc->set_current_data_size(off);
- this->commons_.clear();
+ commons->clear();
}
} // End namespace gold.