public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* [PLUGIN] dlopen and RTLD_NOW
@ 2011-09-05  7:50 Romain Geissler
  2011-09-05  7:51 ` Richard Guenther
  2011-09-06 17:56 ` David Daney
  0 siblings, 2 replies; 8+ messages in thread
From: Romain Geissler @ 2011-09-05  7:50 UTC (permalink / raw)
  To: gcc

Hi

Is there any particular reason to load plugin with the RTLD_NOW option?
This option force .so symbol resolution to be completely made at load time,
but this could be done only when a symbol is needed (RTLD_NOW).

Here is the dlopen line in plugin.c:
dl_handle = dlopen (plugin->full_name, RTLD_NOW | RTLD_GLOBAL);

My issue is, I want to load the same plugin.so in both cc1 and cc1plus, but
in the C++ case, I may need to reference some cc1plus specific symbols. I can
check whether cc1 or cc1plus loaded the plugin and thus use custom C++
symbols only when present. With RTLD_NOW, the plugin fails to load in cc1 as
symbol resolution is forced at load time.

If RTLD_NOW is removed, dlopen falls back to the RTLD_LAZY mode which fits
my need. Moreover, if one can force the complete symbol resolution at load time
by defining the environment LD_BIND_NOW variable.

So, is RTLD_NOW use justified ?

Romain Geissler

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PLUGIN] dlopen and RTLD_NOW
  2011-09-05  7:50 [PLUGIN] dlopen and RTLD_NOW Romain Geissler
@ 2011-09-05  7:51 ` Richard Guenther
  2011-09-05  8:10   ` Jakub Jelinek
  2011-09-06 17:56 ` David Daney
  1 sibling, 1 reply; 8+ messages in thread
From: Richard Guenther @ 2011-09-05  7:51 UTC (permalink / raw)
  To: Romain Geissler; +Cc: gcc

On Mon, Sep 5, 2011 at 9:50 AM, Romain Geissler
<romain.geissler@gmail.com> wrote:
> Hi
>
> Is there any particular reason to load plugin with the RTLD_NOW option?
> This option force .so symbol resolution to be completely made at load time,
> but this could be done only when a symbol is needed (RTLD_NOW).
>
> Here is the dlopen line in plugin.c:
> dl_handle = dlopen (plugin->full_name, RTLD_NOW | RTLD_GLOBAL);
>
> My issue is, I want to load the same plugin.so in both cc1 and cc1plus, but
> in the C++ case, I may need to reference some cc1plus specific symbols. I can
> check whether cc1 or cc1plus loaded the plugin and thus use custom C++
> symbols only when present. With RTLD_NOW, the plugin fails to load in cc1 as
> symbol resolution is forced at load time.
>
> If RTLD_NOW is removed, dlopen falls back to the RTLD_LAZY mode which fits
> my need. Moreover, if one can force the complete symbol resolution at load time
> by defining the environment LD_BIND_NOW variable.
>
> So, is RTLD_NOW use justified ?

Not really, neither RTLD_GLOBAL.

Richard.

> Romain Geissler
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PLUGIN] dlopen and RTLD_NOW
  2011-09-05  7:51 ` Richard Guenther
@ 2011-09-05  8:10   ` Jakub Jelinek
  2011-09-05 17:22     ` Andrew Pinski
  0 siblings, 1 reply; 8+ messages in thread
From: Jakub Jelinek @ 2011-09-05  8:10 UTC (permalink / raw)
  To: Richard Guenther; +Cc: Romain Geissler, gcc

On Mon, Sep 05, 2011 at 09:51:34AM +0200, Richard Guenther wrote:
> > My issue is, I want to load the same plugin.so in both cc1 and cc1plus, but
> > in the C++ case, I may need to reference some cc1plus specific symbols. I can
> > check whether cc1 or cc1plus loaded the plugin and thus use custom C++
> > symbols only when present. With RTLD_NOW, the plugin fails to load in cc1 as
> > symbol resolution is forced at load time.
> >
> > If RTLD_NOW is removed, dlopen falls back to the RTLD_LAZY mode which fits
> > my need. Moreover, if one can force the complete symbol resolution at load time
> > by defining the environment LD_BIND_NOW variable.
> >
> > So, is RTLD_NOW use justified ?
> 
> Not really, neither RTLD_GLOBAL.

That said, relying on lazy binding is terribly bad design.

	Jakub

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PLUGIN] dlopen and RTLD_NOW
  2011-09-05  8:10   ` Jakub Jelinek
@ 2011-09-05 17:22     ` Andrew Pinski
  2011-09-05 17:47       ` Jakub Jelinek
  0 siblings, 1 reply; 8+ messages in thread
From: Andrew Pinski @ 2011-09-05 17:22 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Richard Guenther, Romain Geissler, gcc

On Mon, Sep 5, 2011 at 1:10 AM, Jakub Jelinek <jakub@redhat.com> wrote:
> That said, relying on lazy binding is terribly bad design.

In fact I was going to say why can't those symbols be marked as weak
in your plugin?  You don't even need to change the GCC headers, just
have an extra header that does:
#pargma weak

Thanks,
Andrew Pinski

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PLUGIN] dlopen and RTLD_NOW
  2011-09-05 17:22     ` Andrew Pinski
@ 2011-09-05 17:47       ` Jakub Jelinek
  2011-09-06  7:47         ` Romain Geissler
  0 siblings, 1 reply; 8+ messages in thread
