]> git.ipfire.org Git - thirdparty/glibc.git/blob - csu/gmon-start.c
Update copyright notices with scripts/update-copyrights.
[thirdparty/glibc.git] / csu / gmon-start.c
1 /* Code to enable profiling at program startup.
2 Copyright (C) 1995-2013 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, see
17 <http://www.gnu.org/licenses/>. */
18
19 #include <sys/types.h>
20 #include <sys/gmon.h>
21 #include <stdlib.h>
22 #include <unistd.h>
23 #define __ASSEMBLY__
24 #include <entry.h>
25
26 /* Beginning and end of our code segment. We cannot declare them
27 as the external functions since we want the addresses of those
28 labels. Taking the address of a function may have different
29 meanings on different platforms. */
30 #ifdef ENTRY_POINT_DECL
31 ENTRY_POINT_DECL(extern)
32 #else
33 extern char ENTRY_POINT[];
34 #endif
35 extern char etext[];
36
37 #ifndef TEXT_START
38 # ifdef ENTRY_POINT_DECL
39 # define TEXT_START ENTRY_POINT
40 # else
41 # define TEXT_START &ENTRY_POINT
42 # endif
43 #endif
44
45 /* We cannot use the normal constructor mechanism to call
46 __gmon_start__ because gcrt1.o appears before crtbegin.o in the link.
47 Instead crti.o calls it specially. */
48 extern void __gmon_start__ (void);
49
50 void
51 __gmon_start__ (void)
52 {
53 /* Protect from being called more than once. Since crti.o is linked
54 into every shared library, each of their init functions will call us. */
55 static int called;
56
57 if (called)
58 return;
59
60 called = 1;
61
62 /* Start keeping profiling records. */
63 __monstartup ((u_long) TEXT_START, (u_long) &etext);
64
65 /* Call _mcleanup before exiting; it will write out gmon.out from the
66 collected data. */
67 atexit (&_mcleanup);
68 }