* sysdeps/m68k/dl-machine.h (_dl_start_user): Pass correct
[glibc.git] / csu / gmon-start.c
blob25f5561128bfd1b5d0ae17c652ee38a4c13c641c
1 /* Code to enable profiling at program startup.
2 Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
20 #include <sys/types.h>
21 #include <sys/gmon.h>
22 #include <stdlib.h>
23 #include <unistd.h>
25 /* Beginning and end of our code segment. We cannot declare them
26 as the external functions since we want the addresses of those
27 labels. Taking the address of a function may have different
28 meanings on different platforms. */
29 extern void _start, etext;
31 #ifndef HAVE_INITFINI
32 /* This function gets called at startup by the normal constructor
33 mechanism. We link this file together with start.o to produce gcrt1.o,
34 so this constructor will be first in the list. */
36 void __gmon_start__ (void) __attribute__ ((constructor));
37 #else
38 /* In ELF and COFF, we cannot use the normal constructor mechanism to call
39 __gmon_start__ because gcrt1.o appears before crtbegin.o in the link.
40 Instead crti.o calls it specially (see initfini.c). */
41 #endif
43 void
44 __gmon_start__ (void)
46 #ifdef HAVE_INITFINI
47 /* Protect from being called more than once. Since crti.o is linked
48 into every shared library, each of their init functions will call us. */
49 static int called;
51 if (called++)
52 return;
53 #endif
55 /* Start keeping profiling records. */
56 __monstartup ((u_long) &_start, (u_long) &etext);
58 /* Call _mcleanup before exiting; it will write out gmon.out from the
59 collected data. */
60 atexit (&_mcleanup);