X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=gold%2Fcommon.cc;h=632a20b6c9906469f516cc1d595bf795a3e38759;hb=727fc41e077139570ea8b8ddfd6c546b2a55627c;hp=e2e9f9f7f6eb132e44ccaa0ce736c8ef35bf08c8;hpb=6cb15b7f89d59fb61780b01ad3de2340f33c3728;p=deliverable%2Fbinutils-gdb.git diff --git a/gold/common.cc b/gold/common.cc index e2e9f9f7f6..632a20b6c9 100644 --- a/gold/common.cc +++ b/gold/common.cc @@ -1,6 +1,6 @@ // common.cc -- handle common symbols for gold -// Copyright 2006, 2007 Free Software Foundation, Inc. +// Copyright 2006, 2007, 2008 Free Software Foundation, Inc. // Written by Ian Lance Taylor . // This file is part of gold. @@ -25,6 +25,7 @@ #include #include "workqueue.h" +#include "mapfile.h" #include "layout.h" #include "output.h" #include "symtab.h" @@ -38,35 +39,21 @@ namespace gold // This task allocates the common symbols. We need a lock on the // symbol table. -Task::Is_runnable_type -Allocate_commons_task::is_runnable(Workqueue*) +Task_token* +Allocate_commons_task::is_runnable() { if (!this->symtab_lock_->is_writable()) - return IS_LOCKED; - return IS_RUNNABLE; + return this->symtab_lock_; + return NULL; } // Return the locks we hold: one on the symbol table, and one blocker. -class Allocate_commons_task::Allocate_commons_locker : public Task_locker -{ - public: - Allocate_commons_locker(Task_token& symtab_lock, Task* task, - Task_token& blocker, Workqueue* workqueue) - : symtab_locker_(symtab_lock, task), - blocker_(blocker, workqueue) - { } - - private: - Task_locker_write symtab_locker_; - Task_locker_block blocker_; -}; - -Task_locker* -Allocate_commons_task::locks(Workqueue* workqueue) +void +Allocate_commons_task::locks(Task_locker* tl) { - return new Allocate_commons_locker(*this->symtab_lock_, this, - *this->blocker_, workqueue); + tl->add(this, this->blocker_); + tl->add(this, this->symtab_lock_); } // Allocate the common symbols. @@ -74,7 +61,7 @@ Allocate_commons_task::locks(Workqueue* workqueue) 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 @@ -104,26 +91,24 @@ Sort_commons::operator()(const Symbol* pa, const Symbol* pb) const return true; const Symbol_table* symtab = this->symtab_; - const Sized_symbol* psa; - psa = symtab->get_sized_symbol SELECT_SIZE_NAME(size) (pa - SELECT_SIZE(size)); - const Sized_symbol* psb; - psb = symtab->get_sized_symbol SELECT_SIZE_NAME(size) (pb - SELECT_SIZE(size)); + const Sized_symbol* psa = symtab->get_sized_symbol(pa); + const Sized_symbol* psb = symtab->get_sized_symbol(pb); + // Sort by largest size first. typename Sized_symbol::Size_type sa = psa->symsize(); typename Sized_symbol::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::Value_type va = psa->value(); typename Sized_symbol::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. @@ -133,20 +118,20 @@ Sort_commons::operator()(const Symbol* pa, const Symbol* pb) const // Allocate the common symbols. void -Symbol_table::allocate_commons(const General_options& options, Layout* layout) +Symbol_table::allocate_commons(Layout* layout, Mapfile* mapfile) { - if (this->get_size() == 32) + 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 (this->get_size() == 64) + 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 @@ -159,8 +144,22 @@ Symbol_table::allocate_commons(const General_options& options, Layout* layout) template 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(layout, false, &this->commons_, + mapfile); + this->do_allocate_commons_list(layout, true, &this->tls_commons_, + mapfile); +} + +// Allocate the common symbols in a list. IS_TLS indicates whether +// these are TLS common symbols. + +template +void +Symbol_table::do_allocate_commons_list(Layout* layout, bool is_tls, + Commons_type* commons, + Mapfile* mapfile) { typedef typename Sized_symbol::Value_type Value_type; typedef typename Sized_symbol::Size_type Size_type; @@ -170,8 +169,8 @@ Symbol_table::do_allocate_commons(const General_options&, // 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; @@ -185,10 +184,7 @@ Symbol_table::do_allocate_commons(const General_options&, else { any = true; - Sized_symbol* ssym; - ssym = this->get_sized_symbol SELECT_SIZE_NAME(size) ( - sym - SELECT_SIZE(size)); + Sized_symbol* ssym = this->get_sized_symbol(sym); if (ssym->value() > addralign) addralign = ssym->value(); } @@ -198,45 +194,51 @@ Symbol_table::do_allocate_commons(const General_options&, // 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(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* ssym = this->get_sized_symbol(sym); - Sized_symbol* ssym; - ssym = this->get_sized_symbol SELECT_SIZE_NAME(size) (sym - SELECT_SIZE(size)); + // 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()); - - Size_type symsize = ssym->symsize(); - ssym->init(ssym->name(), poc, off, symsize, ssym->type(), - ssym->binding(), ssym->visibility(), ssym->nonvis(), - false); - - off += symsize; + ssym->allocate_common(poc, off); + off += ssym->symsize(); } - poc->set_space_size(off); + poc->set_current_data_size(off); - this->commons_.clear(); + commons->clear(); } } // End namespace gold.