After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 138402 - [cygwin patch] Symbols not exported from DLL
[cygwin patch] Symbols not exported from DLL
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: win32
2.4.x
Other Windows
: Normal normal
: ---
Assigned To: gtk-win32 maintainers
gtk-win32 maintainers
: 139491 (view as bug list)
Depends on:
Blocks: 137591
 
 
Reported: 2004-03-29 13:21 UTC by Roger Leigh
Modified: 2011-02-18 16:07 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
rl-glib-CVSHEAD-cygwin-exports.patch (1.89 KB, patch)
2004-03-29 13:21 UTC, Roger Leigh
none Details | Review
rl-glib-CVSHEAD-cygwin-gmodule2.patch (1.79 KB, patch)
2004-04-06 14:51 UTC, Roger Leigh
none Details | Review
rl-glib-CVSHEAD-cygwin-gmodule-BROKEN.patch (637 bytes, patch)
2004-04-06 14:54 UTC, Roger Leigh
none Details | Review

Description Roger Leigh 2004-03-29 13:21:11 UTC
Programs fail to link with cygglib.dll on Cygwin, because only five symbols are
exported.  This is because __declspec(dllimport) is used, which prevents symbol
automatic export.

The patch makes this conditional only for G_OS_WIN32, rather than
G_PLATFORM_WIN32, so all the symbols are correctly exported when building on Cygwin.
Comment 1 Roger Leigh 2004-03-29 13:21:49 UTC
Created attachment 26058 [details] [review]
rl-glib-CVSHEAD-cygwin-exports.patch

Against CVS HEAD.
Comment 2 Tor Lillqvist 2004-03-30 01:31:16 UTC
So building on Cygwin doesn't use the .def file? Patch looks fine.
Comment 3 Roger Leigh 2004-03-30 10:57:19 UTC
I think the def file is ignored, and all symbols are exported.  However, when
__declspec(dllimport) is used, this overrides automatic symbol export, so
disabling this for Cygwin makes the default behaviour work correctly.  At least,
this is what I *think* happens, according to the gcc/ld docs.
Comment 4 Tor Lillqvist 2004-03-30 22:44:22 UTC
I think it might even be that with current gcc and/or binutils, the __declspec
(dllexport) declarations for variables aren't necessary for mingw either, and 
just having them in the .def file would be enough. At some point it didn't work 
that way, variables weren't exported if they were only mentioned in the .def 
file.
Comment 5 alexander.winston 2004-04-03 21:36:58 UTC
Adding the PATCH keyword.
Comment 6 Tor Lillqvist 2004-04-04 21:09:21 UTC
Is it only __declspec(dllexport) of variable *definitions* that cause problems 
on Cygwin? I mean, these five variables are also *declared* with __declspec
(dllexport) in various header files.
Comment 7 Roger Leigh 2004-04-06 14:50:15 UTC
Removing the declarations in the headers breaks GModule.  I don't entirely
understand how linking works on Windows, but it appears that the build and tests
are OK with the original patch, but the removing all __declspec declarations
from the headers on Cygwin breaks the GModule checks.

I'm unsure of the effect on GType or GParamSpec, but it seems that whilst
removing all of the __declspec(dllimport) declarations is OK, but
__declspec(dllexport) in gmodule.h is still required (even though dllexport
breaks when used in source files).

I've attached two patches.  The first is not broken, though I'm not sure exactly
how it will impact on modules not built in the GLib tree.  This might possibly
cause breakage, though "make check" shows it works.
The second breaks "make check" module-test.  I'm unsure why, but perhaps the
test modules need .def files if dllexport isn't used? [the other symbols where I
removed dllexport also appear in the def file].

This corresponds with what I've read in the GCC info manual: exports are either
automatic with -export-all or are done with the def file.  glib is doing the
latter, making __declspec(dllimport) unnecessary.  Apparently,
__declspec(dllimport) is also unnecessary since ld will auto-resolve symbols if
passed --enable-auto-import.  I can't see this being used, but I do see
automatic import of some symbols (perhaps GCC passes it automatically?).

Perhaps it's best to leave these patches, since they seem OK without them (the
original patch is still required however).  With a bit of tweaking, I think
these two patches might eventually work too, but it might cause unacceptable
breakage in other packages?

Regards,
Roger

(and to think that once upon a time I thought UNIX shared libraries were
complicated enough ;-)
Comment 8 Roger Leigh 2004-04-06 14:51:29 UTC
Created attachment 26407 [details] [review]
rl-glib-CVSHEAD-cygwin-gmodule2.patch

Works, but could it break other packages?
Comment 9 Roger Leigh 2004-04-06 14:54:58 UTC
Created attachment 26408 [details] [review]
rl-glib-CVSHEAD-cygwin-gmodule-BROKEN.patch

This breaks make check (module-test), but I think this is because the
test modules don't have a .def file.

This is a little worrying though--if a .def file is created, the
existing headers will still add __declspec(dllexport), which will
break any module that /does/ have a .def file (I think).
Comment 10 Tor Lillqvist 2004-04-07 04:19:51 UTC
We must also remember that GLib is intended to be buildable with Microsoft's 
tools. Even more importantly, GLib-using code should be buildable with 
Microsoft's tools. It must be possible to build GLib with MSVC and use the 
resulting DLL from gcc-compiled code and vice versa. The Microsoft linker 
doesn't do auto-imports of variables, so the __declspec(dllimport) declarations 
are definitely needed in the headers. If we can assume an auto-importing GNU 
linker, they could be conditional on _MSC_VER, but as they don't do any harm 
with gcc, why bother.

I think my conclusion so far is that the __declspec(dllexport) declarations for 
the variable definitions in the source files can be removed (as you originally 
suggested, if they cause harm on Cygwin and are otherwise unnecessary), but 
other things are best left as is?
Comment 11 Roger Leigh 2004-04-07 14:44:30 UTC
> I think my conclusion so far is that the __declspec(dllexport) declarations for 
> the variable definitions in the source files can be removed (as you originally 
> suggested, if they cause harm on Cygwin and are otherwise unnecessary), but 
> other things are best left as is?

I think this is the best thing to do.

(Longer-term, since Cygwin doesn't strictly require any __declspec stuff, I'd
like the toolchain to take care of automatic symbol export, too.  If the
defaults were changed, I think this could be done today.  This probably just
requires some libtool tweaks to adjust the gcc and linker flags.  This isn't
urgent though.)
Comment 12 Tor Lillqvist 2004-04-10 01:31:35 UTC
*** Bug 139491 has been marked as a duplicate of this bug. ***
Comment 13 Tor Lillqvist 2004-04-10 01:34:59 UTC
BTW, Hans, can you confirm that the __declspec(dllexport) attributes can be 
removed from the variable definitions in the .c files?
Comment 14 Tor Lillqvist 2004-04-10 02:02:53 UTC
Or actually, I think I did confirm myself that they aren't needed for MSVC 
builds, either. Removed them and committed.
Comment 15 Hans Breuer 2004-04-10 12:07:32 UTC
Confirmed, too. Dia already did it (searched for DIAVAR in all of dia/lib and
found only in header files).