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]

Re: [GOLD] [PATCH] Casting plugin onload entry point


Viktor Kutuzov <vkutuzov@accesssoftek.com> writes:

> Depending on the version of the compiler, the way how plugin onload
> entry point is casted may give a compilation error: "ISO C++ forbids
> casting between pointer-to-function and pointer-to-object".
>
> The attached patch fixes this issue by using the workaround introduced by the POSIX.1-2003.

>   *(void **)(&onload) = dlsym(this->handle_, "onload");

Thanks for pointing that out.  I hope that POSIX doesn't really
recommend your approach, though, as it is an aliasing violation.  I
committed this patch to fix the problem in a way that should be
standard compliant.

Ian


2009-12-09  Ian Lance Taylor  <iant@google.com>

	* plugin.cc (Plugin::load): Don't cast from void* to a function
	pointer.


Index: plugin.cc
===================================================================
RCS file: /cvs/src/src/gold/plugin.cc,v
retrieving revision 1.23
diff -u -p -r1.23 plugin.cc
--- plugin.cc	28 Oct 2009 18:07:25 -0000	1.23
+++ plugin.cc	10 Dec 2009 07:43:47 -0000
@@ -109,14 +109,16 @@ Plugin::load()
     }
 
   // Find the plugin's onload entry point.
-  ld_plugin_onload onload = reinterpret_cast<ld_plugin_onload>
-    (dlsym(this->handle_, "onload"));
-  if (onload == NULL)
+  void* ptr = dlsym(this->handle_, "onload");
+  if (ptr == NULL)
     {
       gold_error(_("%s: could not find onload entry point"),
                  this->filename_.c_str());
       return;
     }
+  ld_plugin_onload onload;
+  gold_assert(sizeof(onload) == sizeof(ptr));
+  memcpy(&onload, &ptr, sizeof(ptr));
 
   // Get the linker's version number.
   const char* ver = get_version_string();

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