This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [GOLD] [PATCH] Casting plugin onload entry point
- From: Ian Lance Taylor <iant at google dot com>
- To: Viktor Kutuzov <vkutuzov at accesssoftek dot com>
- Cc: <binutils at sourceware dot org>
- Date: Wed, 09 Dec 2009 23:46:08 -0800
- Subject: Re: [GOLD] [PATCH] Casting plugin onload entry point
- References: <6AE1604EE3EC5F4296C096518C6B77EEE56FBF79@mail.accesssoftek.com> <6AE1604EE3EC5F4296C096518C6B77EEE56FBF7F@mail.accesssoftek.com> <6AE1604EE3EC5F4296C096518C6B77EEED7DBE12@mail.accesssoftek.com> <6AE1604EE3EC5F4296C096518C6B77EEED7DBE18@mail.accesssoftek.com> <71D42A22F6FB467FA698FE3D4193E555@andreic6e7fe55>
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();