diff mbox

[libgcc] : Solve issue about too early released libgcc's DLL

Message ID 263673100.28332779.1383903400071.JavaMail.root@redhat.com
State New
Headers show

Commit Message

Kai Tietz Nov. 8, 2013, 9:36 a.m. UTC
Hello,

this issue was discussed on cygwin's ML some time ago.  For shared libgcc-DLL use it might happen that the DLL is released too early, so we need to perform an explicit load of it for increasing the load-count.  By this we make sure that the DLL is still loaded on destruction.

I will apply this patch soon, if there are no objections.  Corinna, please retest that this patch fixes the reported issue.

Regards,
Kai

2013-11-08  Kai Tietz  <ktietz@redhat.com>

	* config/i386/cygming-crtbegin.c (__gcc_register_frame):
	Increment load-count on use of LIBGCC_SONAME DLL.
	(hmod_libgcc): New static variable to hold handle of
	LIBGCC_SONAME DLL.
	(__gcc_deregister_frame): Decrement load-count of
	LIBGCC_SONAME DLL.

Comments

Corinna Vinschen Nov. 8, 2013, 12:35 p.m. UTC | #1
Hi,

On Nov  8 04:36, Kai Tietz wrote:
> Hello,
> 
> this issue was discussed on cygwin's ML some time ago.  For shared
> libgcc-DLL use it might happen that the DLL is released too early, so
> we need to perform an explicit load of it for increasing the
> load-count.  By this we make sure that the DLL is still loaded on
> destruction.
> 
> I will apply this patch soon, if there are no objections.  Corinna,
> please retest that this patch fixes the reported issue.

I'm not set up for testing this, but the patch looks basically the same
as the original, which has been reported to fix the problem:

  http://cygwin.com/ml/cygwin/2013-11/msg00158.html


Thanks,
Corinna
diff mbox

Patch

Index: config/i386/cygming-crtbegin.c
===================================================================
--- config/i386/cygming-crtbegin.c	(revision 204561)
+++ config/i386/cygming-crtbegin.c	(working copy)
@@ -91,6 +91,9 @@  static EH_FRAME_SECTION_CONST char __EH_FRAME_BEGI
   = { };
 
 static struct object obj;
+
+/* Handle of libgcc's DLL reference.  */
+HANDLE hmod_libgcc;
 #endif
 
 #if TARGET_USE_JCR_SECTION
@@ -115,9 +118,14 @@  __gcc_register_frame (void)
 
   void (*register_frame_fn) (const void *, struct object *);
   HANDLE h = GetModuleHandle (LIBGCC_SONAME);
+
   if (h)
-    register_frame_fn = (void (*) (const void *, struct object *))
-			GetProcAddress (h, "__register_frame_info");
+    {
+      /* Increasing the load-count of LIBGCC_SONAME DLL.  */
+      hmod_libgcc = LoadLibrary (LIBGCC_SONAME);
+      register_frame_fn = (void (*) (const void *, struct object *))
+			  GetProcAddress (h, "__register_frame_info");
+    }
   else 
     register_frame_fn = __register_frame_info;
   if (register_frame_fn)
@@ -154,5 +162,7 @@  __gcc_deregister_frame (void)
     deregister_frame_fn = __deregister_frame_info;
   if (deregister_frame_fn)
      deregister_frame_fn (__EH_FRAME_BEGIN__);
+  if (hmod_libgcc)
+    FreeLibrary (hmod_libgcc);
 #endif
 }