]> git.ipfire.org Git - thirdparty/glibc.git/blame - csu/gmon-start.c
update from main archive 960904
[thirdparty/glibc.git] / csu / gmon-start.c
CommitLineData
11c981a9 1/* Code to enable profiling at program startup.
5f3d5c2b 2Copyright (C) 1995, 1996 Free Software Foundation, Inc.
11c981a9
RM
3This file is part of the GNU C Library.
4
5The GNU C Library is free software; you can redistribute it and/or
6modify it under the terms of the GNU Library General Public License as
7published by the Free Software Foundation; either version 2 of the
8License, or (at your option) any later version.
9
10The GNU C Library is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13Library General Public License for more details.
14
15You should have received a copy of the GNU Library General Public
16License along with the GNU C Library; see the file COPYING.LIB. If
17not, write to the Free Software Foundation, Inc., 675 Mass Ave,
18Cambridge, MA 02139, USA. */
19
20#include <sys/types.h>
21#include <sys/gmon.h>
22#include <stdlib.h>
23#include <unistd.h>
24
25/* Beginning and end of our code segment. */
1d8dc429 26extern void _start (void), etext (void);
11c981a9 27
5f3d5c2b 28#ifndef HAVE_INITFINI
11c981a9
RM
29/* This function gets called at startup by the normal constructor
30 mechanism. We link this file together with start.o to produce gcrt1.o,
31 so this constructor will be first in the list. */
5f3d5c2b
RM
32
33void __gmon_start__ (void) __attribute__ ((constructor));
34#else
35/* In ELF and COFF, we cannot use the normal constructor mechanism to call
36 __gmon_start__ because gcrt1.o appears before crtbegin.o in the link.
37 Instead crti.o calls it specially (see initfini.c). */
38#endif
39
40void
41__gmon_start__ (void)
11c981a9 42{
57ba7bb4
UD
43#ifdef HAVE_INITFINI
44 /* Protect from being called more than once. Since crti.o is linked
45 into every shared library, each of their init functions will call us. */
46 static int called;
47
48 if (called++)
49 return;
50#endif
51
11c981a9
RM
52 /* Start keeping profiling records. */
53 monstartup ((u_long) &_start, (u_long) &etext);
54
55 /* Call _mcleanup before exitting; it will write out gmon.out from the
56 collected data. */
57 atexit (&_mcleanup);
58}