* elflink.c (set_symbol_value): Add isymbuf and locsymcount
[deliverable/binutils-gdb.git] / gold / dynobj.cc
index 7afaaa55a786b7ba248ccd64924a24cc4fa1a598..09e71263ac8f2200ef665af8968757f1fd476191 100644 (file)
@@ -1,11 +1,32 @@
 // dynobj.cc -- dynamic object support for gold
 
+// Copyright 2006, 2007 Free Software Foundation, Inc.
+// Written by Ian Lance Taylor <iant@google.com>.
+
+// This file is part of gold.
+
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 3 of the License, or
+// (at your option) any later version.
+
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+// MA 02110-1301, USA.
+
 #include "gold.h"
 
 #include <vector>
 #include <cstring>
 
 #include "elfcpp.h"
+#include "parameters.h"
 #include "symtab.h"
 #include "dynobj.h"
 
@@ -153,7 +174,8 @@ Sized_dynobj<size, big_endian>::read_dynsym_section(
       gold_exit(false);
     }
 
-  *view = this->get_lasting_view(shdr.get_sh_offset(), shdr.get_sh_size());
+  *view = this->get_lasting_view(shdr.get_sh_offset(), shdr.get_sh_size(),
+                                false);
   *view_size = shdr.get_sh_size();
   *view_info = shdr.get_sh_info();
 }
@@ -177,7 +199,7 @@ Sized_dynobj<size, big_endian>::set_soname(const unsigned char* pshdrs,
 
   const off_t dynamic_size = dynamicshdr.get_sh_size();
   const unsigned char* pdynamic = this->get_view(dynamicshdr.get_sh_offset(),
-                                                dynamic_size);
+                                                dynamic_size, false);
 
   const unsigned int link = dynamicshdr.get_sh_link();
   if (link != strtab_shndx)
@@ -202,7 +224,7 @@ Sized_dynobj<size, big_endian>::set_soname(const unsigned char* pshdrs,
        }
 
       strtab_size = strtabshdr.get_sh_size();
-      strtabu = this->get_view(strtabshdr.get_sh_offset(), strtab_size);
+      strtabu = this->get_view(strtabshdr.get_sh_offset(), strtab_size, false);
     }
 
   for (const unsigned char* p = pdynamic;
@@ -274,7 +296,7 @@ Sized_dynobj<size, big_endian>::do_read_symbols(Read_symbols_data* sd)
       gold_assert(dynsymshdr.get_sh_type() == elfcpp::SHT_DYNSYM);
 
       sd->symbols = this->get_lasting_view(dynsymshdr.get_sh_offset(),
-                                          dynsymshdr.get_sh_size());
+                                          dynsymshdr.get_sh_size(), false);
       sd->symbols_size = dynsymshdr.get_sh_size();
 
       // Get the symbol names.
@@ -298,7 +320,8 @@ 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());
+                                               strtabshdr.get_sh_size(),
+                                               true);
       sd->symbol_names_size = strtabshdr.get_sh_size();
 
       // Get the version information.
@@ -340,8 +363,7 @@ Sized_dynobj<size, big_endian>::do_read_symbols(Read_symbols_data* sd)
 
 template<int size, bool big_endian>
 void
