delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2006/03/21/21:36:08

X-Spam-Check-By: sourceware.org
Date: Wed, 22 Mar 2006 03:35:50 +0100
Message-Id: <455506406@web.de>
MIME-Version: 1.0
From: Bernhard Loos <bernloos AT web DOT de>
To: cygwin AT cygwin DOT com
Subject: Re: dlopen() bug
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
X-MIME-Autoconverted: from quoted-printable to 8bit by delorie.com id k2M2a2aS015251

> -----Ursprüngliche Nachricht-----
> Von: skaller <skaller <at> users <dot> sourceforge <dot> net>
> Gesendet: 21.03.06 20:31:08

> On Tue, 2006-03-21 at 19:52 +0100, Bernhard Loos wrote:
> > Hello
> > 
> > Is there any progress in solving the problem mentioned in this thread:
> > http://cygwin.com/ml/cygwin/2006-03/msg00274.html ?
> 
> The example in that page is bugged and there is no
> reason at all to expect it to work.
> 
> The mainline ct.c is a C program, it's compiled
> as a C program, and so cannot interact with C++
> libraries.
 
If the C++library declares its calls as 'extern "C"' (as it is done in the example),
AFAIK there shouldn't be any problem.
 
> The mainline of any body of code using C++ MUST be
> compiled as C++. Furthermore you must NOT explicitly
> link libstdc++, that is the job of the compiler.

Yes, but removing the -lstdc++ doesn't make any difference in this example.

> The fact that the example works when libstdc++ is linked
> with the mainline simply suggests an implementation artefact
> that some startup code is stored in the library and the linker
> manages to execute it.
 
It isn't linked against libstdc++. (At least, I don't see, why ist should be.)

> There's no assurance this is actually initialising everything
> correctly. Some initialisation may need to be done 'on the
> bottom of the stack' and/or before other code, and it is too 
> late when a dll is called half way through the program.
> 
> -- 
> John Skaller <skaller at users dot sf dot net>
> Felix, successor to C++: http://felix.sf.net


Anyway all this things aren't really related to the crash.

I removed as much things as possible from the testcase and corrected
the things mentioned above. But I wasn't able to find a solution or even an explaination.

This is a part of the log from depency walker:
00:00:00.438: LoadLibraryA("H:\cygwin\test\CrashTest\CrashTest.dll") called from "CYGWIN1.DLL" at address 0x6100FCB2 by thread 1.
00:00:00.500: Loaded "CRASHTEST.DLL" at address 0x00B40000 by thread 1.  Successfully hooked module.
00:00:00.500: DllMain(0x00B40000, DLL_PROCESS_ATTACH, 0x00000000) in "CRASHTEST.DLL" called by thread 1.
00:00:00.500: First chance exception 0xC0000005 (Access Violation) occurred in "CYGWIN1.DLL" at address 0x610AE938 by thread 1.
00:00:00.500: Unloaded "CRASHTEST.DLL" at address 0x00B40000 by thread 1.
00:00:00.516: LoadLibraryA("H:\cygwin\test\CrashTest\CrashTest.dll") returned NULL by thread 1. Error: Unzulssiger Zugriff auf einen Speicherbereich (998).
00:00:00.578: First chance exception 0xC0000005 (Access Violation) occurred at address 0x00B4F37E by thread 1.
00:00:00.578: First chance exception 0xC0000005 (Access Violation) occurred in "CYGWIN1.DLL" at address 0x6108DFFC by thread 1.
00:00:00.578: First chance exception 0xC0000005 (Access Violation) occurred in "CYGWIN1.DLL" at address 0x6108DFFC by thread 1.
00:00:00.578: First chance exception 0xC0000005 (Access Violation) occurred in "CYGWIN1.DLL" at address 0x6108DFFC by thread 1.

The DllMain fails for some reason.
The program crashs with a stack-overflow after a few hundred lines of like the last three.

With 1.5.18, everything works as aspected.

file ct.cc:
-------------------------------------------------------------------------------
#include <stdio.h>
#include <dlfcn.h>


extern "C"
void test();

int main(int argc, char** argv)
{
	char* pszdll="./CrashTest.dll";

	printf("\n\ndlopening %s\n", pszdll);

	void* hDLL = dlopen(pszdll, 0);

	if(hDLL)
	{
    	printf("OK\n");
	}
	else
		printf("Error dlopening %s\n", pszdll);

	return 0;
}

#ifdef HARDLINKTEST
void TestLinked(char* pszdll)
{
	test();
}
#endif
------------------------------------------------------------------

crashtest.cc:
------------------------------------------------------------------
#include <iostream>

extern "C" __declspec(dllexport)
void test()
{
	return;
}
-----------------------------------------------------------------

compile with:
g++ -W -Wall -g -DMAKEDLL -DDEBUG CrashTest.cc -shared -o CrashTest.dll

g++ -g -W -Wall -DUSEDLL -DDEBUG ct.cc -o ctCRASH.exe
g++ -W -Wall -DHARDLINKTEST -DUSEDLL -DDEBUG ct.cc -o ctOK.exe -L./  -lCrashTest


              Bernhard Loos
______________________________________________________________________
XXL-Speicher, PC-Virenschutz, Spartarife & mehr: Nur im WEB.DE Club!		
Jetzt gratis testen! http://freemail.web.de/home/landingpad/?mc=021130


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


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019