* object.cc (Sized_relobj::layout_section): New function.
[deliverable/binutils-gdb.git] / gold / symtab.cc
index 37f7d35f6680f1a737f8c80048c9e18e72b79324..90ddfaea077ce19dd5a74a807efe950bfafcb7ee 100644 (file)
@@ -37,6 +37,8 @@
 #include "target.h"
 #include "workqueue.h"
 #include "symtab.h"
+#include "demangle.h"   // needed for --dynamic-list-cpp-new
+#include "plugin.h"
 
 namespace gold
 {
@@ -73,6 +75,7 @@ Symbol::init_fields(const char* name, const char* version,
   this->is_copied_from_dynobj_ = false;
   this->is_forced_local_ = false;
   this->is_ordinary_shndx_ = false;
+  this->in_real_elf_ = false;
 }
 
 // Return the demangled version of the symbol's name, but only
@@ -117,6 +120,7 @@ Symbol::init_base_object(const char* name, const char* version, Object* object,
   this->source_ = FROM_OBJECT;
   this->in_reg_ = !object->is_dynamic();
   this->in_dyn_ = object->is_dynamic();
+  this->in_real_elf_ = object->pluginobj() == NULL;
 }
 
 // Initialize the fields in the base class Symbol for a symbol defined
@@ -133,6 +137,7 @@ Symbol::init_base_output_data(const char* name, const char* version,
   this->u_.in_output_data.offset_is_from_end = offset_is_from_end;
   this->source_ = IN_OUTPUT_DATA;
   this->in_reg_ = true;
+  this->in_real_elf_ = true;
 }
 
 // Initialize the fields in the base class Symbol for a symbol defined
@@ -150,6 +155,7 @@ Symbol::init_base_output_segment(const char* name, const char* version,
   this->u_.in_output_segment.offset_base = offset_base;
   this->source_ = IN_OUTPUT_SEGMENT;
   this->in_reg_ = true;
+  this->in_real_elf_ = true;
 }
 
 // Initialize the fields in the base class Symbol for a symbol defined
@@ -163,6 +169,7 @@ Symbol::init_base_constant(const char* name, const char* version,
   this->init_fields(name, version, type, binding, visibility, nonvis);
   this->source_ = IS_CONSTANT;
   this->in_reg_ = true;
+  this->in_real_elf_ = true;
 }
 
 // Initialize the fields in the base class Symbol for an undefined
@@ -177,6 +184,7 @@ Symbol::init_base_undefined(const char* name, const char* version,
   this->dynsym_index_ = -1U;
   this->source_ = IS_UNDEFINED;
   this->in_reg_ = true;
+  this->in_real_elf_ = true;
 }
 
 // Allocate a common symbol in the base.
@@ -281,6 +289,9 @@ Sized_symbol<size>::allocate_common(Output_data* od, Value_type value)
   this->value_ = value;
 }
 
+// The ""'s around str ensure str is a string literal, so sizeof works.
+#define strprefix(var, str)   (strncmp(var, str, sizeof("" str "") - 1) == 0)
+
 // Return true if this symbol should be added to the dynamic symbol
 // table.
 
@@ -295,6 +306,48 @@ Symbol::should_add_dynsym_entry() const
   if (this->is_forced_local())
     return false;
 
