]> git.ipfire.org Git - thirdparty/glibc.git/blob - csu/gmon-start.c
Include <entry.h> (_start): Replaced with ENTRY_POINT.
[thirdparty/glibc.git] / csu / gmon-start.c
1 /* Code to enable profiling at program startup.
2 Copyright (C) 1995, 1996, 1997, 2000 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
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 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
19
20 #include <sys/types.h>
21 #include <sys/gmon.h>
22 #include <stdlib.h>
23 #include <unistd.h>
24 #define __ASSEMBLY__
25 #include <entry.h>
26
27 /* Beginning and end of our code segment. We cannot declare them
28 as the external functions since we want the addresses of those
29 labels. Taking the address of a function may have different
30 meanings on different platforms. */
31 extern void ENTRY_POINT, etext;
32
33 #ifndef HAVE_INITFINI
34 /* This function gets called at startup by the normal constructor
35 mechanism. We link this file together with start.o to produce gcrt1.o,
36 so this constructor will be first in the list. */
37
38 extern void __gmon_start__ (void) __attribute__ ((constructor));
39 #else
40 /* In ELF and COFF, we cannot use the normal constructor mechanism to call
41 __gmon_start__ because gcrt1.o appears before crtbegin.o in the link.
42 Instead crti.o calls it specially (see initfini.c). */
43 extern void __gmon_start__ (void);
44 #endif
45
46 void
47 __gmon_start__ (void)
48 {
49 #ifdef HAVE_INITFINI
50 /* Protect from being called more than once. Since crti.o is linked
51 into every shared library, each of their init functions will call us. */
52 static int called;
53
54 if (called)
55 return;
56
57 called = 1;
58 #endif
59
60 /* Start keeping profiling records. */
61 __monstartup ((u_long) &ENTRY_POINT, (u_long) &etext);
62
63 /* Call _mcleanup before exiting; it will write out gmon.out from the
64 collected data. */
65 atexit (&_mcleanup);
66 }