Re: narwhal and PGDLLIMPORT

From: Andres Freund <andres(at)2ndquadrant(dot)com>
To: Craig Ringer <craig(at)2ndquadrant(dot)com>
Cc: Peter Eisentraut <peter_e(at)gmx(dot)net>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Hiroshi Inoue <inoue(at)tpf(dot)co(dot)jp>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Robert Haas <robertmhaas(at)gmail(dot)com>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: narwhal and PGDLLIMPORT
Date: 2014-02-13 00:26:03
Message-ID: 20140213002603.GA4910@awork2.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 2014-02-13 07:58:09 +0800, Craig Ringer wrote:
> On 02/13/2014 05:35 AM, Peter Eisentraut wrote:
> > On 2/12/14, 4:30 PM, Andres Freund wrote:
> >>> There are cases where one module needs symbols from another directly.
> >>> Would that be affected by this?
> >>
> >> I don't think we have real infrastructure for that yet. Neither from the POV of loading several .so's, nor from a symbol visibility. Afaics we'd need a working definition of PGDLLIMPORT which inverts the declspecs. I think Tom just removed the remnants of that.
> >
> > It works reasonably well on other platforms.
> >
> > Of course, we can barely build extension modules on Windows, so maybe
> > this is a bit much to ask. But as long as we're dealing only with
> > functions, not variables, it should work without any dllimport dances,
> > right?
>
> Don't think so.
>
> If you don't have __declspec(dllexport) or a .DEF file marking something
> as exported, it's not part of the DLL interface at all, it's like you
> compiled it with gcc using -fvisibility=hidden and didn't give the
> symbol __attribute__((visibility ("default")) .
>
> If you _do_ have the symbol exported from the DLL, using
> __declspec(dllimport) or a generated .DEF file that exposes all
> "extern"s, you can link to the symbol.
>
> However, from the reading I've done recently, I'm pretty sure that if
> you fail to declare __declspec(dllimport) on the importing side, you
> actually land up statically linking to a thunk function that in turn
> calls the real function in the DLL. So it works, but at a performance cost.
>
> So you should do the dance. Sorry.

I don't think the thunk function will have such a high overhead in this
day and age. And it's what we essentially already do for all functions
called *from* extensions, no?

> It gets worse, too. Say you want hstore to export a couple of symbols.
> Those symbols must be __declspec(dllexport) while everything else in
> headers must be __declspec(dllimport). This means you can't just use
> PGDLLIMPORT. You must define a HSTOREDLLIMPORT that's
> __declspec(dllexport) when compiling hstore and otherwise
> __declspec(dllimport). Then set a preprocessor macro like
> -DCOMPILING_HSTORE to trigger it.

We actually have a a macro that should do that, namely PGDLLEXPORT. I am
not sure though, why it's not dependent on dependent on BUILDING_DLL
(which is absolutely horribly misnamed, being essentially inverted).

Greetings,

Andres Freund

--
Andres Freund http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Craig Ringer 2014-02-13 00:35:32 Re: narwhal and PGDLLIMPORT
Previous Message Tom Lane 2014-02-13 00:24:02 Re: narwhal and PGDLLIMPORT