about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRoland McGrath <roland@hack.frob.com>2012-05-25 13:40:20 -0700
committerRoland McGrath <roland@hack.frob.com>2012-05-25 13:40:20 -0700
commit3a097cc7a18309c864186c1b864b90889d2a45e9 (patch)
tree90867caf9bc281dee470b566c7a3188ce86d20c1
parent21708942c9b115a91dc03318a5f9e14328c5a71e (diff)
downloadglibc-3a097cc7a18309c864186c1b864b90889d2a45e9.tar.gz
glibc-3a097cc7a18309c864186c1b864b90889d2a45e9.tar.xz
glibc-3a097cc7a18309c864186c1b864b90889d2a45e9.zip
Add --enable-systemtap configuration to define static probe points.
-rw-r--r--ChangeLog10
-rw-r--r--config.h.in4
-rwxr-xr-xconfigure48
-rw-r--r--configure.in24
-rw-r--r--elf/Makefile3
-rw-r--r--elf/rtld-Rules5
-rw-r--r--extra-lib.mk2
-rw-r--r--include/stap-probe.h80
-rw-r--r--nptl/ChangeLog4
-rw-r--r--nptl/pthread_create.c4
10 files changed, 179 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index 8ddc57e880..e89af6fdfd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2012-05-25  Roland McGrath  <roland@hack.frob.com>
+
+	* include/stap-probe.h: New file.
+	* configure.in: Handle --enable-systemtap.
+	* configure: Regenerated.
+	* config.h.in (USE_STAP_PROBE): New #undef.
+	* extra-lib.mk (CPPFLAGS-$(lib)): Add -DIN_LIB=$(lib).
+	* elf/Makefile (CPPFLAGS-.os): Add -DIN_LIB=rtld.
+	* elf/rtld-Rules (rtld-CPPFLAGS): Likewise.
+
 2012-05-25  Joseph Myers  <joseph@codesourcery.com>
 
 	[BZ #13717]
diff --git a/config.h.in b/config.h.in
index 54952609ef..dd184b0cf4 100644
--- a/config.h.in
+++ b/config.h.in
@@ -181,6 +181,10 @@
 /* Define if obsolete RPC code should be made available for user-level code
    to link against.  */
 #undef LINK_OBSOLETE_RPC
+
+/* Define if Systemtap <sys/sdt.h> probes should be defined.  */
+#undef USE_STAP_PROBE
+
 /*
  */
 
diff --git a/configure b/configure
index 09a06377d7..d73042752b 100755
--- a/configure
+++ b/configure
@@ -784,6 +784,7 @@ enable_all_warnings
 enable_multi_arch
 enable_nss_crypt
 enable_obsolete_rpc
+enable_systemtap
 with_cpu
 '
       ac_precious_vars='build_alias
@@ -1441,6 +1442,7 @@ Optional Features:
   --enable-nss-crypt      enable libcrypt to use nss
   --enable-obsolete-rpc   build and install the obsolete RPC code for
                           link-time usage
+  --enable-systemtap      enable systemtap static probe points [default=no]
 
 Optional Packages:
   --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
@@ -3753,6 +3755,7 @@ else
 fi
 
 
+
 # Check whether --enable-obsolete-rpc was given.
 if test "${enable_obsolete_rpc+set}" = set; then :
   enableval=$enable_obsolete_rpc; link_obsolete_rpc=$enableval
@@ -3767,6 +3770,51 @@ if test "$link_obsolete_rpc" = yes; then
 
 fi
 
+# Check whether --enable-systemtap was given.
+if test "${enable_systemtap+set}" = set; then :
+  enableval=$enable_systemtap; systemtap=$enableval
+else
+  systemtap=no
+fi
+
+if test "x$systemtap" != xno; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for systemtap static probe support" >&5
+$as_echo_n "checking for systemtap static probe support... " >&6; }
+if ${libc_cv_sdt+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+    old_CFLAGS="$CFLAGS"
+  CFLAGS="-std=gnu99 $CFLAGS"
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <sys/sdt.h>
+void foo (int i, void *p)
+{
+  asm ("" STAP_PROBE_ASM (foo, bar, STAP_PROBE_ASM_TEMPLATE (2)) ""
+       :: STAP_PROBE_ASM_OPERANDS (2, i, p));
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  libc_cv_sdt=yes
+else
+  libc_cv_sdt=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+  CFLAGS="$old_CFLAGS"
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_sdt" >&5
+$as_echo "$libc_cv_sdt" >&6; }
+  if test $libc_cv_sdt = yes; then
+    $as_echo "#define USE_STAP_PROBE 1" >>confdefs.h
+
+  elif test "x$systemtap" != xauto; then
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "systemtap support needs sys/sdt.h with asm support
+See \`config.log' for more details" "$LINENO" 5; }
+  fi
+fi
+
 # The way shlib-versions is used to generate soversions.mk uses a
 # fairly simplistic model for name recognition that can't distinguish
 # i486-pc-linux-gnu fully from i486-pc-gnu.  So we mutate a $host_os
diff --git a/configure.in b/configure.in
index 38b55a6784..1ae9ca48fb 100644
--- a/configure.in
+++ b/configure.in
@@ -252,6 +252,7 @@ else
 fi
 AC_SUBST(libc_cv_nss_crypt)
 
+
 AC_ARG_ENABLE([obsolete-rpc],
               AC_HELP_STRING([--enable-obsolete-rpc],
                              [build and install the obsolete RPC code for link-time usage]),
@@ -263,6 +264,29 @@ if test "$link_obsolete_rpc" = yes; then
   AC_DEFINE(LINK_OBSOLETE_RPC)
 fi
 
+AC_ARG_ENABLE([systemtap],
+              [AS_HELP_STRING([--enable-systemtap],
+	       [enable systemtap static probe points @<:@default=no@:>@])],
+              [systemtap=$enableval],
+	      [systemtap=no])
+if test "x$systemtap" != xno; then
+  AC_CACHE_CHECK([for systemtap static probe support], libc_cv_sdt, [dnl
+  old_CFLAGS="$CFLAGS"
+  CFLAGS="-std=gnu99 $CFLAGS"
+  AC_COMPILE_IFELSE([#include <sys/sdt.h>
+void foo (int i, void *p)
+{
+  asm ("" STAP_PROBE_ASM (foo, bar, STAP_PROBE_ASM_TEMPLATE (2)) ""
+       :: STAP_PROBE_ASM_OPERANDS (2, i, p));
+}], [libc_cv_sdt=yes], [libc_cv_sdt=no])
+  CFLAGS="$old_CFLAGS"])
+  if test $libc_cv_sdt = yes; then
+    AC_DEFINE([USE_STAP_PROBE])
+  elif test "x$systemtap" != xauto; then
+    AC_MSG_FAILURE([systemtap support needs sys/sdt.h with asm support])
+  fi
+fi
+
 # The way shlib-versions is used to generate soversions.mk uses a
 # fairly simplistic model for name recognition that can't distinguish
 # i486-pc-linux-gnu fully from i486-pc-gnu.  So we mutate a $host_os
diff --git a/elf/Makefile b/elf/Makefile
index f6c6fb4644..0c26ce545a 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -422,7 +422,8 @@ CFLAGS-dl-cache.c = $(SYSCONF-FLAGS)
 CFLAGS-cache.c = $(SYSCONF-FLAGS)
 CFLAGS-rtld.c = $(SYSCONF-FLAGS)
 
-CPPFLAGS-.os += $(if $(filter $(@F),$(patsubst %,%.os,$(all-rtld-routines))),-DNOT_IN_libc=1 -DIS_IN_rtld=1)
+CPPFLAGS-.os += $(if $(filter $(@F),$(patsubst %,%.os,$(all-rtld-routines))),\
+		     -DNOT_IN_libc=1 -DIS_IN_rtld=1 -DIN_LIB=rtld)
 
 test-modules = $(addprefix $(objpfx),$(addsuffix .so,$(strip $(modules-names))))
 generated += $(addsuffix .so,$(strip $(modules-names)))
diff --git a/elf/rtld-Rules b/elf/rtld-Rules
index 6526aec19a..1e03332ca1 100644
--- a/elf/rtld-Rules
+++ b/elf/rtld-Rules
@@ -1,7 +1,6 @@
 # Subroutine makefile for compiling libc modules linked into dynamic linker.
 
-# Copyright (C) 2002,2003,2005,2006,2008,2010,2011
-#   Free Software Foundation, Inc.
+# Copyright (C) 2002-2012 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
@@ -130,6 +129,6 @@ ifdef rtld-depfiles
 endif
 
 # This here is the whole point of all the shenanigans.
-rtld-CPPFLAGS := -DNOT_IN_libc=1 -DIS_IN_rtld=1
+rtld-CPPFLAGS := -DNOT_IN_libc=1 -DIS_IN_rtld=1 -DIN_LIB=rtld
 
 endif
diff --git a/extra-lib.mk b/extra-lib.mk
index f2a19b0423..a2293c5c6e 100644
--- a/extra-lib.mk
+++ b/extra-lib.mk
@@ -101,4 +101,4 @@ ifneq (,$(cpp-srcs-left))
 include $(patsubst %,$(..)cppflags-iterator.mk,$(cpp-srcs-left))
 endif
 
-CPPFLAGS-$(lib) := -DNOT_IN_libc=1 -DIS_IN_$(lib)=1
+CPPFLAGS-$(lib) := -DNOT_IN_libc=1 -DIS_IN_$(lib)=1 -DIN_LIB=$(lib)
diff --git a/include/stap-probe.h b/include/stap-probe.h
new file mode 100644
index 0000000000..1051ad1980
--- /dev/null
+++ b/include/stap-probe.h
@@ -0,0 +1,80 @@
+/* Macros for defining Systemtap <sys/sdt.h> static probe points.
+   Copyright (C) 2012 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
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef _STAP_PROBE_H
+#define _STAP_PROBE_H 1
+
+#ifdef USE_STAP_PROBE
+
+# include <sys/sdt.h>
+
+/* Our code uses one macro LIBC_PROBE (name, n, arg1, ..., argn).
+
+   Without USE_STAP_PROBE, that does nothing but evaluates all
+   its arguments (to prevent bit rot, unlike e.g. assert).
+
+   Systemtap's header defines the macros STAP_PROBE (provider, name) and
+   STAP_PROBEn (provider, name, arg1, ..., argn).  For "provider" we paste
+   in the IN_LIB name (libc, libpthread, etc.) automagically.  */
+
+# ifndef NOT_IN_libc
+#  define IN_LIB	libc
+# elif !defined IN_LIB
+/* This is intentionally defined with extra unquoted commas in it so
+   that macro substitution will bomb out when it is used.  We don't
+   just use #error here, so that this header can be included by
+   other headers that use LIBC_PROBE inside their own macros.  We
+   only want such headers to fail to compile if those macros are
+   actually used in a context where IN_LIB has not been defined.  */
+#  define IN_LIB	,,,missing -DIN_LIB=... -- not extra-lib.mk?,,,
+# endif
+
+# define LIBC_PROBE(name, n, ...)	\
+  LIBC_PROBE_1 (IN_LIB, name, n, ## __VA_ARGS__)
+
+# define LIBC_PROBE_1(lib, name, n, ...) \
+  STAP_PROBE##n (lib, name, ## __VA_ARGS__)
+
+# define STAP_PROBE0		STAP_PROBE
+
+# define LIBC_PROBE_ASM(name, template) \
+  STAP_PROBE_ASM (IN_LIB, name, template)
+
+# define LIBC_PROBE_ASM_OPERANDS STAP_PROBE_ASM_OPERANDS
+
+#else  /* Not USE_STAP_PROBE.  */
+
+# ifndef __ASSEMBLER__
+/* Evaluate all the arguments and verify that N matches their number.  */
+#  define LIBC_PROBE(name, n, ...)					      \
+  do {									      \
+    _Bool __libc_probe_args[] = { 0, ## __VA_ARGS__ };			      \
+    _Bool __libc_probe_verify_n[(sizeof __libc_probe_args / sizeof (_Bool))   \
+                                == n + 1 ? 1 : -1];			      \
+    (void) __libc_probe_verify_n;					      \
+  } while (0)
+# else
+#  define LIBC_PROBE(name, n, ...)		/* Nothing.  */
+# endif
+
+# define LIBC_PROBE_ASM(name, template)		/* Nothing.  */
+# define LIBC_PROBE_ASM_OPERANDS(n, ...)	/* Nothing.  */
+
+#endif	/* USE_STAP_PROBE.  */
+
+#endif	/* stap-probe.h */
diff --git a/nptl/ChangeLog b/nptl/ChangeLog
index efeebca2f3..ade0b18bc1 100644
--- a/nptl/ChangeLog
+++ b/nptl/ChangeLog
@@ -1,3 +1,7 @@
+2012-05-24  Roland McGrath  <roland@hack.frob.com>
+
+	* pthread_create.c (start_thread): Define pthread_start LIBC_PROBE.
+
 2012-05-17  Andreas Jaeger  <aj@suse.de>
 
 	* sysdeps/unix/sysv/linux/i386/i686/dl-sysdep.h
diff --git a/nptl/pthread_create.c b/nptl/pthread_create.c
index 3c1e4794c7..c52ae11379 100644
--- a/nptl/pthread_create.c
+++ b/nptl/pthread_create.c
@@ -31,6 +31,8 @@
 
 #include <shlib-compat.h>
 
+#include <stap-probe.h>
+
 
 /* Local function to start thread and handle cleanup.  */
 static int start_thread (void *arg);
@@ -299,6 +301,8 @@ start_thread (void *arg)
 	  CANCEL_RESET (oldtype);
 	}
 
+      LIBC_PROBE (pthread_start, 3, (pthread_t) pd, pd->start_routine, pd->arg);
+
       /* Run the code the user provided.  */
 #ifdef CALL_THREAD_FCT
       THREAD_SETMEM (pd, result, CALL_THREAD_FCT (pd));