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
symbolvisibility. Afaics we'd need a working definition of PGDLLIMPORT which inverts the declspecs. I think Tom just
removedthe 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.
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.
Even though we're generating .DEF files, I don't think we can avoid
that, because we at minimum need to have the hstore exported symbols
*not* annotated __declspec(dllimport) when compiling hstore, but have
them so annotated when importing the header into anything else.
(Come to think of it, how're we dealing with this in libpq? I wonder if
postgres is linking to libpq using thunk functions?)
-- Craig Ringer http://www.2ndQuadrant.com/PostgreSQL Development, 24x7 Support, Training & Services