*** empty log message ***
[deliverable/binutils-gdb.git] / gold / dynobj.cc
index a6f3588f48c9ad306e110e2456d74d060d2722d7..a33707b8c812d189a6d4ed0876f858a5f236ccda 100644 (file)
@@ -1,6 +1,6 @@
 // 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.
@@ -27,6 +27,7 @@
 
 #include "elfcpp.h"
 #include "parameters.h"
+#include "script.h"
 #include "symtab.h"
 #include "dynobj.h"
 
@@ -162,7 +163,7 @@ Sized_dynobj<size, big_endian>::read_dynsym_section(
     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)
@@ -183,7 +184,7 @@ Sized_dynobj<size, big_endian>::read_dynsym_section(
 
   *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();
 }
 
@@ -313,7 +314,8 @@ Sized_dynobj<size, big_endian>::do_read_symbols(Read_symbols_data* sd)
 
       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();
@@ -334,8 +336,9 @@ Sized_dynobj<size, big_endian>::do_read_symbols(Read_symbols_data* sd)
 
       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.
 
@@ -444,10 +447,10 @@ Sized_dynobj<size, big_endian>::make_verdef_map(
     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;
@@ -462,7 +465,7 @@ Sized_dynobj<size, big_endian>::make_verdef_map(
          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.
@@ -470,36 +473,40 @@ Sized_dynobj<size, big_endian>::make_verdef_map(
       // 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;
        }
 
@@ -519,10 +526,10 @@ Sized_dynobj<size, big_endian>::make_verneed_map(
     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;
@@ -537,11 +544,12 @@ Sized_dynobj<size, big_endian>::make_verneed_map(
          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;
        }
 
@@ -555,28 +563,29 @@ Sized_dynobj<size, big_endian>::make_verneed_map(
          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;
        }
 
@@ -621,7 +630,7 @@ Sized_dynobj<size, big_endian>::do_add_symbols(Symbol_table* symtab,
   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;
@@ -659,6 +668,10 @@ Sized_dynobj<size, big_endian>::do_add_symbols(Symbol_table* symtab,
       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
@@ -1215,6 +1228,47 @@ Verneed::write(const Stringpool* dynpool, bool is_last,
 
 // 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();
@@ -1253,7 +1307,7 @@ Versions::record_version(const Symbol_table* symtab,
 {
   gold_assert(!this->is_finalized_);
   gold_assert(sym->version() != NULL);
-
+  
   Stringpool::Key version_key;
   const char* version = dynpool->add(sym->version(), false, &version_key);
 
@@ -1288,10 +1342,8 @@ Versions::add_def(const Symbol* sym, const char* version,
 
       // 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
     {
@@ -1301,20 +1353,14 @@ Versions::add_def(const Symbol* sym, const char* version,
       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;
     }
@@ -1369,8 +1415,8 @@ Versions::add_need(Stringpool* dynpool, const char* filename, const char* name,
 // 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_);
 
@@ -1386,12 +1432,12 @@ Versions::finalize(const Target* target, Symbol_table* symtab,
       // 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;
@@ -1486,10 +1532,14 @@ Versions::symbol_section_contents(const Symbol_table* symtab,
       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;
This page took 0.029188 seconds and 4 git commands to generate.