]>
Commit | Line | Data |
---|---|---|
11c981a9 | 1 | /* Code to enable profiling at program startup. |
a04586d8 | 2 | Copyright (C) 1995,1996,1997,2000,2001,2002 Free Software Foundation, Inc. |
6d52618b | 3 | This file is part of the GNU C Library. |
11c981a9 | 4 | |
6d52618b | 5 | The GNU C Library is free software; you can redistribute it and/or |
41bdb6e2 AJ |
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. | |
11c981a9 | 9 | |
6d52618b UD |
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 | |
41bdb6e2 | 13 | Lesser General Public License for more details. |
11c981a9 | 14 | |
41bdb6e2 AJ |
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. */ | |
11c981a9 RM |
19 | |
20 | #include <sys/types.h> | |
21 | #include <sys/gmon.h> | |
22 | #include <stdlib.h> | |
23 | #include <unistd.h> | |
6ef77f19 UD |
24 | #define __ASSEMBLY__ |
25 | #include <entry.h> | |
11c981a9 | 26 | |
dfcaa642 UD |
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. */ | |
ca13ce66 UD |
31 | #ifdef ENTRY_POINT_DECL |
32 | ENTRY_POINT_DECL(extern) | |
33 | #else | |
34 | extern void ENTRY_POINT; | |
35 | #endif | |
36 | extern void etext; | |
11c981a9 | 37 | |
65233b58 | 38 | #ifndef TEXT_START |
9bc17809 UD |
39 | # ifdef ENTRY_POINT_DECL |
40 | # define TEXT_START ENTRY_POINT | |
41 | # else | |
42 | # define TEXT_START &ENTRY_POINT | |
43 | # endif | |
65233b58 RM |
44 | #endif |
45 | ||
5f3d5c2b | 46 | #ifndef HAVE_INITFINI |
11c981a9 RM |
47 | /* This function gets called at startup by the normal constructor |
48 | mechanism. We link this file together with start.o to produce gcrt1.o, | |
49 | so this constructor will be first in the list. */ | |
5f3d5c2b | 50 | |
1eab1361 | 51 | extern void __gmon_start__ (void) __attribute__ ((constructor)); |
5f3d5c2b RM |
52 | #else |
53 | /* In ELF and COFF, we cannot use the normal constructor mechanism to call | |
54 | __gmon_start__ because gcrt1.o appears before crtbegin.o in the link. | |
55 | Instead crti.o calls it specially (see initfini.c). */ | |
1eab1361 | 56 | extern void __gmon_start__ (void); |
5f3d5c2b RM |
57 | #endif |
58 | ||
59 | void | |
60 | __gmon_start__ (void) | |
11c981a9 | 61 | { |
57ba7bb4 UD |
62 | #ifdef HAVE_INITFINI |
63 | /* Protect from being called more than once. Since crti.o is linked | |
64 | into every shared library, each of their init functions will call us. */ | |
65 | static int called; | |
66 | ||
de71a46a | 67 | if (called) |
57ba7bb4 | 68 | return; |
de71a46a UD |
69 | |
70 | called = 1; | |
57ba7bb4 UD |
71 | #endif |
72 | ||
11c981a9 | 73 | /* Start keeping profiling records. */ |
65233b58 | 74 | __monstartup ((u_long) TEXT_START, (u_long) &etext); |
11c981a9 | 75 | |
6d52618b | 76 | /* Call _mcleanup before exiting; it will write out gmon.out from the |
11c981a9 RM |
77 | collected data. */ |
78 | atexit (&_mcleanup); | |
79 | } |