X-Recipient: archive-cygwin AT delorie DOT com X-SWARE-Spam-Status: No, hits=-2.3 required=5.0 tests=AWL,BAYES_00,SPF_PASS X-Spam-Check-By: sourceware.org Message-ID: <499EC6E5.5000408@gmail.com> Date: Fri, 20 Feb 2009 15:06:13 +0000 From: Dave Korn User-Agent: Thunderbird 2.0.0.17 (Windows/20080914) MIME-Version: 1.0 To: Dave Korn CC: cygwin AT cygwin DOT com Subject: Re: [ANNOUNCEMENT] [1.7] Updated: file-5.00-1 References: <499E2B9A DOT 5030907 AT cwilson DOT fastmail DOT fm> <20090220095916 DOT GA759 AT calimero DOT vinschen DOT de> <499EB5A6 DOT 5000707 AT gmail DOT com> <499EBABE DOT 8080303 AT gmail DOT com> In-Reply-To: <499EBABE.8080303@gmail.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: 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 Dave Korn wrote: > Ok, now I'll try debugging it. Ah. Right. Ouch. I see what's going on. Rebasing does not interact well with the presence of unresolved weaks. Gah. The problem arises here, in cygming-crtbegin.c: ---------------------------------------------- extern void __register_frame_info (const void *, struct object *) TARGET_ATTRIBUTE_WEAK; ---------------------------------------------- /* We need to indirect through a variable, as gcc assumes that a function label used as a constant is never zero. */ void (*register_frame_info_ptr) (const void *, struct object *) = __register_frame_info; ---------------------------------------------- < comments, #ifdefs folded > void __gcc_register_frame (void) { void (*register_frame_fn) (const void *, struct object *) = 0; HANDLE h = GetModuleHandle (LIBGCC_SONAME); if (h) register_frame_fn = (void (*) (const void *, struct object *)) GetProcAddress (h, "__register_frame_info"); if (!register_frame_fn) register_frame_fn = register_frame_info_ptr; if (register_frame_fn) register_frame_fn (__EH_FRAME_BEGIN__, &obj); ---------------------------------------------- The purpose of playing these games is in order not to drag in the whole exception handling machinery into a statically-linked application unless we actually need it. We're relying on detecting an unlinked weak symbol by it having a value of zero at runtime. That usually works, but the pointer variable register_frame_info_ptr must have some kind of reloc pointing at it, because rebase adjusts it, so instead of zero it becomes equal to the difference between the new and old base addresses. I'll need to do some thinking about this, as it might be possible to make it work, but in any case, the rule should be that DLLs are *always* linked against shared-libgcc, regardless; even plain old C with no exceptions. It's OK if you're linking an entire app statically to link against static libgcc, but it's definitely bad practice when building a DLL. I should probably warn against this usage in the compiler, if not fail it altogether; not sure yet, because it does basically work, even if the DLL it produces isn't rebaseable, and because it might not be difficult to make rebase skip relocating unresolved weaks, and because I have this long-term scheme to make weaks work properly on win32 like they do on ELF which would avoid the problem altogether. Take-home point: never use -static-libgcc when building a DLL. cheers, DaveK -- 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/