Pass the elf object of the archive files to a linker plugin's claim file handler

Sriraman Tallam tmsriram@google.com
Sat Mar 30 00:29:00 GMT 2013


Hi,

   Currently, the elf object of archive files is not passed to a
linker plugin's claim file handler.  This means APIs like
get_section_count will not work on archive files.  The following patch
fixes this by creating an elf object for archive files before the
plugin's claim file handler is invoked.  If the plugin claims the file
then the elf object is deleted.  This is similar to how regular
objects are handled in readsyms.cc.

Is this alright?

Thanks
Sri
-------------- next part --------------
	* archive.cc (Archive::get_elf_object_for_member):  Create the elf
	object before calling the plugin claim_file handler.  Pass the elf
	object of the archive to the plugin. Delete the elf object if the
	plugin claims the file.

Index: archive.cc
===================================================================
RCS file: /cvs/src/src/gold/archive.cc,v
retrieving revision 1.71
diff -u -p -r1.71 archive.cc
--- archive.cc	17 Apr 2012 00:28:41 -0000	1.71
+++ archive.cc	30 Mar 2013 00:20:45 -0000
@@ -654,33 +654,45 @@ Archive::get_elf_object_for_member(off_t
 				 &member_name))
     return NULL;
 
+  const unsigned char* ehdr;
+  int read_size;
+  Object *obj = NULL;
+  bool is_elf_obj = false;
+
+  if (is_elf_object(input_file, memoff, &ehdr, &read_size))
+    {
+      obj = make_elf_object((std::string(this->input_file_->filename())
+			     + "(" + member_name + ")"),
+			    input_file, memoff, ehdr, read_size,
+			    punconfigured);
+      is_elf_obj = true;
+    }
+
   if (parameters->options().has_plugins())
     {
-      Object* obj = parameters->options().plugins()->claim_file(input_file,
-                                                                memoff,
-                                                                memsize,
-								NULL);
-      if (obj != NULL)
+      Object* plugin_obj
+	= parameters->options().plugins()->claim_file(input_file,
+						      memoff,
+						      memsize,
+						      obj);
+      if (plugin_obj != NULL)
         {
           // The input file was claimed by a plugin, and its symbols
           // have been provided by the plugin.
-          return obj;
+	  // Delete its elf object.
+	  if (obj != NULL)
+	    delete obj;
+          return plugin_obj;
         }
     }
 
-  const unsigned char* ehdr;
-  int read_size;
-  if (!is_elf_object(input_file, memoff, &ehdr, &read_size))
+  if (!is_elf_obj)
     {
       gold_error(_("%s: member at %zu is not an ELF object"),
 		 this->name().c_str(), static_cast<size_t>(off));
       return NULL;
     }
 
-  Object* obj = make_elf_object((std::string(this->input_file_->filename())
-				 + "(" + member_name + ")"),
-				input_file, memoff, ehdr, read_size,
-				punconfigured);
   if (obj == NULL)
     return NULL;
   obj->set_no_export(this->no_export());


More information about the Binutils mailing list