This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] Let plugins know the final size of common symbols


When resolving common symbols, gold will always keep the first one it
finds. It will then patch the size if a larger one shows up. This is
fine, but this information is currently never passed to the plugin
which may end up producing a final .o file with a symbol that is too
small.

The attached patch changes Pluginobj::get_symbol_resolution_info to
set the size of  ld_plugin_symbol in addition to the resolution. With
this information the plugin can then update its view on the common
symbol and produce an ELF file where the symbol has the correct size.

Cheers,
Rafael


2014-07-08  Rafael Ãvila de EspÃndola <rafael.espindola@gmail.com>

        * plugin.h (Sized_pluginobj::do_get_symbol_resolution_info): Moved from
        Pluginobj.
        * plugin.cc (Sized_pluginobj::do_get_symbol_resolution_info): Update the
        symbol size.
diff --git a/gold/plugin.cc b/gold/plugin.cc
index 6519732..ba3f590 100644
--- a/gold/plugin.cc
+++ b/gold/plugin.cc
@@ -908,11 +908,10 @@ is_visible_from_outside(Symbol* lsym)
 
 // Get symbol resolution info.
 
+template <int size, bool big_endian>
 ld_plugin_status
-Pluginobj::get_symbol_resolution_info(int nsyms,
-				      ld_plugin_symbol* syms,
-				      int version) const
-{
+Sized_pluginobj<size, big_endian>::do_get_symbol_resolution_info(
+    int nsyms, ld_plugin_symbol *syms, int version) const {
   // For version 1 of this interface, we cannot use
   // LDPR_PREVAILING_DEF_IRONLY_EXP, so we return LDPR_PREVAILING_DEF
   // instead.
@@ -937,9 +936,12 @@ Pluginobj::get_symbol_resolution_info(int nsyms,
   for (int i = 0; i < nsyms; i++)
     {
       ld_plugin_symbol* isym = &syms[i];
-      Symbol* lsym = this->symbols_[i];
+      Sized_symbol<size>* lsym =
+          static_cast<Sized_symbol<size>*>(this->symbols_[i]);
       ld_plugin_symbol_resolution res = LDPR_UNKNOWN;
 
+      isym->size = lsym->symsize();
+
       if (lsym->is_undefined())
         // The symbol remains undefined.
         res = LDPR_UNDEF;
diff --git a/gold/plugin.h b/gold/plugin.h
index 9ef2812..771ba38 100644
--- a/gold/plugin.h
+++ b/gold/plugin.h
@@ -395,7 +395,9 @@ class Pluginobj : public Object
   ld_plugin_status
   get_symbol_resolution_info(int nsyms,
 			     ld_plugin_symbol* syms,
-			     int version) const;
+			     int version) const {
+    return do_get_symbol_resolution_info(nsyms, syms, version);
+  }
 
   // Store the incoming symbols from the plugin for later processing.
   void
@@ -431,6 +433,11 @@ class Pluginobj : public Object
   do_pluginobj()
   { return this; }
 
+  virtual ld_plugin_status
+  do_get_symbol_resolution_info(int nsyms,
+			     ld_plugin_symbol* syms,
+			     int version) const = 0;
+
   // The number of symbols provided by the plugin.
   int nsyms_;
 
@@ -543,6 +550,11 @@ class Sized_pluginobj : public Pluginobj
 
  protected:
 
+  ld_plugin_status
+  do_get_symbol_resolution_info(int nsyms,
+                                ld_plugin_symbol* syms,
+                                int version) const;
+
  private:
 };
 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]