X-Spam-Check-By: sourceware.org Date: Sat, 11 Feb 2006 20:38:26 -0500 (EST) From: Igor Peshansky Reply-To: cygwin AT cygwin DOT com To: skaller cc: cygwin AT cygwin DOT com Subject: Re: help with dynamic linkage? In-Reply-To: <1139640407.8498.67.camel@rosella> Message-ID: References: <1139634710 DOT 8498 DOT 16 DOT camel AT rosella> <1139640407 DOT 8498 DOT 67 DOT camel AT rosella> MIME-Version: 1.0 Content-Type: MULTIPART/Mixed; BOUNDARY="=-7PjuT68WsAU/CJ5SvxEP" Content-ID: Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com --=-7PjuT68WsAU/CJ5SvxEP Content-Type: TEXT/PLAIN; CHARSET=US-ASCII Content-ID: On Sat, 11 Feb 2006, skaller wrote: > On Sat, 2006-02-11 at 00:59 -0500, Igor Peshansky wrote: > > On Sat, 11 Feb 2006, skaller wrote: > > > > > hi, I'm having some problem getting dynamic linkage to work. > > > The linkage model is like this: > > > > > > mainline <----- load time ---- librtl.dll > > > ^ / > > > \ / > > > dlopen / > > > \ / > > > user.dll <----------------- > > > > > > gdb indicates the code is crashing in dlopen. LoadLibrary > > > doesn't appear to work either :) > > > In fact, a small example program, buildable with a makefile into two > > DLLs and a main application, would be even more helpful. > > I have tried that .. it works :) Basically the original instructions > on the website say to use -Wl,-auto-import ... blah blah in the advanced > explanations suff. But the simplified example doesn't use that. > Neither do I. I did try building an export/import lib. That does seem > to change the time and way the system crashes. > > The crash occurs when an attempt is made to load the user.dll, > even when the filename given is rubbish .. so the problem isn't > related to that dll. The program WORKS when no filename is > given, in which case it just prints the usual 'usage' information. > > In the case of a garbage filename, the rtl should be throwing > a C++ exception. Perhaps that's causing the problem. However > in the case of a valid filename it should work .. but I get > the same result. > > Unfortunately the only easy way to reproduce the problem is to > download and install Felix: > > http://felix.sf.net/flx_1.1.2_rc1.tgz Well, you could have done *some* work on cutting the testcase down, especially since you know the code better than I do. But, since I'm the Cygwin O'Caml maintainer, I was curious, so I downloaded it (turns out the problem has nothing to do with O'Caml). Starting with the make log and the generated C++ version of the code, I ended up with the attached files. FWIW, it seems to be crashing in the flx_dynlink_t destructor (not in dlopen) -- in fact, even before I cut it down to the attached, commenting out any mention of dlopen still caused the crash. Stepping through the code in gdb quickly gets you to the place where it crashes. > which requires Python and Ocaml. After that ./configure, make > should work. Then make test. BTW: if any Cygwin expert would > like to join the project that would be great! > > > Then wouldn't you be able to reproduce it with only one DLL and one > > main application? Can we see a small complete example that shows the > > problem? > > As above .. small C example, as given on the Cygwin website, works > just fine. > > The problem could be related to C++ RTTI, since I know > ELF/gcc 4.0 doesn't work correctly it would be unfair to expect > gcc 3.4 on Cygwin to do all that nasty emulation and work. > > (The problem here is related to duplicate typeinfo records, > which cannot be avoided in general with dynamic linkage. > Some care is needed in the code to ensure the RTTI is only > instantiated once, and properly imported from that one > location, because gcc's method of catching exceptions > is broken) > > However no exception should be thrown when loading one > of the proper dlls with dlopen(), so there could be > two distinct faults. > > It's also possible -O3 -fomit-frame-pointer is the problem: > gcc's -O3 is known to not work reliably. (however if I recall > I got rid of both, and it made no difference). > > > > Info: resolving vtable for XXXby linking to __imp__XXX (auto-import) > > > > > > occur when linking the executable. > > > > Those are informational. You can either ignore them, or give the > > "-Wl,--enable-auto-import" flag to the linker to quiet them. > > I admit being confused what that does. According to my understanding > of it, this auto-import thing should only apply to variables. > vtables and code are read only, they should be in the code (text) > segment shouldn't they? I'm not sure. Technically, vtables are data (though they contain pointers to the code). But I'm not a C++ internals expert, and this is not a C++ internals list... :-) Besides, that's irrelevant to your crash. > > > Cygwin: latest setup provides. > > > > Umm, setup can provide quite a few versions ranging from ancient to > > latest, depending on your mirror. Why not follow the guidelines at > > and attach (as an uncompressed text > > attachment) the output of "cygcheck -svr"? > > Done, for the XP64 machine. The other I can't get atm, since > its dual booted with Linux which is running my mail client :) > > > > Any hints what is causing the problem or how to fix it? > > > > Not until we have enough information to allow us to reproduce the > > problem. > > I need some hint of what it could be to try to reduce > the 100KLoc to a manageable size :) It has to be something As I said above, this has nothing to do with dynamic linkage. And cutting this down was relatively easy (if tedious) -- just start with main(), keep removing functionality until it doesn't crash anymore, then put the last removed piece back in and start removing finer-grained functionality. > related to different ways Linux and Cygwin handle dynamic linkage, > interacting with some other feature -- such as threads, exception > handling, linkage technique/dll startup code, etc etc. > > One difference: on Linux I have to use -lpthread, on Cygwin > that seems unnecessary. I did try rebuilding with it. The pthreads functionality is built into cygwin1.dll. > > FWIW, I was unable to reproduce this with a trivial instance of your > > scheme above and default linker options. > > Neither was I. > > > One quick question: how are you > > invoking functions from user.dll, are you getting the right function > > pointer, and are you taking care of C++ name mangling when loading symbols > > from the DLL? > > I think so: it works on Linux, OSX, -mno-cygwin, MSVC++ etc. > All the dlsym() symbols are extern "C". > > However, the rtl is not dlopen()ed. This looks to me like another instance of (follow that thread through -- it has a reference to another thread, too). HTH, Igor -- http://cs.nyu.edu/~pechtcha/ |\ _,,,---,,_ pechtcha AT cs DOT nyu DOT edu | igor AT watson DOT ibm DOT com ZZZzz /,`.-'`' -. ;-;;,_ Igor Peshansky, Ph.D. (name changed!) |,4- ) )-,_. ,\ ( `'-' old name: Igor Pechtchanski '---''(_/--' `-'\_) fL a.k.a JaguaR-R-R-r-r-r-.-.-. Meow! "Las! je suis sot... -Mais non, tu ne l'es pas, puisque tu t'en rends compte." "But no -- you are no fool; you call yourself a fool, there's proof enough in that!" -- Rostand, "Cyrano de Bergerac" --=-7PjuT68WsAU/CJ5SvxEP Content-Type: TEXT/PLAIN; charset=US-ASCII; name=Makefile Content-Transfer-Encoding: BASE64 Content-ID: Content-Description: Content-Disposition: attachment; filename=Makefile Q1hYRkxBR1M9LWcgLVdhbGwgLVduby1pbnZhbGlkLW9mZnNldG9mIC1PMyAt Zm9taXQtZnJhbWUtcG9pbnRlciAtLWlubGluZSAtRE5ERUJVRyAtREZMWF9C VUlMRF9EWU5BTUlDX1JUTA0KTERGTEFHUz0tV2wsLS1lbmFibGUtYXV0by1p bXBvcnQgLUwuDQpMRExJQlM9LWxmbHhfZHluYW1pYw0KDQouREVGQVVMVDog YWxsDQoJDQphbGw6IGZseF9ydW4gbGliZmx4X2R5bmFtaWMuZGxsDQoNCkZM WF9SVU5fT0JKUz1cDQoJZmx4X3J1bl9keW5hbWljLm8NCg0KRkxYX0RZTkFN SUNfT0JKUz1cDQoJZmx4X2R5bmxpbmtfZHluYW1pYy5vDQoNCmZseF9ydW46 ICQoRkxYX1JVTl9PQkpTKSBsaWJmbHhfZHluYW1pYy5kbGwNCgkkKExJTksu Y2MpICQoRkxYX1JVTl9PQkpTKSAkKExETElCUykgLW8gJEANCg0KbGliZmx4 X2R5bmFtaWMuZGxsOiAkKEZMWF9EWU5BTUlDX09CSlMpDQoJJChMSU5LLmNj KSAtc2hhcmVkIC1vICRAIC1XbCwtLW91dC1pbXBsaWI9JEAuYSAkXg0KDQou UEhPTlk6IGNsZWFuDQouU1VGRklYRVM6IF9keW5hbWljLm8gLmN4eA0KDQol X2R5bmFtaWMubzogJS5jeHgNCgkkKENPTVBJTEUuY2MpICQ8IC1vICRADQoN CiVfZHluYW1pYy5vOiAlLmNwcA0KCSQoQ09NUElMRS5jYykgJDwgLW8gJEAN Cg0KY2xlYW46DQoJLXJtICQoRkxYX1JVTl9PQkpTKSAkKEZMWF9EWU5BTUlD X09CSlMpDQoNCg== --=-7PjuT68WsAU/CJ5SvxEP Content-Type: TEXT/PLAIN; charset=US-ASCII; name=flx_run.cxx Content-Transfer-Encoding: BASE64 Content-ID: Content-Description: Content-Disposition: attachment; filename=flx_run.cxx Ly8jbGluZSAxMzU0ICJscHNyYy9mbHhfcnRsLmlwayINCiNpbmNsdWRlIDxj c3RkbGliPg0KI2luY2x1ZGUgPHN0ZGlvLmg+DQojaW5jbHVkZSA8dmVjdG9y Pg0KI2luY2x1ZGUgPGxpc3Q+DQojaW5jbHVkZSA8bWFwPg0KI2luY2x1ZGUg PGNzdHJpbmc+DQojaW5jbHVkZSA8Y2Fzc2VydD4NCg0KI2luY2x1ZGUgPHN0 cmluZz4NCi8vI2luY2x1ZGUgPHVuaXN0ZC5oPg0KLy8jaW5jbHVkZSAiZmx4 X3J0bC5ocHAiDQoNCiNpbmNsdWRlICJmbHhfZHlubGluay5ocHAiDQp1c2lu ZyBuYW1lc3BhY2Ugc3RkOw0KdXNpbmcgbmFtZXNwYWNlIGZseDo6cnRsOw0K DQppbnQgbWFpbihpbnQgYXJnYywgY2hhcioqIGFyZ3YpDQp7DQogIGlmIChh cmdjPDIpDQogIHsNCiAgICBwcmludGYoInVzYWdlOiBmbHhfcnVuIFstLWRl YnVnXSBkbGxfZmlsZW5hbWUgb3B0aW9ucyAuLlxuIik7DQogICAgcmV0dXJu IDE7DQogIH0NCiAgZmx4X2R5bmxpbmtfdCBsaWJyYXJ5Ow0KICByZXR1cm4g MDsNCn0NCg0K --=-7PjuT68WsAU/CJ5SvxEP Content-Type: TEXT/PLAIN; charset=US-ASCII; name=flx_dynlink.cpp Content-Transfer-Encoding: BASE64 Content-ID: Content-Description: Content-Disposition: attachment; filename=flx_dynlink.cpp Ly8jbGluZSAxMTY3ICJscHNyYy9mbHhfcnRsLmlwayINCiNpbmNsdWRlICJm bHhfZHlubGluay5ocHAiDQoNCm5hbWVzcGFjZSBmbHggeyBuYW1lc3BhY2Ug cnRsIHsNCg0KZmx4X2R5bmxpbmtfdDo6fmZseF9keW5saW5rX3QoKXt9DQoN Cn19IC8vIG5hbWVzcGFjZXMNCg0KDQo= --=-7PjuT68WsAU/CJ5SvxEP Content-Type: TEXT/PLAIN; charset=US-ASCII; name=flx_dynlink.hpp Content-Transfer-Encoding: BASE64 Content-ID: Content-Description: Content-Disposition: attachment; filename=flx_dynlink.hpp Ly8jbGluZSA5OTAgImxwc3JjL2ZseF9ydGwuaXBrIg0KI2lmbmRlZiBGTFhf RFlOTElOSw0KI2RlZmluZSBGTFhfRFlOTElOSw0KI2RlZmluZSBGTFhfUlRM X0VYVEVSTiBfX2RlY2xzcGVjKGRsbGV4cG9ydCkNCiNpbmNsdWRlIDxzdHJp bmc+DQp1c2luZyBuYW1lc3BhY2Ugc3RkOw0KDQpuYW1lc3BhY2UgZmx4IHsg bmFtZXNwYWNlIHJ0bCB7DQoNCnN0cnVjdCBGTFhfUlRMX0VYVEVSTiBmbHhf ZHlubGlua190Ow0KDQovLy8gZHluYW1pYyBvYmplY3QgbG9hZGVyLg0KDQpz dHJ1Y3QgRkxYX1JUTF9FWFRFUk4gZmx4X2R5bmxpbmtfdA0Kew0KcHVibGlj Og0KICAvLyBkYXRhDQogIHN0cmluZyBmaWxlbmFtZTsNCg0KICB2aXJ0dWFs IH5mbHhfZHlubGlua190KCk7DQp9Ow0KDQp9fSAvLyBuYW1lc3BhY2VzDQoj ZW5kaWYNCg0K --=-7PjuT68WsAU/CJ5SvxEP Content-Type: text/plain; charset=us-ascii -- 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/ --=-7PjuT68WsAU/CJ5SvxEP--