delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin-developers/1999/08/15/20:22:51

Mailing-List: contact cygwin-developers-help AT sourceware DOT cygnus DOT com; run by ezmlm
List-Unsubscribe: <mailto:cygwin-developers-unsubscribe-archive-cygwin-developers=delorie DOT com AT sourceware DOT cygnus DOT com>
List-Archive: <http://sourceware.cygnus.com/ml/cygwin-developers/>
List-Post: <mailto:cygwin-developers AT sourceware DOT cygnus DOT com>
List-Help: <mailto:cygwin-developers-help AT sourceware DOT cygnus DOT com>,
<http://sourceware.cygnus.com/ml/#faqs>
Sender: cygwin-developers-owner AT sourceware DOT cygnus DOT com
Delivered-To: mailing list cygwin-developers AT sourceware DOT cygnus DOT com
Message-Id: <199908160022.TAA08576@mercury.xraylith.wisc.edu>
To: cygwin-developers AT sourceware DOT cygnus DOT com
Subject: (patch) Profiling/gcrt0 fix
Date: Sun, 15 Aug 1999 19:22:20 -0500
From: Mumit Khan <khan AT xraylith DOT wisc DOT EDU>

As some of you already know, Cygwin profiling is somewhat limited at
present -- you can profile when you have a function named main and 
compile that with -pg as well. This precludes profiling g77 code, and
anything built with -mwindows where you only define WinMain. Also,
can't profile C++ (or GNU C specific) global constructors.

The following change preserves backward compatibility and allows all
of the above by:

1. turning _monstartup into a constructor function, so that GCC doesn't
   need to see main.

2. preventing multiple invocations so that DLLs linked to gcrt0.o will
   keep on working. This also provides backward compatibility for those
   using older versions of gcc (eg., gcc-2.95 and older).

I'll submit the gcc-specific changes later, but this gcrt0 will work
with or without that.

One change you'll notice is that I've changed the assembler name of
eprol to __eprol to avoid namespace pollution. To be correct, this 
should be the entry point, mainCRTStartup. However, if I used that
instead of eprol, profiling won't work for if -mwindows is specified
since Cygwin *still* doesn't have a WinMainCRTStartup. It's ok for
all practical purposes, so let's leave this alone for now.

Sun Aug 15 19:11:49 1999  Mumit Khan  <khan AT xraylith DOT wisc DOT edu>

	* gcrt0.c (__eprol): Avoid namespace pollution. 
	(_monstartup): Turn into a constructor function and prevent multiple 
	invocations.

Index: gcrt0.c
===================================================================
RCS file: /homes/khan/src/CVSROOT/cygwin-dev/winsup/gcrt0.c,v
retrieving revision 1.1.1.1
diff -u -3 -p -r1.1.1.1 gcrt0.c
--- gcrt0.c	1999/07/15 21:02:34	1.1.1.1
+++ gcrt0.c	1999/08/16 00:09:05
@@ -11,20 +11,31 @@ details. */
 #include <sys/types.h>
 #include <stdlib.h>
 
-extern u_char etext asm("etext");
-extern u_char eprol asm("eprol");
-extern void _mcleanup();
+extern u_char etext asm ("etext");
+extern u_char eprol asm ("__eprol");
+extern void _mcleanup (void);
 extern void monstartup (u_long, u_long);
 
+void _monstartup (void) __attribute__((__constructor__));
+
 /* startup initialization for -pg support */
+
 void
-_monstartup()
+_monstartup (void) 
 {
-    atexit(_mcleanup);
-    monstartup((u_long)&eprol, (u_long)&etext);
+  static int called;
+
+  /* Guard against multiple calls that may happen if DLLs are linked
+     with profile option set as well. Addede side benefit is that it
+     makes profiling backward compatible (GCC used to emit a call to 
+     _monstartup when compiling main with profiling enabled).  */
+  if (called++)
     return;
+
+  monstartup ((u_long) &eprol, (u_long) &etext);
+  atexit (&_mcleanup);
 }
 
-asm(".text");
-asm("eprol:");
+asm (".text");
+asm ("__eprol:");
 
Regards,
Mumit

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019