aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoland McGrath <roland@gnu.org>1996-01-17 02:29:57 +0000
committerRoland McGrath <roland@gnu.org>1996-01-17 02:29:57 +0000
commit5f3d5c2bbb4757e9cc5b30bc66b1d7555739bc4a (patch)
tree57d9fa3f28869526d8a1482982bc01cefdacbcb6
parentd99d7e264430e26e9070b4908a6e81103aa92747 (diff)
downloadglibc-5f3d5c2bbb4757e9cc5b30bc66b1d7555739bc4a.zip
glibc-5f3d5c2bbb4757e9cc5b30bc66b1d7555739bc4a.tar.gz
glibc-5f3d5c2bbb4757e9cc5b30bc66b1d7555739bc4a.tar.bz2
* csu/initfini.c (_init): Call __gmon_start__ if defined (weak ref).
* csu/gmon-start.c (__gmon_start__): Renamed from gmon_start, made global. [! HAVE_INITFINI]: Only make it a constructor in this case.
-rw-r--r--ChangeLog5
-rw-r--r--csu/gmon-start.c16
-rw-r--r--csu/initfini.c11
3 files changed, 28 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index e6fc570..5a85adf 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
Tue Jan 16 17:37:39 1996 Roland McGrath <roland@churchy.gnu.ai.mit.edu>
+ * csu/initfini.c (_init): Call __gmon_start__ if defined (weak ref).
+ * csu/gmon-start.c (__gmon_start__): Renamed from gmon_start, made
+ global.
+ [! HAVE_INITFINI]: Only make it a constructor in this case.
+
* gmon/Makefile (CFLAGS-mcount.c): New variable.
(mcount.po): New target.
diff --git a/csu/gmon-start.c b/csu/gmon-start.c
index c9d51b1..2ebbbf1 100644
--- a/csu/gmon-start.c
+++ b/csu/gmon-start.c
@@ -1,5 +1,5 @@
/* Code to enable profiling at program startup.
-Copyright (C) 1995 Free Software Foundation, Inc.
+Copyright (C) 1995, 1996 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -30,12 +30,20 @@ extern void _start (), etext ();
extern void monstartup (u_long, u_long);
extern void _mcleanup (void);
+#ifndef HAVE_INITFINI
/* This function gets called at startup by the normal constructor
mechanism. We link this file together with start.o to produce gcrt1.o,
so this constructor will be first in the list. */
-static void gmon_start (void) __attribute__ ((constructor));
-static void
-gmon_start (void)
+
+void __gmon_start__ (void) __attribute__ ((constructor));
+#else
+/* In ELF and COFF, we cannot use the normal constructor mechanism to call
+ __gmon_start__ because gcrt1.o appears before crtbegin.o in the link.
+ Instead crti.o calls it specially (see initfini.c). */
+#endif
+
+void
+__gmon_start__ (void)
{
/* Start keeping profiling records. */
monstartup ((u_long) &_start, (u_long) &etext);
diff --git a/csu/initfini.c b/csu/initfini.c
index b0d0e68..a3c3b3b 100644
--- a/csu/initfini.c
+++ b/csu/initfini.c
@@ -63,6 +63,17 @@ SECTION (".init")
void
_init (void)
{
+ /* We cannot use the normal constructor mechanism in gcrt1.o because it
+ appears before crtbegin.o in the link, so the header elt of .ctors
+ would come after the elt for __gmon_start__. One approach is for
+ gcrt1.o to reference a symbol which would be defined by some library
+ module which has a constructor; but then user code's constructors
+ would come first, and not be profiled. */
+ extern void __gmon_start__ (void) __attribute__ ((weak));
+ weak_symbol (__gmon_start__)
+ if (&__gmon_start__)
+ __gmon_start__ ();
+
/* End the here document containing the .init prologue code.
Then fetch the .section directive just written and append that
to crtn.s-new, followed by the function epilogue. */