+  // If the symbol was forced dynamic in a --dynamic-list file, add it.
+  if (parameters->options().in_dynamic_list(this->name()))
+    return true;
+
+  // If dynamic-list-data was specified, add any STT_OBJECT.
+  if (parameters->options().dynamic_list_data()
+      && !this->is_from_dynobj()
+      && this->type() == elfcpp::STT_OBJECT)
+    return true;
+
+  // If --dynamic-list-cpp-new was specified, add any new/delete symbol.
+  // If --dynamic-list-cpp-typeinfo was specified, add any typeinfo symbols.
+  if ((parameters->options().dynamic_list_cpp_new()
+       || parameters->options().dynamic_list_cpp_typeinfo())
+      && !this->is_from_dynobj())
+    {
+      // TODO(csilvers): We could probably figure out if we're an operator
+      //                 new/delete or typeinfo without the need to demangle.
+      char* demangled_name = cplus_demangle(this->name(),
+                                            DMGL_ANSI | DMGL_PARAMS);
+      if (demangled_name == NULL)
+        {
+          // Not a C++ symbol, so it can't satisfy these flags
+        }
+      else if (parameters->options().dynamic_list_cpp_new()
+               && (strprefix(demangled_name, "operator new")
+                   || strprefix(demangled_name, "operator delete")))
+        {
+          free(demangled_name);
+          return true;
+        }
+      else if (parameters->options().dynamic_list_cpp_typeinfo()
+               && (strprefix(demangled_name, "typeinfo name for")
+                   || strprefix(demangled_name, "typeinfo for")))
+        {
+          free(demangled_name);
+          return true;
+        }
+      else
+        free(demangled_name);
+    }
+
   // If exporting all symbols or building a shared library,
   // and the symbol is defined in a regular object and is
   // externally visible, we need to add it.
@@ -357,6 +410,7 @@ Symbol::output_section() const
        if (shndx != elfcpp::SHN_UNDEF && this->is_ordinary_shndx_)
          {
            gold_assert(!this->u_.from_object.object->is_dynamic());
+           gold_assert(this->u_.from_object.object->pluginobj() == NULL);
            Relobj* relobj = static_cast<Relobj*>(this->u_.from_object.object);
            return relobj->output_section(shndx);
          }
@@ -973,6 +1027,68 @@ Symbol_table::add_from_relobj(
     }
 }
 
+// Add a symbol from a plugin-claimed file.
+
+template<int size, bool big_endian>
+Symbol*
+Symbol_table::add_from_pluginobj(
+    Sized_pluginobj<size, big_endian>* obj,
+    const char* name,
+    const char* ver,
+    elfcpp::Sym<size, big_endian>* sym)
+{
+  unsigned int st_shndx = sym->get_st_shndx();
+
+  Stringpool::Key ver_key = 0;
+  bool def = false;
+  bool local = false;
+
+  if (ver != NULL)
+    {
+      ver = this->namepool_.add(ver, true, &ver_key);
+    }
+  // We don't want to assign a version to an undefined symbol,
+  // even if it is listed in the version script.  FIXME: What
+  // about a common symbol?
+  else
+    {
+      if (!this->version_script_.empty()
+          && st_shndx != elfcpp::SHN_UNDEF)
+        {
+          // The symbol name did not have a version, but the
+          // version script may assign a version anyway.
+          std::string version;
+          if (this->version_script_.get_symbol_version(name, &version))
+            {
+              // The version can be empty if the version script is
+              // only used to force some symbols to be local.
+              if (!version.empty())
+                {
+                  ver = this->namepool_.add_with_length(version.c_str(),
+                                                        version.length(),
+                                                        true,
+                                                        &ver_key);
+                  def = true;
+                }
+            }
+          else if (this->version_script_.symbol_is_local(name))
+            local = true;
+        }
+    }
+
+  Stringpool::Key name_key;
+  name = this->namepool_.add(name, true, &name_key);
+
+  Sized_symbol<size>* res;
+  res = this->add_from_object(obj, name, name_key, ver, ver_key,
+                             def, *sym, st_shndx, true, st_shndx);
+
+  if (local)
+       this->force_local(res);
+
+  return res;
+}
+
 // Add all the symbols in a dynamic object to the hash table.
 
 template<int size, bool big_endian>
@@ -2043,6 +2159,11 @@ Symbol_table::sized_finalize_symbol(Symbol* unsized_sym)
            value = 0;
            shndx = elfcpp::SHN_UNDEF;
          }
+       else if (symobj->pluginobj() != NULL)
+         {
+           value = 0;
+           shndx = elfcpp::SHN_UNDEF;
+         }
        else if (shndx == elfcpp::SHN_UNDEF)
          value = 0;
        else if (!is_ordinary
@@ -2061,11 +2182,20 @@ Symbol_table::sized_finalize_symbol(Symbol* unsized_sym)
              }
 
             uint64_t secoff64 = relobj->output_section_offset(shndx);
