This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: abort during exit() with a dynamically loaded C++ library


On 17/06/2014 19:11, Jon TURNEY wrote:
I think I have found a problem when building programs using the latest
mesa library, where abort is being called during exit()

This seems to be x86 specific, and looks like it is somehow related to
having a C++ library dynamically loaded by a C program.

I think I have reduced it to the following test case:

So, this seems to be related to this patch [1], to fix a different abort during __gcc_deregister_frame()

[1] https://sourceware.org/ml/cygwin/2013-07/msg00528.html

Since this code is baked into libgcc itself, that patch has the side-effect of making libgcc pin itself in memory.

I can't really tell from what's written there if that was deliberate or not, but it seems that it introduces a different problem when the executable doesn't have a dependency on libgcc.

test.c:

#include <assert.h>
#include <dlfcn.h>

int main()
{
    void *h = dlopen("dllib.dll", 0);
    assert(h);
    dlclose(h);

The problem can be worked around by adding code to force libgcc to get unloaded here, which seems to support this theory, e.g.

+#define LIBGCC_SONAME "cyggcc_s-1.dll"
+   HANDLE hmod_libgcc = GetModuleHandle(LIBGCC_SONAME);
+   FreeLibrary(hmod_libgcc);

}

Attached is a patch which modifies __gcc_register_frame() to avoid it pinning itself in memory.

Alternatively, as one of the emails in the linked thread says [2], the assert in __deregister_frame_info_bases() itself could be removed.

[2] http://www.mail-archive.com/gcc@gcc.gnu.org/msg68286.html

Attachment: cygming-crtbegin.c.patch
Description: Text document

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]