From: Jakub Jelinek @ 2011-09-05 17:47 UTC (permalink / raw)
  To: Andrew Pinski; +Cc: Richard Guenther, Romain Geissler, gcc

On Mon, Sep 05, 2011 at 10:22:10AM -0700, Andrew Pinski wrote:
> On Mon, Sep 5, 2011 at 1:10 AM, Jakub Jelinek <jakub@redhat.com> wrote:
> > That said, relying on lazy binding is terribly bad design.
> 
> In fact I was going to say why can't those symbols be marked as weak
> in your plugin?  You don't even need to change the GCC headers, just
> have an extra header that does:
> #pargma weak

s/pargma/pragma/.  Yeah, making them weak will work just fine, independently
on whether it is RTLD_NOW or not, or, when program is directly linked
against it, with LD_BIND_NOW=1 or not.

	Jakub

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PLUGIN] dlopen and RTLD_NOW
  2011-09-05 17:47       ` Jakub Jelinek
@ 2011-09-06  7:47         ` Romain Geissler
  0 siblings, 0 replies; 8+ messages in thread
From: Romain Geissler @ 2011-09-06  7:47 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Andrew Pinski, Richard Guenther, gcc

2011/9/5 Jakub Jelinek <jakub@redhat.com>:
> On Mon, Sep 05, 2011 at 10:22:10AM -0700, Andrew Pinski wrote:
>> On Mon, Sep 5, 2011 at 1:10 AM, Jakub Jelinek <jakub@redhat.com> wrote:
>> > That said, relying on lazy binding is terribly bad design.
>>
>> In fact I was going to say why can't those symbols be marked as weak
>> in your plugin?  You don't even need to change the GCC headers, just
>> have an extra header that does:
>> #pargma weak
>
> s/pargma/pragma/.  Yeah, making them weak will work just fine, independently
> on whether it is RTLD_NOW or not, or, when program is directly linked
> against it, with LD_BIND_NOW=1 or not.
>
>        Jakub
>

Thanks, it works fine. I didn't know about weak symbols.

Romain Geissler

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PLUGIN] dlopen and RTLD_NOW
  2011-09-05  7:50 [PLUGIN] dlopen and RTLD_NOW Romain Geissler
  2011-09-05  7:51 ` Richard Guenther
@ 2011-09-06 17:56 ` David Daney
  2011-09-06 18:17   ` David Daney
  1 sibling, 1 reply; 8+ messages in thread
From: David Daney @ 2011-09-06 17:56 UTC (permalink / raw)
  To: Romain Geissler; +Cc: gcc

On 09/05/2011 12:50 AM, Romain Geissler wrote:
> Hi
>
> Is there any particular reason to load plugin with the RTLD_NOW option?
> This option force .so symbol resolution to be completely made at load time,
> but this could be done only when a symbol is needed (RTLD_NOW).
>
> Here is the dlopen line in plugin.c:
> dl_handle = dlopen (plugin->full_name, RTLD_NOW | RTLD_GLOBAL);
>
> My issue is, I want to load the same plugin.so in both cc1 and cc1plus, but
> in the C++ case, I may need to reference some cc1plus specific symbols. I can
> check whether cc1 or cc1plus loaded the plugin and thus use custom C++
> symbols only when present. With RTLD_NOW, the plugin fails to load in cc1 as
> symbol resolution is forced at load time.
>

Can you supply weak binding implementations for the missing functions? 
That might allow the linking to succeed.

David Daney

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PLUGIN] dlopen and RTLD_NOW
  2011-09-06 17:56 ` David Daney
@ 2011-09-06 18:17   ` David Daney
  0 siblings, 0 replies; 8+ messages in thread
From: David Daney @ 2011-09-06 18:17 UTC (permalink / raw)
  To: David Daney; +Cc: Romain Geissler, gcc

On 09/06/2011 10:55 AM, David Daney wrote:
> On 09/05/2011 12:50 AM, Romain Geissler wrote:
>> Hi
>>
>> Is there any particular reason to load plugin with the RTLD_NOW option?
>> This option force .so symbol resolution to be completely made at load
>> time,
>> but this could be done only when a symbol is needed (RTLD_NOW).
>>
>> Here is the dlopen line in plugin.c:
>> dl_handle = dlopen (plugin->full_name, RTLD_NOW | RTLD_GLOBAL);
>>
>> My issue is, I want to load the same plugin.so in both cc1 and
>> cc1plus, but
>> in the C++ case, I may need to reference some cc1plus specific
>> symbols. I can
>> check whether cc1 or cc1plus loaded the plugin and thus use custom C++
>> symbols only when present. With RTLD_NOW, the plugin fails to load in
>> cc1 as
>> symbol resolution is forced at load time.
>>
>
> Can you supply weak binding implementations for the missing functions?
> That might allow the linking to succeed.
>

... And if I read the entire thread before responding, I would have seen 
that others had already suggested the same thing.

Sorry for the noise.

David Daney

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2011-09-06 18:17 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-05  7:50 [PLUGIN] dlopen and RTLD_NOW Romain Geissler
2011-09-05  7:51 ` Richard Guenther
2011-09-05  8:10   ` Jakub Jelinek
2011-09-05 17:22     ` Andrew Pinski
2011-09-05 17:47       ` Jakub Jelinek
2011-09-06  7:47         ` Romain Geissler
2011-09-06 17:56 ` David Daney
2011-09-06 18:17   ` David Daney

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).