-            Value_type secoff = convert_types<Value_type, uint64_t>(secoff64);
-           if (sym->type() == elfcpp::STT_TLS)
-             value = sym->value() + os->tls_offset() + secoff;
-           else
-             value = sym->value() + os->address() + secoff;
+            if (secoff64 == -1ULL)
+              {
+                // The section needs special handling (e.g., a merge section).
+               value = os->output_address(relobj, shndx, sym->value());
+             }
+            else
+              {
+                Value_type secoff =
+                  convert_types<Value_type, uint64_t>(secoff64);
+               if (sym->type() == elfcpp::STT_TLS)
+                 value = sym->value() + os->tls_offset() + secoff;
+               else
+                 value = sym->value() + os->address() + secoff;
+             }
          }
       }
       break;
@@ -2261,6 +2391,8 @@ Symbol_table::sized_write_globals(const Input_objects* input_objects,
                      dynsym_value = target.dynsym_value(sym);
                    shndx = elfcpp::SHN_UNDEF;
                  }
+               else if (symobj->pluginobj() != NULL)
+                 shndx = elfcpp::SHN_UNDEF;
                else if (in_shndx == elfcpp::SHN_UNDEF
                         || (!is_ordinary
                             && (in_shndx == elfcpp::SHN_ABS
@@ -2655,7 +2787,7 @@ Symbol_table::add_from_relobj<32, false>(
     size_t symndx_offset,
     const char* sym_names,
     size_t sym_name_size,
-    Sized_relobj<32, true>::Symbols* sympointers,
+    Sized_relobj<32, false>::Symbols* sympointers,
     size_t* defined);
 #endif
 
@@ -2669,7 +2801,7 @@ Symbol_table::add_from_relobj<32, true>(
     size_t symndx_offset,
     const char* sym_names,
     size_t sym_name_size,
-    Sized_relobj<32, false>::Symbols* sympointers,
+    Sized_relobj<32, true>::Symbols* sympointers,
     size_t* defined);
 #endif
 
@@ -2683,7 +2815,7 @@ Symbol_table::add_from_relobj<64, false>(
     size_t symndx_offset,
     const char* sym_names,
     size_t sym_name_size,
-    Sized_relobj<64, true>::Symbols* sympointers,
+    Sized_relobj<64, false>::Symbols* sympointers,
     size_t* defined);
 #endif
 
@@ -2697,10 +2829,50 @@ Symbol_table::add_from_relobj<64, true>(
     size_t symndx_offset,
     const char* sym_names,
     size_t sym_name_size,
-    Sized_relobj<64, false>::Symbols* sympointers,
+    Sized_relobj<64, true>::Symbols* sympointers,
     size_t* defined);
 #endif
 
+#ifdef HAVE_TARGET_32_LITTLE
+template
+Symbol*
+Symbol_table::add_from_pluginobj<32, false>(
+    Sized_pluginobj<32, false>* obj,
+    const char* name,
+    const char* ver,
+    elfcpp::Sym<32, false>* sym);
+#endif
+
+#ifdef HAVE_TARGET_32_BIG
+template
+Symbol*
+Symbol_table::add_from_pluginobj<32, true>(
+    Sized_pluginobj<32, true>* obj,
+    const char* name,
+    const char* ver,
+    elfcpp::Sym<32, true>* sym);
+#endif
+
+#ifdef HAVE_TARGET_64_LITTLE
+template
+Symbol*
+Symbol_table::add_from_pluginobj<64, false>(
+    Sized_pluginobj<64, false>* obj,
+    const char* name,
+    const char* ver,
+    elfcpp::Sym<64, false>* sym);
+#endif
+
+#ifdef HAVE_TARGET_64_BIG
+template
+Symbol*
+Symbol_table::add_from_pluginobj<64, true>(
+    Sized_pluginobj<64, true>* obj,
+    const char* name,
+    const char* ver,
+    elfcpp::Sym<64, true>* sym);
+#endif
+
 #ifdef HAVE_TARGET_32_LITTLE
 template
 void
This page took 0.02657 seconds and 4 git commands to generate.