*** empty log message ***
[deliverable/binutils-gdb.git] / gold / dynobj.cc
index 3c3549d8e27ba1310f9aac961c747687db5e3f06..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"
 
@@ -1227,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();
@@ -1265,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);
 
@@ -1302,9 +1344,6 @@ Versions::add_def(const Symbol* sym, const char* version,
       // 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
     {
@@ -1318,16 +1357,10 @@ Versions::add_def(const Symbol* sym, const char* 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;
     }
@@ -1382,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_);
 
@@ -1399,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;
@@ -1499,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.04291 seconds and 4 git commands to generate.