This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Patch; let -subsystem option on pe targets actually affect entry symbol


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 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]