-Sized_dynobj<size, big_endian>::do_layout(const General_options&,
-                                         Symbol_table* symtab,
+Sized_dynobj<size, big_endian>::do_layout(Symbol_table* symtab,
                                          Layout*,
                                          Read_symbols_data* sd)
 {
@@ -718,8 +740,7 @@ Dynobj::elf_hash(const char* name)
 // symbol table.
 
 void
-Dynobj::create_elf_hash_table(const Target* target,
-                             const std::vector<Symbol*>& dynsyms,
+Dynobj::create_elf_hash_table(const std::vector<Symbol*>& dynsyms,
                              unsigned int local_dynsym_count,
                              unsigned char** pphash,
                              unsigned int* phashlen)
@@ -752,10 +773,24 @@ Dynobj::create_elf_hash_table(const Target* target,
                          * 4);
   unsigned char* phash = new unsigned char[hashlen];
 
-  if (target->is_big_endian())
-    Dynobj::sized_create_elf_hash_table<true>(bucket, chain, phash, hashlen);
+  if (parameters->is_big_endian())
+    {
+#if defined(HAVE_TARGET_32_BIG) || defined(HAVE_TARGET_64_BIG)
+      Dynobj::sized_create_elf_hash_table<true>(bucket, chain, phash,
+                                               hashlen);
+#else
+      gold_unreachable();
+#endif
+    }
   else
-    Dynobj::sized_create_elf_hash_table<false>(bucket, chain, phash, hashlen);
+    {
+#if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_64_LITTLE)
+      Dynobj::sized_create_elf_hash_table<false>(bucket, chain, phash,
+                                                hashlen);
+#else
+      gold_unreachable();
+#endif
+    }
 
   *pphash = phash;
   *phashlen = hashlen;
@@ -818,8 +853,7 @@ Dynobj::gnu_hash(const char* name)
 // symbol table.
 
 void
-Dynobj::create_gnu_hash_table(const Target* target,
-                             const std::vector<Symbol*>& dynsyms,
+Dynobj::create_gnu_hash_table(const std::vector<Symbol*>& dynsyms,
                              unsigned int local_dynsym_count,
                              unsigned char** pphash,
                              unsigned int* phashlen)
@@ -868,37 +902,61 @@ Dynobj::create_gnu_hash_table(const Target* target,
 
   // For the actual data generation we call out to a templatized
   // function.
-  int size = target->get_size();
-  bool big_endian = target->is_big_endian();
+  int size = parameters->get_size();
+  bool big_endian = parameters->is_big_endian();
   if (size == 32)
     {
       if (big_endian)
-       Dynobj::sized_create_gnu_hash_table<32, true>(hashed_dynsyms,
-                                                     dynsym_hashvals,
-                                                     unhashed_dynsym_index,
-                                                     pphash,
-                                                     phashlen);
+       {
+#ifdef HAVE_TARGET_32_BIG
+         Dynobj::sized_create_gnu_hash_table<32, true>(hashed_dynsyms,
+                                                       dynsym_hashvals,
+                                                       unhashed_dynsym_index,
+                                                       pphash,
+                                                       phashlen);
+#else
+         gold_unreachable();
+#endif
+       }
       else
-       Dynobj::sized_create_gnu_hash_table<32, false>(hashed_dynsyms,
-                                                      dynsym_hashvals,
-                                                      unhashed_dynsym_index,
-                                                      pphash,
-                                                      phashlen);
+       {
+#ifdef HAVE_TARGET_32_LITTLE
+         Dynobj::sized_create_gnu_hash_table<32, false>(hashed_dynsyms,
+                                                        dynsym_hashvals,
+                                                        unhashed_dynsym_index,
+                                                        pphash,
+                                                        phashlen);
+#else
+         gold_unreachable();
+#endif
+       }
     }
   else if (size == 64)
     {
       if (big_endian)
-       Dynobj::sized_create_gnu_hash_table<64, true>(hashed_dynsyms,
-                                                     dynsym_hashvals,
-                                                     unhashed_dynsym_index,
-                                                     pphash,
-                                                     phashlen);
+       {
+#ifdef HAVE_TARGET_64_BIG
+         Dynobj::sized_create_gnu_hash_table<64, true>(hashed_dynsyms,
+                                                       dynsym_hashvals,
+                                                       unhashed_dynsym_index,
+                                                       pphash,
+                                                       phashlen);
+#else
+         gold_unreachable();
+#endif
+       }
       else
-       Dynobj::sized_create_gnu_hash_table<64, false>(hashed_dynsyms,
-                                                      dynsym_hashvals,
-                                                      unhashed_dynsym_index,
-                                                      pphash,
-                                                      phashlen);
+       {
+#ifdef HAVE_TARGET_64_LITTLE
+         Dynobj::sized_create_gnu_hash_table<64, false>(hashed_dynsyms,
+                                                        dynsym_hashvals,
+                                                        unhashed_dynsym_index,
+                                                        pphash,
+                                                        phashlen);
+#else
+         gold_unreachable();
+#endif
+       }
     }
   else
     gold_unreachable();
@@ -1195,7 +1253,10 @@ Versions::record_version(const General_options* options,
   const char* version = dynpool->add(sym->version(), &version_key);
 
   if (!sym->is_from_dynobj())
-    this->add_def(options, sym, version, version_key);
+    {
+      if (parameters->output_is_shared())
+        this->add_def(options, sym, version, version_key);
+    }
   else
     {
       // This is a version reference.
@@ -1236,7 +1297,7 @@ Versions::add_def(const General_options* options, const Symbol* sym,
       // If we are creating a shared object, it is an error to
       // find a definition of a symbol with a version which is not
       // in the version script.
-      if (options->is_shared())
+      if (parameters->output_is_shared())
        {
          fprintf(stderr, _("%s: symbol %s has undefined version %s\n"),
                  program_name, sym->name(), version);
@@ -1324,13 +1385,14 @@ 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(),
-                                                  (*p)->name(), 0, 0,
-                                                  elfcpp::STT_OBJECT,
-                                                  elfcpp::STB_GLOBAL,
-                                                  elfcpp::STV_DEFAULT, 0,
-                                                  false);
+         Symbol* vsym = symtab->define_as_constant(target, (*p)->name(),
+                                                   (*p)->name(), 0, 0,
+                                                   elfcpp::STT_OBJECT,
+                                                   elfcpp::STB_GLOBAL,
+                                                   elfcpp::STV_DEFAULT, 0,
+                                                   false);
          vsym->set_needs_dynsym_entry();
+          vsym->set_dynsym_index(dynsym_index);
          ++dynsym_index;
          syms->push_back(vsym);
          // The name is already in the dynamic pool.
@@ -1370,7 +1432,11 @@ Versions::version_index(const Stringpool* dynpool, const Symbol* sym) const
 
   Key k;
   if (!sym->is_from_dynobj())
-    k = Key(version_key, 0);
+    {
+      if (!parameters->output_is_shared())
+        return elfcpp::VER_NDX_GLOBAL;
+      k = Key(version_key, 0);
+    }
   else
     {
       Object* object = sym->object();
@@ -1520,18 +1586,27 @@ Versions::need_section_contents(const Stringpool* dynpool,
 // Instantiate the templates we need.  We could use the configure
 // script to restrict this to only the ones for implemented targets.
 
+#ifdef HAVE_TARGET_32_LITTLE
 template
 class Sized_dynobj<32, false>;
+#endif
 
+#ifdef HAVE_TARGET_32_BIG
 template
 class Sized_dynobj<32, true>;
+#endif
 
+#ifdef HAVE_TARGET_64_LITTLE
 template
 class Sized_dynobj<64, false>;
+#endif
 
+#ifdef HAVE_TARGET_64_BIG
 template
 class Sized_dynobj<64, true>;
+#endif
 
+#ifdef HAVE_TARGET_32_LITTLE
 template
 void
 Versions::symbol_section_contents<32, false>(
@@ -1541,7 +1616,9 @@ Versions::symbol_section_contents<32, false>(
     unsigned char**,
     unsigned int*
     ACCEPT_SIZE_ENDIAN_EXPLICIT(32, false)) const;
+#endif
 
+#ifdef HAVE_TARGET_32_BIG
 template
 void
 Versions::symbol_section_contents<32, true>(
@@ -1551,7 +1628,9 @@ Versions::symbol_section_contents<32, true>(
     unsigned char**,
     unsigned int*
     ACCEPT_SIZE_ENDIAN_EXPLICIT(32, true)) const;
+#endif
 
+#ifdef HAVE_TARGET_64_LITTLE
 template
 void
 Versions::symbol_section_contents<64, false>(
@@ -1561,7 +1640,9 @@ Versions::symbol_section_contents<64, false>(
     unsigned char**,
     unsigned int*
     ACCEPT_SIZE_ENDIAN_EXPLICIT(64, false)) const;
+#endif
 
+#ifdef HAVE_TARGET_64_BIG
 template
 void
 Versions::symbol_section_contents<64, true>(
@@ -1571,7 +1652,9 @@ Versions::symbol_section_contents<64, true>(
     unsigned char**,
     unsigned int*
     ACCEPT_SIZE_ENDIAN_EXPLICIT(64, true)) const;
+#endif
 
+#ifdef HAVE_TARGET_32_LITTLE
 template
 void
 Versions::def_section_contents<32, false>(
@@ -1580,7 +1663,9 @@ Versions::def_section_contents<32, false>(
     unsigned int*,
     unsigned int*
     ACCEPT_SIZE_ENDIAN_EXPLICIT(32, false)) const;
+#endif
 
+#ifdef HAVE_TARGET_32_BIG
 template
 void
 Versions::def_section_contents<32, true>(
@@ -1589,7 +1674,9 @@ Versions::def_section_contents<32, true>(
     unsigned int*,
     unsigned int*
     ACCEPT_SIZE_ENDIAN_EXPLICIT(32, true)) const;
+#endif
 
+#ifdef HAVE_TARGET_64_LITTLE
 template
 void
 Versions::def_section_contents<64, false>(
@@ -1598,7 +1685,9 @@ Versions::def_section_contents<64, false>(
     unsigned int*,
     unsigned int*
     ACCEPT_SIZE_ENDIAN_EXPLICIT(64, false)) const;
+#endif
 
+#ifdef HAVE_TARGET_64_BIG
 template
 void
 Versions::def_section_contents<64, true>(
@@ -1607,7 +1696,9 @@ Versions::def_section_contents<64, true>(
     unsigned int*,
     unsigned int*
     ACCEPT_SIZE_ENDIAN_EXPLICIT(64, true)) const;
+#endif
 
+#ifdef HAVE_TARGET_32_LITTLE
 template
 void
 Versions::need_section_contents<32, false>(
@@ -1616,7 +1707,9 @@ Versions::need_section_contents<32, false>(
     unsigned int*,
     unsigned int*
     ACCEPT_SIZE_ENDIAN_EXPLICIT(32, false)) const;
+#endif
 
+#ifdef HAVE_TARGET_32_BIG
 template
 void
 Versions::need_section_contents<32, true>(
@@ -1625,7 +1718,9 @@ Versions::need_section_contents<32, true>(
     unsigned int*,
     unsigned int*
     ACCEPT_SIZE_ENDIAN_EXPLICIT(32, true)) const;
+#endif
 
+#ifdef HAVE_TARGET_64_LITTLE
 template
 void
 Versions::need_section_contents<64, false>(
@@ -1634,7 +1729,9 @@ Versions::need_section_contents<64, false>(
     unsigned int*,
     unsigned int*
     ACCEPT_SIZE_ENDIAN_EXPLICIT(64, false)) const;
+#endif
 
+#ifdef HAVE_TARGET_64_BIG
 template
 void
 Versions::need_section_contents<64, true>(
@@ -1643,5 +1740,6 @@ Versions::need_section_contents<64, true>(
     unsigned int*,
     unsigned int*
     ACCEPT_SIZE_ENDIAN_EXPLICIT(64, true)) const;
+#endif
 
 } // End namespace gold.
This page took 0.03021 seconds and 4 git commands to generate.