public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* Patch; let -subsystem option on pe targets actually affect entry symbol
@ 2005-09-27 15:04 Danny Smith
  2005-09-28 12:32 ` Alan Modra
  2005-09-28 14:39 ` Christopher Faylor
  0 siblings, 2 replies; 6+ messages in thread
From: Danny Smith @ 2005-09-27 15:04 UTC (permalink / raw)
  To: binutils, Christopher Faylor

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 <windows.h>
#include <assert.h>

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  <amodra@bigpond.net.au>
        * 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  <dannysmith@users.sourceforge.met>

        * 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 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Patch; let -subsystem option on pe targets actually affect entry symbol
  2005-09-27 15:04 Patch; let -subsystem option on pe targets actually affect entry symbol Danny Smith
@ 2005-09-28 12:32 ` Alan Modra
  2005-09-28 14:39 ` Christopher Faylor
  1 sibling, 0 replies; 6+ messages in thread
From: Alan Modra @ 2005-09-28 12:32 UTC (permalink / raw)
  To: dannysmith; +Cc: binutils, Christopher Faylor

On Tue, Sep 27, 2005 at 10:59:50PM +1200, Danny Smith wrote:
>         * emultempl/pe.em (gld_${EMULATION_NAME}_before_parse):
> 	Set default entry symbol to ENTRY here.
> 	* scripttempl/pe.sc: Not here.

Looks reasonable to me.

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Patch; let -subsystem option on pe targets actually affect entry symbol
  2005-09-27 15:04 Patch; let -subsystem option on pe targets actually affect entry symbol Danny Smith
  2005-09-28 12:32 ` Alan Modra
@ 2005-09-28 14:39 ` Christopher Faylor
  2005-09-28 22:03   ` Danny Smith
  2005-10-04  7:33   ` Danny Smith
  1 sibling, 2 replies; 6+ messages in thread
From: Christopher Faylor @ 2005-09-28 14:39 UTC (permalink / raw)
  To: dannysmith, binutils

On Tue, Sep 27, 2005 at 10:59:50PM +1200, Danny Smith wrote:
>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. 

It sounds like, for cygwin, the simple solution for this, is to just include
a WinMainCRTStartup function which calls _manCRTStartup, right?

cgf

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Patch; let -subsystem option on pe targets actually affect entry symbol
  2005-09-28 14:39 ` Christopher Faylor
@ 2005-09-28 22:03   ` Danny Smith
  2005-10-04  7:33   ` Danny Smith
  1 sibling, 0 replies; 6+ messages in thread
From: Danny Smith @ 2005-09-28 22:03 UTC (permalink / raw)
  To: Christopher Faylor, binutils


----- Original Message -----
From: "Christopher Faylor
>
> It sounds like, for cygwin, the simple solution for this, is to just include
> a WinMainCRTStartup function which calls _manCRTStartup, right?


Yes.
Danny

> cgf


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Patch; let -subsystem option on pe targets actually affect entry symbol
  2005-09-28 14:39 ` Christopher Faylor
  2005-09-28 22:03   ` Danny Smith
@ 2005-10-04  7:33   ` Danny Smith
  2005-10-04 13:54     ` Christopher Faylor
  1 sibling, 1 reply; 6+ messages in thread
From: Danny Smith @ 2005-10-04  7:33 UTC (permalink / raw)
  To: Christopher Faylor, binutils


----- Original Message -----
From: "Christopher Faylor"
Sent: Thursday, 29 September 2005 02:27


> On Tue, Sep 27, 2005 at 10:59:50PM +1200, Danny Smith wrote:
> >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.
>
> It sounds like, for cygwin, the simple solution for this, is to just include
> a WinMainCRTStartup function which calls _manCRTStartup, right?
>
> cgf

Corrina's winsup commit to add a  WinMainCRTStartup alias to cygwin's crt0.c
gets rid of the cygwin
 --subsystem windows warnings.

Is the patch now okay to commit?

        * emultempl/pe.em (gld_${EMULATION_NAME}_before_parse): Set
        default entry symbol to ENTRY here.
        * scripttempl/pe.sc: Not here.



Danny


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Patch; let -subsystem option on pe targets actually affect entry symbol
  2005-10-04  7:33   ` Danny Smith
@ 2005-10-04 13:54     ` Christopher Faylor
  0 siblings, 0 replies; 6+ messages in thread
From: Christopher Faylor @ 2005-10-04 13:54 UTC (permalink / raw)
  To: binutils

On Tue, Oct 04, 2005 at 08:30:04PM +1300, Danny Smith wrote:
>----- Original Message -----
>From: "Christopher Faylor"
>Sent: Thursday, 29 September 2005 02:27
>
>
>> On Tue, Sep 27, 2005 at 10:59:50PM +1200, Danny Smith wrote:
>> >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.
>>
>> It sounds like, for cygwin, the simple solution for this, is to just include
>> a WinMainCRTStartup function which calls _manCRTStartup, right?
>
>Corrina's winsup commit to add a  WinMainCRTStartup alias to cygwin's crt0.c
>gets rid of the cygwin
> --subsystem windows warnings.
>
>Is the patch now okay to commit?
>
>        * emultempl/pe.em (gld_${EMULATION_NAME}_before_parse): Set
>        default entry symbol to ENTRY here.
>        * scripttempl/pe.sc: Not here.

Yes.

cgf

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2005-10-04 13:54 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-09-27 15:04 Patch; let -subsystem option on pe targets actually affect entry symbol Danny Smith
2005-09-28 12:32 ` Alan Modra
2005-09-28 14:39 ` Christopher Faylor
2005-09-28 22:03   ` Danny Smith
2005-10-04  7:33   ` Danny Smith
2005-10-04 13:54     ` Christopher Faylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).