* nto-procfs.c (get_regset): Pass correct pointer.
[deliverable/binutils-gdb.git] / gold / object.cc
index d1e16727032d83f6f69a6bcd5bed30b676ba20b9..75fb67970ea7326494ce78d1d78d567249c7d53e 100644 (file)
@@ -1873,8 +1873,8 @@ Sized_relobj<size, big_endian>::map_to_kept_section(
       *found = true;
       Output_section* os = kept->object_->output_section(kept->shndx_);
       Address offset = kept->object_->get_output_section_offset(kept->shndx_);
-      gold_assert(os != NULL && offset != invalid_address);
-      return os->address() + offset;
+      if (os != NULL && offset != invalid_address)
+        return os->address() + offset;
     }
   *found = false;
   return 0;
@@ -2100,6 +2100,33 @@ make_elf_sized_object(const std::string& name, Input_file* input_file,
 namespace gold
 {
 
+// Return whether INPUT_FILE is an ELF object.
+
+bool
+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;
+  if (filesize - offset < want)
+    want = filesize - offset;
+
+  const unsigned char* p = input_file->file().get_view(offset, 0, want,
+                                                      true, false);
+  *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;
+}
+
 // Read an ELF file and return the appropriate instance of Object.
 
 Object*
This page took 0.033433 seconds and 4 git commands to generate.