You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modules-dev@httpd.apache.org by Mark Taylor <mt...@gmail.com> on 2016/01/07 04:30:52 UTC

dlopen a .so from a module

Hi all,

I have a module that dlopens a .so, gets a handle to a function in the so
and calls it. The function in the so calls ap_rputs.  dlopen returns the
error 'undefined symbol ap_rputs'.

nm tells me ap_rputs is defined in httpd, and via some dark magic, httpd
symbols are available to modules compiles the apxs -c.  But when I compile
my .so to be loaded into my module, the symbols from httpd aren't
available. My hypothesis, now disproven, was that symbols available to my
module would be visible to my .so.

Does anyone have any insight into this process? How do modules resolve
symbols from httpd, while my .so cannot?

-Mark

Re: dlopen a .so from a module

Posted by Mark Taylor <mt...@gmail.com>.
Thanks Nick,

Replacing ap_rputs with ap_rwrite in my .so worked although I'm not clear
on why?

Right now I'm just using dlopen/dlsym for test/proof of concept.  The .so
could change externally and require reloading at runtime so that's why I'm
not using LoadFile.

Incidentally, I bought your book a while back, it's really a hell of a
thing, thanks for writing it!

-Mark

On Thu, Jan 7, 2016 at 12:16 AM, Nick Kew <ni...@apache.org> wrote:

> On Wed, 2016-01-06 at 21:30 -0600, Mark Taylor wrote:
> > Hi all,
> >
> > I have a module that dlopens a .so, gets a handle to a function in the so
> > and calls it. The function in the so calls ap_rputs.  dlopen returns the
> > error 'undefined symbol ap_rputs'.
>
> Looks like you're falling victim to
> http://svn.apache.org/viewvc?view=revision&revision=1131465
> which also points to ap_rwrite as an obvious workaround.
> That would've caught me out, too!
>
> > nm tells me ap_rputs is defined in httpd, and via some dark magic, httpd
> > symbols are available to modules compiles the apxs -c.  But when I
> compile
> > my .so to be loaded into my module, the symbols from httpd aren't
> > available. My hypothesis, now disproven, was that symbols available to my
> > module would be visible to my .so.
>
> Does your module use dlopen or apr_dso_load/family?
>
> Is your module loading/unloading anything per-request or
> per-connection?  If not, why not use LoadFile in httpd.conf
> to load the .so?
>
> --
> Nick Kew
>
>

Re: dlopen a .so from a module

Posted by Nick Kew <ni...@apache.org>.
On Wed, 2016-01-06 at 21:30 -0600, Mark Taylor wrote:
> Hi all,
> 
> I have a module that dlopens a .so, gets a handle to a function in the so
> and calls it. The function in the so calls ap_rputs.  dlopen returns the
> error 'undefined symbol ap_rputs'.

Looks like you're falling victim to
http://svn.apache.org/viewvc?view=revision&revision=1131465
which also points to ap_rwrite as an obvious workaround.
That would've caught me out, too!

> nm tells me ap_rputs is defined in httpd, and via some dark magic, httpd
> symbols are available to modules compiles the apxs -c.  But when I compile
> my .so to be loaded into my module, the symbols from httpd aren't
> available. My hypothesis, now disproven, was that symbols available to my
> module would be visible to my .so.

Does your module use dlopen or apr_dso_load/family?

Is your module loading/unloading anything per-request or
per-connection?  If not, why not use LoadFile in httpd.conf
to load the .so?

-- 
Nick Kew