]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Add --enable-systemtap configuration to define static probe points.
authorRoland McGrath <roland@hack.frob.com>
Fri, 25 May 2012 20:40:20 +0000 (13:40 -0700)
committerRoland McGrath <roland@hack.frob.com>
Fri, 25 May 2012 20:40:20 +0000 (13:40 -0700)
ChangeLog
config.h.in
configure
configure.in
elf/Makefile
elf/rtld-Rules
extra-lib.mk
include/stap-probe.h [new file with mode: 0644]
nptl/ChangeLog
nptl/pthread_create.c

index 8ddc57e8806a607ab40c21dfb3da3cda39939851..e89af6fdfd1531c4e29043bce4bb6202544e5099 100644 (file)
--- 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]
index 54952609efec2703e36b589c1919914eef8e6601..dd184b0cf47b92cbea76521b399a7c0b9fe1c026 100644 (file)
 /* 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
+
 /*
 \f */
 
index 09a06377d7b153f6bded37506f6cbfb0ed4207b0..d73042752ba02071329092ebb81a015118116d08 100755 (executable)
--- 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
index 38b55a6784d248fa3f0ffddacbf9aa852655e44b..1ae9ca48fb5e30f23b04c4d8729eb025d5e93051 100644 (file)
@@ -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
index f6c6fb4644e4eeec86e6cf5eebcd175beb7c865a..0c26ce545a7b16ecebb607897776c01639d1b46d 100644 (file)
@@ -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)))
index 6526aec19ae84df4e8eaae3c60f333e927f81eba..1e03332ca1894b678da230b9abc8c9db10877c2a 100644 (file)
@@ -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
index f2a19b0423b0d77da7047e24adbc4c83ce5a03c3..a2293c5c6e843cd08fdb9f56bb7edc5fc1d12aba 100644 (file)
@@ -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 (file)
index 0000000..1051ad1
--- /dev/null
@@ -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 */
index efeebca2f37108603c337d6862932f9c258cfd7e..ade0b18bc11ef60459bc7b57c9a7c561f0ca9e4c 100644 (file)
@@ -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
index 3c1e4794c77af9f34a3b5852440e044adba4219b..c52ae1137982c33c8e9f5a23c01f8cafd78948af 100644 (file)
@@ -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));