From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8568 invoked by alias); 27 Sep 2005 10:59:58 -0000 Mailing-List: contact binutils-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sources.redhat.com Received: (qmail 8550 invoked by uid 22791); 27 Sep 2005 10:59:51 -0000 Received: from web50905.mail.yahoo.com (HELO web50905.mail.yahoo.com) (206.190.38.125) by sourceware.org (qpsmtpd/0.30-dev) with SMTP; Tue, 27 Sep 2005 10:59:51 +0000 Received: (qmail 49954 invoked by uid 60001); 27 Sep 2005 10:59:50 -0000 Message-ID: <20050927105950.49952.qmail@web50905.mail.yahoo.com> Received: from [218.101.109.89] by web50905.mail.yahoo.com via HTTP; Tue, 27 Sep 2005 22:59:50 NZST Date: Tue, 27 Sep 2005 15:04:00 -0000 From: Danny Smith Reply-To: dannysmith@users.sourceforge.net Subject: Patch; let -subsystem option on pe targets actually affect entry symbol To: binutils , Christopher Faylor MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-SW-Source: 2005-09/txt/msg00298.txt.bz2 Hello The ld --subsystem windows switch for pe targets is supposed to: A) change subsystem to GUI subsystem B) set the default entry symbol to _WinMainCRTStartup The code in emultempl/pe.em: set_pe_subsystem indeed does make these two changes. However, the change to the default entry symbol is ineffectual, since it is later overriden by the ENTRY specified in the builtin linker script (1). Why is this important? On mingw, entry through _WinMainCRTStartup causes system errors to be output though a GUI message box. This is useful for debugging purposes. There are other ways to cause this to happen, but other windows compilers do it this way and mingw developer gets bug reports if we don't do it the windows way For example, compiling this with --subsystem windows and running the app #include #include int WINAPI WinMain(HINSTANCE i, HINSTANCE j, LPSTR s, int k) { assert(0); } *should* bring up a GUI dialog which displays the standard assert info and also asks if you want to debug the app. If a JIT debugger is enabled in the registry, it will be invoked to produce a backtrace. The following change fixes this by specifying the default entry symbol only in pe,em and not in the internal linker scripts. However, I believe this may resurrect some old problems on cygwin, which does not provide a WinMainCRTStartup fumction. There used to be instructions in cygwin users guide on how to work-around this (ie, when setting windows subsystem either add an explict -e _mainCRTStartup or add a stub WinMainCRTStartup that just calls the console entry symbol), but those instruction have been removed. (1) FWIW, the failure of set_pe_subsystem() to do anything useful to the entry symbol started here: 2002-05-22 Alan Modra * emultempl/pe.em (set_pe_subsystem): Don't set "cmdline" when calling lang_add_entry. I naively tried to just revert that, but that was a bad idea, since treating it as a cmdline option could cause an explicitly specified entry symbol to be ignored. Here is the proposed patch. Danny Smith * emultempl/pe.em (gld_${EMULATION_NAME}_before_parse): Set default entry symbol to ENTRY here. * scripttempl/pe.sc: Not here. Index: emultempl/pe.em =================================================================== RCS file: /cvs/src/src/ld/emultempl/pe.em,v retrieving revision 1.110 diff -c -3 -p -r1.110 pe.em *** emultempl/pe.em 4 Aug 2005 06:22:13 -0000 1.110 --- emultempl/pe.em 27 Sep 2005 08:46:11 -0000 *************** *** 1,5 **** --- 1,6 ---- # This shell script emits a C file. -*- C -*- # It does some substitutions. + test -z "${ENTRY}" && ENTRY="_mainCRTStartup" if [ -z "$MACHINE" ]; then OUTPUT_ARCH=${ARCH} else *************** gld_${EMULATION_NAME}_before_parse (void *** 143,148 **** --- 144,151 ---- #else lang_default_entry ("_WinMainCRTStartup"); #endif + #else + lang_default_entry ("${ENTRY}"); #endif #endif } Index: scripttempl/pe.sc =================================================================== RCS file: /cvs/src/src/ld/scripttempl/pe.sc,v retrieving revision 1.14 diff -c -3 -p -r1.14 pe.sc *** scripttempl/pe.sc 30 Nov 2004 23:54:53 -0000 1.14 --- scripttempl/pe.sc 27 Sep 2005 08:46:11 -0000 *************** ${OUTPUT_ARCH+OUTPUT_ARCH(${OUTPUT_ARCH} *** 50,57 **** ${LIB_SEARCH_DIRS} - ENTRY(${ENTRY}) - SECTIONS { ${RELOCATING+/* Make the virtual address and file offset synced if the alignment is} --- 50,55 ---- Send instant messages to your online friends http://au.messenger.yahoo.com