OSDN Git Service

2009-10-11 Michael Snyder <msnyder@vmware.com>
[pf3gnuchains/pf3gnuchains3x.git] / gold / object.cc
index 4d892c8..e09a71f 100644 (file)
@@ -231,6 +231,25 @@ Object::handle_gnu_warning_section(const char* name, unsigned int shndx,
   return false;
 }
 
+// If NAME is the name of the special section which indicates that
+// this object was compiled with -fstack-split, mark it accordingly.
+
+bool
+Object::handle_split_stack_section(const char* name)
+{
+  if (strcmp(name, ".note.GNU-split-stack") == 0)
+    {
+      this->uses_split_stack_ = true;
+      return true;
+    }
+  if (strcmp(name, ".note.GNU-no-split-stack") == 0)
+    {
+      this->has_no_split_stack_ = true;
+      return true;
+    }
+  return false;
+}
+
 // Class Relobj
 
 // To copy the symbols data read from the file to a local data structure.
@@ -340,7 +359,7 @@ Sized_relobj<size, big_endian>::~Sized_relobj()
 
 template<int size, bool big_endian>
 void
-Sized_relobj<size, big_endian>::setup()
+Sized_relobj<size, big_endian>::do_setup()
 {
   const unsigned int shnum = this->elf_file_.shnum();
   this->set_shnum(shnum);
@@ -1109,6 +1128,16 @@ Sized_relobj<size, big_endian>::do_layout(Symbol_table* symtab,
              omit[i] = true;
             }
 
+         // The .note.GNU-split-stack section is also special.  It
+         // indicates that the object was compiled with
+         // -fsplit-stack.
+         if (this->handle_split_stack_section(name))
+           {
+             if (!parameters->options().relocatable()
+                 && !parameters->options().shared())
+               omit[i] = true;
+           }
+
           bool discard = omit[i];
           if (!discard)
             {
@@ -2252,7 +2281,7 @@ is_elf_object(Input_file* input_file, off_t offset,
              const unsigned char** start, int *read_size)
 {
   off_t filesize = input_file->file().filesize();
-  int want = elfcpp::Elf_sizes<64>::ehdr_size;
+  int want = elfcpp::Elf_recognizer::max_header_size;
   if (filesize - offset < want)
     want = filesize - offset;
 
@@ -2261,15 +2290,7 @@ is_elf_object(Input_file* input_file, off_t offset,
   *start = p;
   *read_size = want;
 
-  if (want < 4)
-    return false;
-
-  static unsigned char elfmagic[4] =
-    {
-      elfcpp::ELFMAG0, elfcpp::ELFMAG1,
-      elfcpp::ELFMAG2, elfcpp::ELFMAG3
-    };
-  return memcmp(p, elfmagic, 4) == 0;
+  return elfcpp::Elf_recognizer::is_elf_file(p, want);
 }
 
 // Read an ELF file and return the appropriate instance of Object.
@@ -2282,57 +2303,18 @@ make_elf_object(const std::string& name, Input_file* input_file, off_t offset,
   if (punconfigured != NULL)
     *punconfigured = false;
 
-  if (bytes < elfcpp::EI_NIDENT)
-    {
-      gold_error(_("%s: ELF file too short"), name.c_str());
-      return NULL;
-    }
-
-  int v = p[elfcpp::EI_VERSION];
-  if (v != elfcpp::EV_CURRENT)
-    {
-      if (v == elfcpp::EV_NONE)
-       gold_error(_("%s: invalid ELF version 0"), name.c_str());
-      else
-       gold_error(_("%s: unsupported ELF version %d"), name.c_str(), v);
-      return NULL;
-    }
-
-  int c = p[elfcpp::EI_CLASS];
-  if (c == elfcpp::ELFCLASSNONE)
-    {
-      gold_error(_("%s: invalid ELF class 0"), name.c_str());
-      return NULL;
-    }
-  else if (c != elfcpp::ELFCLASS32
-          && c != elfcpp::ELFCLASS64)
+  std::string error;
+  bool big_endian;
+  int size;
+  if (!elfcpp::Elf_recognizer::is_valid_header(p, bytes, &size,
+                                               &big_endian, &error))
     {
-      gold_error(_("%s: unsupported ELF class %d"), name.c_str(), c);
+      gold_error(_("%s: %s"), name.c_str(), error.c_str());
       return NULL;
     }
 
-  int d = p[elfcpp::EI_DATA];
-  if (d == elfcpp::ELFDATANONE)
-    {
-      gold_error(_("%s: invalid ELF data encoding"), name.c_str());
-      return NULL;
-    }
-  else if (d != elfcpp::ELFDATA2LSB
-          && d != elfcpp::ELFDATA2MSB)
+  if (size == 32)
     {
-      gold_error(_("%s: unsupported ELF data encoding %d"), name.c_str(), d);
-      return NULL;
-    }
-
-  bool big_endian = d == elfcpp::ELFDATA2MSB;
-
-  if (c == elfcpp::ELFCLASS32)
-    {
-      if (bytes < elfcpp::Elf_sizes<32>::ehdr_size)
-       {
-         gold_error(_("%s: ELF file too short"), name.c_str());
-         return NULL;
-       }
       if (big_endian)
        {
 #ifdef HAVE_TARGET_32_BIG
@@ -2366,13 +2348,8 @@ make_elf_object(const std::string& name, Input_file* input_file, off_t offset,
 #endif
        }
     }
-  else
+  else if (size == 64)
     {
-      if (bytes < elfcpp::Elf_sizes<64>::ehdr_size)
-       {
-         gold_error(_("%s: ELF file too short"), name.c_str());
-         return NULL;
-       }
       if (big_endian)
        {
 #ifdef HAVE_TARGET_64_BIG
@@ -2406,6 +2383,8 @@ make_elf_object(const std::string& name, Input_file* input_file, off_t offset,
 #endif
        }
     }
+  else
+    gold_unreachable();
 }
 
 // Instantiate the templates we need.