Mail Archives: cygwin-developers/1999/08/15/20:22:51
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 -