// dynobj.cc -- dynamic object support for gold
-// Copyright 2006, 2007 Free Software Foundation, Inc.
+// Copyright 2006, 2007, 2008 Free Software Foundation, Inc.
// Written by Ian Lance Taylor <iant@google.com>.
// This file is part of gold.
#include "elfcpp.h"
#include "parameters.h"
+#include "script.h"
#include "symtab.h"
#include "dynobj.h"
elfcpp::SHT type,
unsigned int link,
File_view** view,
- off_t* view_size,
+ section_size_type* view_size,
unsigned int* view_info)
{
if (shndx == -1U)
*view = this->get_lasting_view(shdr.get_sh_offset(), shdr.get_sh_size(),
false);
- *view_size = shdr.get_sh_size();
+ *view_size = convert_to_section_size_type(shdr.get_sh_size());
*view_info = shdr.get_sh_info();
}
sd->symbols = this->get_lasting_view(dynsymshdr.get_sh_offset(),
dynsymshdr.get_sh_size(), false);
- sd->symbols_size = dynsymshdr.get_sh_size();
+ sd->symbols_size =
+ convert_to_section_size_type(dynsymshdr.get_sh_size());
// Get the symbol names.
strtab_shndx = dynsymshdr.get_sh_link();
sd->symbol_names = this->get_lasting_view(strtabshdr.get_sh_offset(),
strtabshdr.get_sh_size(),
- true);
- sd->symbol_names_size = strtabshdr.get_sh_size();
+ false);
+ sd->symbol_names_size =
+ convert_to_section_size_type(strtabshdr.get_sh_size());
// Get the version information.
return;
const char* names = reinterpret_cast<const char*>(sd->symbol_names->data());
- off_t names_size = sd->symbol_names_size;
+ section_size_type names_size = sd->symbol_names_size;
const unsigned char* pverdef = sd->verdef->data();
- off_t verdef_size = sd->verdef_size;
+ section_size_type verdef_size = sd->verdef_size;
const unsigned int count = sd->verdef_info;
const unsigned char* p = pverdef;
return;
}
- const unsigned int vd_ndx = verdef.get_vd_ndx();
+ const section_size_type vd_ndx = verdef.get_vd_ndx();
// The GNU linker clears the VERSYM_HIDDEN bit. I'm not
// sure why.
// The first Verdaux holds the name of this version. Subsequent
// ones are versions that this one depends upon, which we don't
// care about here.
- const unsigned int vd_cnt = verdef.get_vd_cnt();
+ const section_size_type vd_cnt = verdef.get_vd_cnt();
if (vd_cnt < 1)
{
- this->error(_("verdef vd_cnt field too small: %u"), vd_cnt);
+ this->error(_("verdef vd_cnt field too small: %u"),
+ static_cast<unsigned int>(vd_cnt));
return;
}
- const unsigned int vd_aux = verdef.get_vd_aux();
+ const section_size_type vd_aux = verdef.get_vd_aux();
if ((p - pverdef) + vd_aux >= verdef_size)
{
- this->error(_("verdef vd_aux field out of range: %u"), vd_aux);
+ this->error(_("verdef vd_aux field out of range: %u"),
+ static_cast<unsigned int>(vd_aux));
return;
}
const unsigned char* pvda = p + vd_aux;
elfcpp::Verdaux<size, big_endian> verdaux(pvda);
- const unsigned int vda_name = verdaux.get_vda_name();
+ const section_size_type vda_name = verdaux.get_vda_name();
if (vda_name >= names_size)
{
- this->error(_("verdaux vda_name field out of range: %u"), vda_name);
+ this->error(_("verdaux vda_name field out of range: %u"),
+ static_cast<unsigned int>(vda_name));
return;
}
this->set_version_map(version_map, vd_ndx, names + vda_name);
- const unsigned int vd_next = verdef.get_vd_next();
+ const section_size_type vd_next = verdef.get_vd_next();
if ((p - pverdef) + vd_next >= verdef_size)
{
- this->error(_("verdef vd_next field out of range: %u"), vd_next);
+ this->error(_("verdef vd_next field out of range: %u"),
+ static_cast<unsigned int>(vd_next));
return;
}
return;
const char* names = reinterpret_cast<const char*>(sd->symbol_names->data());
- off_t names_size = sd->symbol_names_size;
+ section_size_type names_size = sd->symbol_names_size;
const unsigned char* pverneed = sd->verneed->data();
- const off_t verneed_size = sd->verneed_size;
+ const section_size_type verneed_size = sd->verneed_size;
const unsigned int count = sd->verneed_info;
const unsigned char* p = pverneed;
return;
}
- const unsigned int vn_aux = verneed.get_vn_aux();
+ const section_size_type vn_aux = verneed.get_vn_aux();
if ((p - pverneed) + vn_aux >= verneed_size)
{
- this->error(_("verneed vn_aux field out of range: %u"), vn_aux);
+ this->error(_("verneed vn_aux field out of range: %u"),
+ static_cast<unsigned int>(vn_aux));
return;
}
if (vna_name >= names_size)
{
this->error(_("vernaux vna_name field out of range: %u"),
- vna_name);
+ static_cast<unsigned int>(vna_name));
return;
}
this->set_version_map(version_map, vernaux.get_vna_other(),
names + vna_name);
- const unsigned int vna_next = vernaux.get_vna_next();
+ const section_size_type vna_next = vernaux.get_vna_next();
if ((pvna - pverneed) + vna_next >= verneed_size)
{
this->error(_("verneed vna_next field out of range: %u"),
- vna_next);
+ static_cast<unsigned int>(vna_next));
return;
}
pvna += vna_next;
}
- const unsigned int vn_next = verneed.get_vn_next();
+ const section_size_type vn_next = verneed.get_vn_next();
if ((p - pverneed) + vn_next >= verneed_size)
{
- this->error(_("verneed vn_next field out of range: %u"), vn_next);
+ this->error(_("verneed vn_next field out of range: %u"),
+ static_cast<unsigned int>(vn_next));
return;
}
const int sym_size = This::sym_size;
const size_t symcount = sd->symbols_size / sym_size;
gold_assert(sd->external_symbols_offset == 0);
- if (static_cast<off_t>(symcount * sym_size) != sd->symbols_size)
+ if (symcount * sym_size != sd->symbols_size)
{
this->error(_("size of dynamic symbols is not multiple of symbol size"));
return;
delete sd->verneed;
sd->verneed = NULL;
}
+
+ // This is normally the last time we will read any data from this
+ // file.
+ this->clear_view_cache_marks();
}
// Given a vector of hash codes, compute the number of hash buckets to
// Versions methods.
+Versions::Versions(const Version_script_info& version_script,
+ Stringpool* dynpool)
+ : defs_(), needs_(), version_table_(),
+ is_finalized_(false), version_script_(version_script)
+{
+ // We always need a base version, so define that first. Nothing
+ // explicitly declares itself as part of base, so it doesn't need to
+ // be in version_table_.
+ // FIXME: Should use soname here when creating a shared object. Is
+ // this fixme still valid? It looks like it's doing the right thing
+ // to me.
+ if (parameters->output_is_shared())
+ {
+ const char* name = dynpool->add(parameters->output_file_name(),
+ false, NULL);
+ Verdef* vdbase = new Verdef(name, std::vector<std::string>(),
+ true, false, true);
+ this->defs_.push_back(vdbase);
+ }
+
+ if (!this->version_script_.empty())
+ {
+ // Parse the version script, and insert each declared version into
+ // defs_ and version_table_.
+ std::vector<std::string> versions = this->version_script_.get_versions();
+ for (size_t k = 0; k < versions.size(); ++k)
+ {
+ Stringpool::Key version_key;
+ const char* version = dynpool->add(versions[k].c_str(),
+ true, &version_key);
+ Verdef* const vd = new Verdef(
+ version,
+ this->version_script_.get_dependencies(version),
+ false, false, false);
+ this->defs_.push_back(vd);
+ Key key(version_key, 0);
+ this->version_table_.insert(std::make_pair(key, vd));
+ }
+ }
+}
+
Versions::~Versions()
{
for (Defs::iterator p = this->defs_.begin();
{
gold_assert(!this->is_finalized_);
gold_assert(sym->version() != NULL);
-
+
Stringpool::Key version_key;
const char* version = dynpool->add(sym->version(), false, &version_key);
// We have now seen a symbol in this version, so it is not
// weak.
+ gold_assert(vb != NULL);
vb->clear_weak();
-
- // FIXME: When we support version scripts, we will need to
- // check whether this symbol should be forced local.
}
else
{
if (parameters->output_is_shared())
{
gold_error(_("symbol %s has undefined version %s"),
- sym->name(), version);
+ sym->demangled_name().c_str(), version);
return;
}
- // If this is the first version we are defining, first define
- // the base version. FIXME: Should use soname here when
- // creating a shared object.
- Verdef* vdbase = new Verdef(parameters->output_file_name(), true, false,
- true);
- this->defs_.push_back(vdbase);
-
// When creating a regular executable, automatically define
// a new version.
- Verdef* vd = new Verdef(version, false, false, false);
+ Verdef* vd = new Verdef(version, std::vector<std::string>(),
+ false, false, false);
this->defs_.push_back(vd);
ins.first->second = vd;
}
// each new version definition.
unsigned int
-Versions::finalize(const Target* target, Symbol_table* symtab,
- unsigned int dynsym_index, std::vector<Symbol*>* syms)
+Versions::finalize(Symbol_table* symtab, unsigned int dynsym_index,
+ std::vector<Symbol*>* syms)
{
gold_assert(!this->is_finalized_);
// Create a version symbol if necessary.
if (!(*p)->is_symbol_created())
{
- Symbol* vsym = symtab->define_as_constant(target, (*p)->name(),
+ Symbol* vsym = symtab->define_as_constant((*p)->name(),
(*p)->name(), 0, 0,
elfcpp::STT_OBJECT,
elfcpp::STB_GLOBAL,
elfcpp::STV_DEFAULT, 0,
- false);
+ false, false);
vsym->set_needs_dynsym_entry();
vsym->set_dynsym_index(dynsym_index);
++dynsym_index;
const char* version = (*p)->version();
if (version == NULL)
version_index = elfcpp::VER_NDX_GLOBAL;
- else
+ else
version_index = this->version_index(symtab, dynpool, *p);
+ // If the symbol was defined as foo@V1 instead of foo@@V1, add
+ // the hidden bit.
+ if ((*p)->version() != NULL && !(*p)->is_default())
+ version_index |= elfcpp::VERSYM_HIDDEN;
elfcpp::Swap<16, big_endian>::writeval(pbuf + (*p)->dynsym_index() * 2,
- version_index);
+ version_index);
}
*pp = pbuf;