Blame csu/gmon-start.c

Packit Service 82fcde
/* Code to enable profiling at program startup.
Packit Service 82fcde
   Copyright (C) 1995-2018 Free Software Foundation, Inc.
Packit Service 82fcde
   This file is part of the GNU C Library.
Packit Service 82fcde
Packit Service 82fcde
   The GNU C Library is free software; you can redistribute it and/or
Packit Service 82fcde
   modify it under the terms of the GNU Lesser General Public
Packit Service 82fcde
   License as published by the Free Software Foundation; either
Packit Service 82fcde
   version 2.1 of the License, or (at your option) any later version.
Packit Service 82fcde
Packit Service 82fcde
   In addition to the permissions in the GNU Lesser General Public
Packit Service 82fcde
   License, the Free Software Foundation gives you unlimited
Packit Service 82fcde
   permission to link the compiled version of this file with other
Packit Service 82fcde
   programs, and to distribute those programs without any restriction
Packit Service 82fcde
   coming from the use of this file.  (The GNU Lesser General Public
Packit Service 82fcde
   License restrictions do apply in other respects; for example, they
Packit Service 82fcde
   cover modification of the file, and distribution when not linked
Packit Service 82fcde
   into another program.)
Packit Service 82fcde
Packit Service 82fcde
   Note that people who make modified versions of this file are not
Packit Service 82fcde
   obligated to grant this special exception for their modified
Packit Service 82fcde
   versions; it is their choice whether to do so.  The GNU Lesser
Packit Service 82fcde
   General Public License gives permission to release a modified
Packit Service 82fcde
   version without this exception; this exception also makes it
Packit Service 82fcde
   possible to release a modified version which carries forward this
Packit Service 82fcde
   exception.
Packit Service 82fcde
Packit Service 82fcde
   The GNU C Library is distributed in the hope that it will be useful,
Packit Service 82fcde
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 82fcde
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 82fcde
   Lesser General Public License for more details.
Packit Service 82fcde
Packit Service 82fcde
   You should have received a copy of the GNU Lesser General Public
Packit Service 82fcde
   License along with the GNU C Library; if not, see
Packit Service 82fcde
   <http://www.gnu.org/licenses/>.  */
Packit Service 82fcde
Packit Service 82fcde
#include <sys/types.h>
Packit Service 82fcde
#include <sys/gmon.h>
Packit Service 82fcde
#include <stdlib.h>
Packit Service 82fcde
#include <unistd.h>
Packit Service 82fcde
#define __ASSEMBLY__
Packit Service 82fcde
#include <entry.h>
Packit Service 82fcde
Packit Service 82fcde
/* Beginning and end of our code segment. We cannot declare them
Packit Service 82fcde
   as the external functions since we want the addresses of those
Packit Service 82fcde
   labels. Taking the address of a function may have different
Packit Service 82fcde
   meanings on different platforms. */
Packit Service 82fcde
#ifdef ENTRY_POINT_DECL
Packit Service 82fcde
ENTRY_POINT_DECL(extern)
Packit Service 82fcde
#else
Packit Service 82fcde
extern char ENTRY_POINT[];
Packit Service 82fcde
#endif
Packit Service 82fcde
extern char etext[];
Packit Service 82fcde
Packit Service 82fcde
#ifndef TEXT_START
Packit Service 82fcde
# ifdef ENTRY_POINT_DECL
Packit Service 82fcde
#  define TEXT_START ENTRY_POINT
Packit Service 82fcde
# else
Packit Service 82fcde
#  define TEXT_START &ENTRY_POINT
Packit Service 82fcde
# endif
Packit Service 82fcde
#endif
Packit Service 82fcde
Packit Service 82fcde
#ifdef GMON_START_ARRAY_SECTION
Packit Service 82fcde
static void __gmon_start__ (void);
Packit Service 82fcde
static void (*const gmon_start_initializer) (void)
Packit Service 82fcde
  __attribute__ ((used, section (GMON_START_ARRAY_SECTION))) = &__gmon_start__;
Packit Service 82fcde
static
Packit Service 82fcde
#else
Packit Service 82fcde
/* We cannot use the normal constructor mechanism to call
Packit Service 82fcde
   __gmon_start__ because gcrt1.o appears before crtbegin.o in the link.
Packit Service 82fcde
   Instead crti.o calls it specially.  */
Packit Service 82fcde
extern void __gmon_start__ (void);
Packit Service 82fcde
#endif
Packit Service 82fcde
Packit Service 82fcde
void
Packit Service 82fcde
__gmon_start__ (void)
Packit Service 82fcde
{
Packit Service 82fcde
  /* Protect from being called more than once.  Since crti.o is linked
Packit Service 82fcde
     into every shared library, each of their init functions will call us.  */
Packit Service 82fcde
  static int called;
Packit Service 82fcde
Packit Service 82fcde
  if (called)
Packit Service 82fcde
    return;
Packit Service 82fcde
Packit Service 82fcde
  called = 1;
Packit Service 82fcde
Packit Service 82fcde
  /* Start keeping profiling records.  */
Packit Service 82fcde
  __monstartup ((u_long) TEXT_START, (u_long) &etext);
Packit Service 82fcde
Packit Service 82fcde
  /* Call _mcleanup before exiting; it will write out gmon.out from the
Packit Service 82fcde
     collected data.  */
Packit Service 82fcde
  atexit (&_mcleanup);
Packit Service 82fcde
}