From Craig Silverstein: Don't crash if we see a file we don't recognize.
authorIan Lance Taylor <iant@google.com>
Wed, 7 Nov 2007 00:31:32 +0000 (00:31 +0000)
committerIan Lance Taylor <iant@google.com>
Wed, 7 Nov 2007 00:31:32 +0000 (00:31 +0000)
gold/archive.cc
gold/object.cc

index 4d95b7901d63f242afe99e06bf5cf4155dc6bb9a..5862f34a6f631cc213c91ddbb6082775eb01f1d0 100644 (file)
@@ -399,12 +399,19 @@ Archive::include_member(Symbol_table* symtab, Layout* layout,
                                this->input_file_, memoff, ehdr_buf,
                                read_size);
 
-  input_objects->add_object(obj);
+  if (input_objects->add_object(obj))
+    {
+      Read_symbols_data sd;
+      obj->read_symbols(&sd);
+      obj->layout(symtab, layout, &sd);
+      obj->add_symbols(symtab, &sd);
+    }
+  else
+    {
+      // FIXME: We need to close the descriptor here.
+      delete obj;
+    }
 
-  Read_symbols_data sd;
-  obj->read_symbols(&sd);
-  obj->layout(symtab, layout, &sd);
-  obj->add_symbols(symtab, &sd);
 }
 
 // Add_archive_symbols methods.
index 58f0db0824286b1f7a29cc7253ff4a6f87e64ba4..8efd4ec7e35e43d4d466cc67921654cc425fb49a 100644 (file)
@@ -866,6 +866,15 @@ Sized_relobj<size, big_endian>::get_symbol_location_info(
 bool
 Input_objects::add_object(Object* obj)
 {
+  Target* target = obj->target();
+  if (this->target_ == NULL)
+    this->target_ = target;
+  else if (this->target_ != target)
+    {
+      gold_error(_("%s: incompatible target"), obj->name().c_str());
+      return false;
+    }
+
   if (!obj->is_dynamic())
     this->relobj_list_.push_back(static_cast<Relobj*>(obj));
   else
@@ -884,15 +893,6 @@ Input_objects::add_object(Object* obj)
       this->dynobj_list_.push_back(dynobj);
     }
 
-  Target* target = obj->target();
-  if (this->target_ == NULL)
-    this->target_ = target;
-  else if (this->target_ != target)
-    {
-      gold_error(_("%s: incompatible target"), obj->name().c_str());
-      return false;
-    }
-
   set_parameters_size_and_endianness(target->get_size(),
                                     target->is_big_endian());