public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [RFC v2][PATCH 01/27] Add NT_GNU_INFINITY to elf.h
  2016-06-13 10:47 [RFC v2][PATCH 00/27] Infinity full-system preview Gary Benson
@ 2016-06-13 10:40 ` Gary Benson
  2016-06-13 10:41 ` [RFC v2][PATCH 02/27] Add Infinity THREAD_SELF macros to sysdeps/aarch64/nptl/tls.h Gary Benson
                   ` (25 subsequent siblings)
  26 siblings, 0 replies; 55+ messages in thread
From: Gary Benson @ 2016-06-13 10:40 UTC (permalink / raw)
  To: libc-alpha

This commit adds a new note type NT_GNU_INFINITY to elf.h.
---
 elf/elf.h |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/elf/elf.h b/elf/elf.h
index 15f5a75..cceda8a 100644
--- a/elf/elf.h
+++ b/elf/elf.h
@@ -1123,6 +1123,9 @@ typedef struct
 /* Version note generated by GNU gold containing a version string.  */
 #define NT_GNU_GOLD_VERSION	4
 
+/* Debugger interface note.  */
+#define NT_GNU_INFINITY	5
+
 
 /* Move records.  */
 typedef struct
-- 
1.7.1

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [RFC v2][PATCH 20/27] Add ./configure checks for I8C and I8X
  2016-06-13 10:47 [RFC v2][PATCH 00/27] Infinity full-system preview Gary Benson
                   ` (5 preceding siblings ...)
  2016-06-13 10:41 ` [RFC v2][PATCH 04/27] Add Infinity THREAD_SELF macros to sysdeps/arm/nptl/tls.h Gary Benson
@ 2016-06-13 10:41 ` Gary Benson
  2016-06-13 10:41 ` [RFC v2][PATCH 22/27] Export stack_used as __stack_used Gary Benson
                   ` (19 subsequent siblings)
  26 siblings, 0 replies; 55+ messages in thread
From: Gary Benson @ 2016-06-13 10:41 UTC (permalink / raw)
  To: libc-alpha

This commit adds configure checks for I8C (the Infinity note
compiler) and I8X (the Infinity note testing framework).

This patch differs from the previous version
<https://sourceware.org/ml/libc-alpha/2015-10/msg00702.html>
in the following ways:

 * The versions of I8C and I8X are checked.

 * There is now a --with-infinity option.  If specified, configure
   will fail if I8C and I8X are not present or too old.  If
   --without-infinity is specified then no checks will be performed.
   If neither is specified then --with-infinity will be assumed if
   I8C is found on the build system.

 * Minimum versions of I8C and I8X are listed in manual/install.texi
   and INSTALL.
---
 INSTALL             |   10 ++
 config.make.in      |    3 +
 configure           |  254 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 configure.ac        |   42 +++++++++
 manual/install.texi |   11 ++
 5 files changed, 319 insertions(+), 1 deletions(-)

diff --git a/INSTALL b/INSTALL
index c70ea9f..363bb24 100644
--- a/INSTALL
+++ b/INSTALL
@@ -407,6 +407,16 @@ build the GNU C Library:
      GNU 'sed' 3.02.  If you like to run the test suite, you should
      definitely upgrade 'sed'.
 
+   * I8C and I8X 0.0.3 or newer
+
+     I8C is used to compile Infinity notes, and I8X is used to test
+     them.  Whether they are required is controlled by the
+     '--with-infinity' and '--without-infinity' configuration options.
+     If '--with-infinity' is specified then both I8C and I8X are
+     required to build the GNU C Library.  If neither '--with-infinity'
+     nor '--without-infinity' are specified then '--with-infinity' will
+     be assumed if I8C is present on the build system.
+
 If you change any of the 'configure.ac' files you will also need
 
    * GNU 'autoconf' 2.69 (exactly)
diff --git a/config.make.in b/config.make.in
index 05ed6ec..cb08ba0 100644
--- a/config.make.in
+++ b/config.make.in
@@ -90,6 +90,7 @@ use-nscd = @use_nscd@
 build-hardcoded-path-in-tests= @hardcoded_path_in_tests@
 build-pt-chown = @build_pt_chown@
 enable-lock-elision = @enable_lock_elision@
+build-infinity = @build_infinity@
 
 # Build tools.
 CC = @CC@
@@ -108,6 +109,8 @@ AUTOCONF = @AUTOCONF@
 OBJDUMP = @OBJDUMP@
 OBJCOPY = @OBJCOPY@
 READELF = @READELF@
+I8C = @I8C@
+I8X = @I8X@
 
 # Installation tools.
 INSTALL = @INSTALL@
diff --git a/configure b/configure
index 06ea87e..6fc0a0c 100755
--- a/configure
+++ b/configure
@@ -652,6 +652,9 @@ LN_S
 INSTALL_DATA
 INSTALL_SCRIPT
 INSTALL_PROGRAM
+build_infinity
+I8X
+I8C
 sysdeps_add_ons
 sysnames
 submachine
@@ -748,6 +751,7 @@ with_gd_lib
 with_fp
 with_binutils
 with_selinux
+with_infinity
 with_headers
 with_default_link
 enable_sanity_checks
@@ -1454,6 +1458,7 @@ Optional Packages:
   --with-fp               if using floating-point hardware [default=yes]
   --with-binutils=PATH    specify location of binutils (as and ld)
   --with-selinux          if building with SELinux support
+  --with-infinity         if building with Infinity support
   --with-headers=PATH     location of system headers to use (for example
                           /usr/src/linux/include) [default=compiler default]
   --with-default-link     do not use explicit linker scripts
@@ -3303,6 +3308,14 @@ else
 fi
 
 
+# Check whether --with-infinity was given.
+if test "${with_infinity+set}" = set; then :
+  withval=$with_infinity; with_infinity=$withval
+else
+  with_infinity=auto
+fi
+
+
 
 # Check whether --with-headers was given.
 if test "${with_headers+set}" = set; then :
@@ -3864,7 +3877,7 @@ if test -z "$enable_hacker_mode" && test x"$libc_config_ok" != xyes; then
 *** The GNU C library is currently unavailable for this platform.
 *** If you are interested in seeing glibc on this platform visit
 *** the \"How to submit a new port\" in the wiki:
-***   https://sourceware.org/glibc/wiki/HomePage#Development
+***   https://sourceware.org/glibc/wiki/#Development
 *** and join the community!" "$LINENO" 5
     ;;
   esac
@@ -4204,6 +4217,116 @@ $as_echo "$as_me: WARNING: add-on $add_on contributed no useful sysdeps director
 done
 
 
+# Infinity detection
+if test x$with_infinity = xno ; then
+  build_infinity=no;
+else
+  for ac_prog in i8c
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_I8C+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$I8C"; then
+  ac_cv_prog_I8C="$I8C" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_I8C="$ac_prog"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+I8C=$ac_cv_prog_I8C
+if test -n "$I8C"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $I8C" >&5
+$as_echo "$I8C" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+  test -n "$I8C" && break
+done
+test -n "$I8C" || I8C="no"
+
+  if test x$I8C = xno ; then
+    if test x$with_infinity = xyes ; then
+      as_fn_error $? "Infinity explicitly required, but i8c not found" "$LINENO" 5
+    else
+      build_infinity=no
+    fi
+  fi
+  if test x$build_infinity != xno ; then
+    for ac_prog in i8x
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_I8X+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$I8X"; then
+  ac_cv_prog_I8X="$I8X" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_I8X="$ac_prog"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+I8X=$ac_cv_prog_I8X
+if test -n "$I8X"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $I8X" >&5
+$as_echo "$I8X" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+  test -n "$I8X" && break
+done
+test -n "$I8X" || I8X="no"
+
+    if test x$I8X = xno ; then
+      if test x$with_infinity = xyes ; then
+        as_fn_error $? "Infinity explicitly required, but i8x not found" "$LINENO" 5
+      else
+        build_infinity=no
+      fi
+    else
+      build_infinity=yes
+    fi
+  fi
+fi
+
 
 ### Locate tools.
 
@@ -5013,6 +5136,135 @@ else
   AUTOCONF=no
 fi
 
+if test x$build_infinity = xyes ; then
+  for ac_prog in $I8C
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_I8C+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$I8C"; then
+  ac_cv_prog_I8C="$I8C" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_I8C="$ac_prog"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+I8C=$ac_cv_prog_I8C
+if test -n "$I8C"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $I8C" >&5
+$as_echo "$I8C" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+  test -n "$I8C" && break
+done
+
+if test -z "$I8C"; then
+  ac_verc_fail=yes
+else
+  # Found it, now check the version.
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking version of $I8C" >&5
+$as_echo_n "checking version of $I8C... " >&6; }
+  ac_prog_version=`$I8C --version 2>&1 | sed -n 's/^.*.*I8C.* \([0-9]*\.[0-9.]*\).*$/\1/p'`
+  case $ac_prog_version in
+    '') ac_prog_version="v. ?.??, bad"; ac_verc_fail=yes;;
+    0.0.[3-9]* | 0.0.[1-9][0-9]* | 0.[1-9]* | [1-9].*)
+       ac_prog_version="$ac_prog_version, ok"; ac_verc_fail=no;;
+    *) ac_prog_version="$ac_prog_version, bad"; ac_verc_fail=yes;;
+
+  esac
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_prog_version" >&5
+$as_echo "$ac_prog_version" >&6; }
+fi
+if test $ac_verc_fail = yes; then
+  critic_missing="$critic_missing i8c"
+fi
+
+  for ac_prog in $I8X
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_I8X+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$I8X"; then
+  ac_cv_prog_I8X="$I8X" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_I8X="$ac_prog"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+I8X=$ac_cv_prog_I8X
+if test -n "$I8X"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $I8X" >&5
+$as_echo "$I8X" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+  test -n "$I8X" && break
+done
+
+if test -z "$I8X"; then
+  ac_verc_fail=yes
+else
+  # Found it, now check the version.
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking version of $I8X" >&5
+$as_echo_n "checking version of $I8X... " >&6; }
+  ac_prog_version=`$I8X --version 2>&1 | sed -n 's/^.*.*I8X.* \([0-9]*\.[0-9.]*\).*$/\1/p'`
+  case $ac_prog_version in
+    '') ac_prog_version="v. ?.??, bad"; ac_verc_fail=yes;;
+    0.0.[3-9]* | 0.0.[1-9][0-9]* | 0.[1-9]* | [1-9].*)
+       ac_prog_version="$ac_prog_version, ok"; ac_verc_fail=no;;
+    *) ac_prog_version="$ac_prog_version, bad"; ac_verc_fail=yes;;
+
+  esac
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_prog_version" >&5
+$as_echo "$ac_prog_version" >&6; }
+fi
+if test $ac_verc_fail = yes; then
+  critic_missing="$critic_missing i8x"
+fi
+
+fi
+
 test -n "$critic_missing" && as_fn_error $? "
 *** These critical programs are missing or too old:$critic_missing
 *** Check the INSTALL file for required versions." "$LINENO" 5
diff --git a/configure.ac b/configure.ac
index 3c766b7..c750775 100644
--- a/configure.ac
+++ b/configure.ac
@@ -143,6 +143,11 @@ AC_ARG_WITH([selinux],
 			   [if building with SELinux support]),
 	    [with_selinux=$withval],
 	    [with_selinux=auto])
+AC_ARG_WITH([infinity],
+	    AC_HELP_STRING([--with-infinity],
+			   [if building with Infinity support]),
+	    [with_infinity=$withval],
+	    [with_infinity=auto])
 
 AC_ARG_WITH([headers],
 	    AC_HELP_STRING([--with-headers=PATH],
@@ -926,6 +931,32 @@ for add_on in $add_ons; do
 done
 AC_SUBST(sysdeps_add_ons)
 
+# Infinity detection
+if test x$with_infinity = xno ; then
+  build_infinity=no;
+else
+  AC_CHECK_PROGS(I8C, i8c, no)
+  if test x$I8C = xno ; then
+    if test x$with_infinity = xyes ; then
+      AC_MSG_ERROR([Infinity explicitly required, but i8c not found])
+    else
+      build_infinity=no
+    fi
+  fi
+  if test x$build_infinity != xno ; then
+    AC_CHECK_PROGS(I8X, i8x, no)
+    if test x$I8X = xno ; then
+      if test x$with_infinity = xyes ; then
+        AC_MSG_ERROR([Infinity explicitly required, but i8x not found])
+      else
+        build_infinity=no
+      fi
+    else
+      build_infinity=yes
+    fi
+  fi
+fi
+AC_SUBST(build_infinity)
 
 ### Locate tools.
 
@@ -1004,6 +1035,17 @@ else
   AUTOCONF=no
 fi
 
+if test x$build_infinity = xyes ; then
+  AC_CHECK_PROG_VER(I8C, $I8C, --version,
+    [.*I8C.* \([0-9]*\.[0-9.]*\)],
+    [0.0.[3-9]* | 0.0.[1-9][0-9]* | 0.[1-9]* | [1-9].*],
+    critic_missing="$critic_missing i8c")
+  AC_CHECK_PROG_VER(I8X, $I8X, --version,
+    [.*I8X.* \([0-9]*\.[0-9.]*\)],
+    [0.0.[3-9]* | 0.0.[1-9][0-9]* | 0.[1-9]* | [1-9].*],
+    critic_missing="$critic_missing i8x")
+fi
+
 test -n "$critic_missing" && AC_MSG_ERROR([
 *** These critical programs are missing or too old:$critic_missing
 *** Check the INSTALL file for required versions.])
diff --git a/manual/install.texi b/manual/install.texi
index de9d270..63d8444 100644
--- a/manual/install.texi
+++ b/manual/install.texi
@@ -454,6 +454,17 @@ generate @code{msgs.h} for the test suite.  This script works correctly
 only with GNU @code{sed} 3.02.  If you like to run the test suite, you
 should definitely upgrade @code{sed}.
 
+@item
+I8C and I8X 0.0.3 or newer
+
+I8C is used to compile Infinity notes, and I8X is used to test them.
+Whether they are required is controlled by the @samp{--with-infinity}
+and @samp{--without-infinity} configuration options.  If
+@samp{--with-infinity} is specified then both I8C and I8X are required
+to build @theglibc{}.  If neither @samp{--with-infinity} nor
+@samp{--without-infinity} are specified then @samp{--with-infinity}
+will be assumed if I8C is present on the build system.
+
 @end itemize
 
 @noindent
-- 
1.7.1

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [RFC v2][PATCH 04/27] Add Infinity THREAD_SELF macros to sysdeps/arm/nptl/tls.h
  2016-06-13 10:47 [RFC v2][PATCH 00/27] Infinity full-system preview Gary Benson
                   ` (4 preceding siblings ...)
  2016-06-13 10:41 ` [RFC v2][PATCH 18/27] New gen-as-const-header infinity-thread_self.h Gary Benson
@ 2016-06-13 10:41 ` Gary Benson
  2016-06-13 10:41 ` [RFC v2][PATCH 20/27] Add ./configure checks for I8C and I8X Gary Benson
                   ` (20 subsequent siblings)
  26 siblings, 0 replies; 55+ messages in thread
From: Gary Benson @ 2016-06-13 10:41 UTC (permalink / raw)
  To: libc-alpha

This commit adds Infinity THREAD_SELF macros for arm.
---
 sysdeps/arm/nptl/tls.h |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/sysdeps/arm/nptl/tls.h b/sysdeps/arm/nptl/tls.h
index 1ef57d2..4174e4c 100644
--- a/sysdeps/arm/nptl/tls.h
+++ b/sysdeps/arm/nptl/tls.h
@@ -95,9 +95,13 @@ typedef struct
 # define THREAD_SELF \
  ((struct pthread *)__builtin_thread_pointer () - 1)
 
+/* Magic for Infinity to know how to do THREAD_SELF.  */
+# define I8_THREAD_SELF I8_TS_CONST_THREAD_AREA
+# define I8_TS_CTA_VALUE sizeof (struct pthread)
+
 /* Magic for libthread_db to know how to do THREAD_SELF.  */
 # define DB_THREAD_SELF \
-  CONST_THREAD_AREA (32, sizeof (struct pthread))
+  CONST_THREAD_AREA (32, I8_TS_CTA_VALUE)
 
 /* Access to data in the thread descriptor is easy.  */
 #define THREAD_GETMEM(descr, member) \
-- 
1.7.1

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [RFC v2][PATCH 25/27] Add Infinity notes implementing libpthread::thr_iter
  2016-06-13 10:47 [RFC v2][PATCH 00/27] Infinity full-system preview Gary Benson
                   ` (7 preceding siblings ...)
  2016-06-13 10:41 ` [RFC v2][PATCH 22/27] Export stack_used as __stack_used Gary Benson
@ 2016-06-13 10:41 ` Gary Benson
  2016-06-13 10:47 ` [RFC v2][PATCH 15/27] Add Infinity THREAD_SELF macros to sysdeps/sparc/nptl/tls.h Gary Benson
                   ` (17 subsequent siblings)
  26 siblings, 0 replies; 55+ messages in thread
From: Gary Benson @ 2016-06-13 10:41 UTC (permalink / raw)
  To: libc-alpha

This commit adds the Infinity function libpthread::thr_iter,
the Infinity equivalent of libthread_db's td_ta_thr_iter.
---
 nptl/Makefile                 |    2 +-
 nptl/infinity-thr_iter.i8     |  187 ++++++++++++++++++++++++++++++++++
 nptl/tst-infinity-thr_iter.py |  221 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 409 insertions(+), 1 deletions(-)
 create mode 100644 nptl/infinity-thr_iter.i8
 create mode 100644 nptl/tst-infinity-thr_iter.py

diff --git a/nptl/Makefile b/nptl/Makefile
index 9beb879..6967940 100644
--- a/nptl/Makefile
+++ b/nptl/Makefile
@@ -139,7 +139,7 @@ libpthread-routines = nptl-init vars events version pt-interp \
 #		      pthread_setresgid
 
 ifeq ($(build-infinity),yes)
-infinity-routines = infinity-map_lwp2thr
+infinity-routines = infinity-map_lwp2thr infinity-thr_iter
 
 libpthread-routines += $(infinity-routines)
 endif
diff --git a/nptl/infinity-thr_iter.i8 b/nptl/infinity-thr_iter.i8
new file mode 100644
index 0000000..7c079fe
--- /dev/null
+++ b/nptl/infinity-thr_iter.i8
@@ -0,0 +1,187 @@
+/* Iterate over a process's threads.
+   Copyright (C) 2003-2016 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/>.  */
+
+#include "infinity-nptl.i8"
+
+/* Call CALLBACK (TD, CBDATA_P) for each thread in the list starting
+   at HEAD.  Our first return value will be TD_OK on success, or a
+   non-TD_OK td_err_e code indicating the reason for failure.  If our
+   first return value was TD_OK then our second return value will be
+   TRUE if the list is uninitialized or empty; FALSE otherwise.  If
+   our first return value was not TD_OK then our second return value
+   is undefined.  */
+
+define MODULE_NAME::__iterate_thread_list returns td_err_e, bool
+	argument thr_iter_f callback
+	argument opaque cbdata_p
+	argument int ti_pri
+	argument ptr head
+	argument pid_t match_pid
+	argument bool fake_if_empty
+
+  /* Load the first descriptor in the list.  If it's NULL then
+     __pthread_initialize_minimal has not gotten far enough and
+     we may need to fake a descriptor for the main thread.  */
+	deref LIST_T_NEXT_OFFSET(head), ptr
+	dup
+	beq NULL, libpthread_maybe_uninitialized
+	dup
+	beq head, libpthread_maybe_uninitialized
+
+  /* Load our second return value (FALSE, to indicate that the supplied
+     list was not uninitialized or empty).  */
+	load FALSE
+	swap
+
+  /* Main loop.  ToS is a pointer to a list_t, either the list field
+     of a struct pthread, or to the list head if we're at the end.  */
+loop:
+	dup
+	beq head, end_of_list
+	sub PTHREAD_LIST_OFFSET
+	name 0, descr
+
+  /* Verify that this thread's pid field matches the child PID.  If
+     its pid field is negative, it's about to do a fork or it's the
+     sole thread in a fork child. */
+	deref PTHREAD_PID_OFFSET(descr), pid_t
+	dup
+	bge 0, test_pid
+
+  /* If pid == -match_pid it's about to do a fork, but it's really
+     still the parent PID.  */
+	neg
+	beq match_pid, pid_matches /* It's about to fork. */
+
+  /* It must be a fork child, whose new PID is in the tid field.  */
+	deref PTHREAD_TID_OFFSET(descr), pid_t
+
+test_pid:
+	bne match_pid, continue_loop
+
+pid_matches:
+  /* Now test whether this thread matches the specified conditions.  */
+	deref PTHREAD_SCHEDPOLICY_OFFSET(descr), i32
+	bne SCHED_OTHER, load_priority
+	load 0
+	goto test_priority
+
+load_priority:
+	deref PTHREAD_SCHEDPARAM_SCHED_PRIORITY_OFFSET(descr), i32
+
+test_priority:
+	blt ti_pri, continue_loop
+
+  /* It matches, call the callback function.  */
+        load descr
+	load cbdata_p
+	call callback
+	bne 0, main_loop_callback_failed
+
+continue_loop:
+  /* ToS is descr.  */
+	add PTHREAD_LIST_OFFSET
+	add LIST_T_NEXT_OFFSET
+	deref ptr
+	goto loop
+
+end_of_list:
+  /* ToS is head.  */
+	drop
+	load TD_OK
+	return
+
+libpthread_maybe_uninitialized:
+	load TRUE  /* The supplied list was uninitialized or empty).  */
+	load fake_if_empty
+	beq TRUE, fake_main_thread
+  /* We do not need to fake the main thread.  */
+	load TD_OK
+	return
+
+fake_main_thread:
+  /* __pthread_initialize_minimal has not gotten far enough.  We
+     need to call the callback for the main thread, but we can't
+     rely on its thread register as they sometimes contain garbage
+     that would confuse us (left by the kernel at exec).   We fake
+     a special descriptor of NULL for the initial thread; other
+     routines in this library recognise this special descriptor
+     and act accordingly.  */
+	load NULL
+	load cbdata_p
+	call callback
+	bne 0, fake_main_callback_failed
+	load TD_OK
+	return
+
+fake_main_callback_failed:
+	load TD_DBERR
+	return
+
+main_loop_callback_failed:
+  /* ToS is descr.  */
+	drop
+	load TD_DBERR
+	return
+
+/* Call CALLBACK (TD, CBDATA_P) for each of a process's threads, with
+   TD being a thread descriptor for the thread.  Thread descriptors
+   are opaque pointers and should not be dereferenced outside of this
+   library.  Return TD_OK on success, or a non-TD_OK td_err_e code
+   indicating the reason for failure.  The callback should return 0
+   to indicate success; if the callback returns otherwise then this
+   iteration will stop and this function will return TD_DBERR.  */
+
+define MODULE_NAME::thr_iter returns td_err_e
+	argument thr_iter_f callback
+	argument opaque cbdata_p
+	argument int ti_pri
+
+  /* The thread library keeps two lists for the running threads.
+     One list (__stack_user) contains the thread which are using
+     user-provided stacks and the other (__stack_used) includes the
+     threads for which the thread library allocated the stacks.  We
+     have to iterate over both lists separately.  We're going to
+     start with __stack_user, but we're going to set up the stack
+     for the second call (to iterate __stack_used) first.  */
+	load __stack_used
+
+  /* Get the PID of the main thread.  */
+	call procservice::getpid
+	name 0, main_pid
+
+  /* Process the list of threads with user-provided stacks.  */
+	load callback
+	load cbdata_p
+	load ti_pri
+	load __stack_user
+	load main_pid
+	load FALSE
+	call __iterate_thread_list
+
+	dup  /* Save code in case it's not TD_OK.  */
+	bne TD_OK, first_call_failed
+	drop /* It was TD_OK, we can drop it now.  */
+
+  /* Process the list of threads with library-allocated stacks.  */
+	call __iterate_thread_list
+	return
+
+first_call_failed:
+  /* ToS is td_err_e error code from __iterate_thread_list.  */
+	return
diff --git a/nptl/tst-infinity-thr_iter.py b/nptl/tst-infinity-thr_iter.py
new file mode 100644
index 0000000..f9f3354
--- /dev/null
+++ b/nptl/tst-infinity-thr_iter.py
@@ -0,0 +1,221 @@
+from i8c.runtime import TestCase
+
+TestCase.import_builtin_constants()
+TestCase.import_constants_from("infinity-nptl-constants.h")
+TestCase.import_constants_from("infinity-nptl_db-constants.h")
+
+class TestThread(object):
+    def __init__(self, pid, policy=SCHED_OTHER, priority=0, tid=None):
+        self.pid = pid
+        self.policy = policy
+        self.priority = priority
+        self.tid = tid
+
+    def write_into(self, buf):
+        self.__buf = buf
+        buf.store_i32(PTHREAD_PID_OFFSET, self.pid)
+        buf.store_i32(PTHREAD_SCHEDPOLICY_OFFSET, self.policy)
+        buf.store_i32(PTHREAD_SCHEDPARAM_SCHED_PRIORITY_OFFSET,
+                      self.priority)
+        if self.tid is not None:
+            buf.store_i32(PTHREAD_TID_OFFSET, self.tid)
+
+    @property
+    def handle(self):
+        return self.__buf.location
+
+    def matches(self, test):
+        if self.pid < 0:
+            if not (self.pid == -test.MAIN_PID
+                    or self.tid == test.MAIN_PID):
+                return False
+        elif self.pid != test.MAIN_PID:
+            return False
+        if self.priority < test.TI_PRIORITY:
+            return False
+        return True
+
+class TestThrIter(TestCase):
+    TESTFUNC = "libpthread::thr_iter(Fi(po)oi)i"
+    MAIN_PID = 30000
+
+    # Arguments call_thr_iter uses.
+    TI_CALLBACK_ARG = lambda x: x + 3
+    TI_PRIORITY = TD_THR_LOWEST_PRIORITY
+
+    def setUp(self):
+        # Set up the address space.
+        with self.memory.builder() as mem:
+            self.__setup_threads(mem, "__stack_user", self.STACK_USER)
+            self.__setup_threads(mem, "__stack_used", self.STACK_USED)
+
+    def __setup_threads(self, mem, symname, threads):
+        head = mem.alloc(symname)
+        if threads is None:
+            # This thread list is uninitialized.
+            head.store_ptr(LIST_T_NEXT_OFFSET, NULL)
+            return
+
+        prev = head
+        for src in threads:
+            dst = mem.alloc()
+            src.write_into(dst)
+
+            list = dst + PTHREAD_LIST_OFFSET
+            prev.store_ptr(LIST_T_NEXT_OFFSET, list)
+            prev = list
+        prev.store_ptr(LIST_T_NEXT_OFFSET, head)
+
+    def call_procservice_getpid(self):
+        """Implementation of procservice::getpid."""
+        return self.MAIN_PID
+
+    def recording_callback(self, handle, arg):
+        self.assertEqual(arg, self.TI_CALLBACK_ARG)
+        self.calls.append(handle)
+        return 0
+
+    def failing_callback(self, handle, arg):
+        self.assertEqual(arg, self.TI_CALLBACK_ARG)
+        return 1
+
+    def call_thr_iter(self, callback):
+        return self.i8ctx.call(self.TESTFUNC,
+                               callback,
+                               self.TI_CALLBACK_ARG,
+                               self.TI_PRIORITY)
+
+    def run_standard_test(self, expect_ncalls, null_ok=False):
+        # Check callback is called for the expected threads.
+        self.calls = []
+        result = self.call_thr_iter(self.recording_callback)
+        self.assertEqual(len(result), 1)
+        self.assertEqual(result[0], TD_OK)
+        self.check_calls(expect_ncalls, null_ok)
+        # Check that callback errors are handled.
+        if expect_ncalls != 0:
+            result = self.call_thr_iter(self.failing_callback)
+            self.assertEqual(len(result), 1)
+            self.assertEqual(result[0], TD_DBERR)
+
+    def check_calls(self, expect_ncalls, null_ok):
+        expect, empty_count = [], 0
+        for list in self.STACK_USER, self.STACK_USED:
+            if not list:
+                empty_count += 1
+                continue
+            for thread in list:
+                if thread.matches(self):
+                    expect.append(thread.handle)
+        if empty_count == 2:
+            expect.append(NULL) # faked main process
+        # Check the list we've built seems right.
+        self.assertEqual(len(expect), expect_ncalls)
+        if not null_ok:
+            self.assertNotIn(NULL, expect)
+        # Now check our list matches what happened.
+        self.assertEqual(self.calls, expect)
+
+# Tests with uninitialized and partly initialized thread lists.
+
+class TestThrIter_both_uninit(TestThrIter):
+    STACK_USER = None
+    STACK_USED = None
+
+    def test_both_uninit(self):
+       """Test thr_iter with both lists uninitialized"""
+       self.run_standard_test(1, True)
+
+class TestThrIter_stack_user_uninit(TestThrIter):
+    STACK_USER = None
+    STACK_USED = []
+
+    def test_stack_user_uninit(self):
+        """Test thr_iter with __stack_user uninitialized"""
+        # There is a tiny window in glibc where this setup can happen.
+        self.run_standard_test(1, True)
+
+class TestThrIter_both_empty(TestThrIter):
+    STACK_USER = []
+    STACK_USED = []
+
+    def test_stack_user_uninit(self):
+        """Test thr_iter with both lists initialized but empty"""
+        # There is a tiny window in glibc where this setup can happen.
+        self.run_standard_test(1, True)
+
+class TestThrIter_stack_used_uninit_1(TestThrIter):
+    STACK_USER = []
+    STACK_USED = None
+
+    def test_stack_used_uninit_1(self):
+        """Test thr_iter with __stack_used uninitialized (1)"""
+        # This should never happen in glibc (__stack_used is
+        # initialized first) but we test it anyway.
+        self.run_standard_test(1, True)
+
+class TestThrIter_stack_used_uninit_2(TestThrIter):
+    STACK_USER = [TestThread(TestThrIter.MAIN_PID)]
+    STACK_USED = None
+
+    def test_stack_used_uninit_2(self):
+        """Test thr_iter with __stack_used uninitialized (2)"""
+        # This should never happen in glibc (__stack_used is
+        # initialized first) but we test it anyway.
+        self.run_standard_test(1)
+
+# Test with threads on both lists.
+
+class TestThrIter_regular(TestThrIter):
+    STACK_USER = [TestThread(TestThrIter.MAIN_PID),
+                  TestThread(TestThrIter.MAIN_PID, SCHED_FIFO, 5),
+                  TestThread(TestThrIter.MAIN_PID, SCHED_RR, -14),
+                  TestThread(TestThrIter.MAIN_PID),
+                  TestThread(TestThrIter.MAIN_PID + 1),
+                  TestThread(TestThrIter.MAIN_PID + 2),
+                  TestThread(TestThrIter.MAIN_PID)]
+    STACK_USED = [TestThread(TestThrIter.MAIN_PID + 4, SCHED_FIFO, -3),
+                  TestThread(TestThrIter.MAIN_PID),
+                  TestThread(TestThrIter.MAIN_PID, SCHED_RR, -5),
+                  TestThread(TestThrIter.MAIN_PID + 2, SCHED_RR, -3),
+                  TestThread(TestThrIter.MAIN_PID + 1),
+                  TestThread(TestThrIter.MAIN_PID),
+                  TestThread(TestThrIter.MAIN_PID + 2),
+                  TestThread(TestThrIter.MAIN_PID + 1),
+                  TestThread(TestThrIter.MAIN_PID - 1),
+                  # Threads which are about to fork.
+                  TestThread(-TestThrIter.MAIN_PID),
+                  TestThread(-TestThrIter.MAIN_PID, SCHED_FIFO, -3),
+                  # Threads which are fork children.
+                  TestThread(-(TestThrIter.MAIN_PID + 1),
+                             tid=TestThrIter.MAIN_PID),
+                  TestThread(-(TestThrIter.MAIN_PID + 2),
+                             SCHED_RR, -5,
+                             tid=TestThrIter.MAIN_PID),
+                  TestThread(-(TestThrIter.MAIN_PID + 2),
+                             tid=TestThrIter.MAIN_PID + 4),
+    ]
+
+    def test_thr_iter(self):
+        """Test thr_iter with both lists initialized"""
+        self.run_standard_test(12)
+
+    def test_by_priority(self):
+        """Test thr_iter priority filtering works."""
+        counts = {}
+        for list in self.STACK_USER, self.STACK_USED:
+            for thread in list:
+                if thread.matches(self):
+                    priority = thread.priority
+                    counts[priority] = counts.get(priority, 0) + 1
+
+        pstart = TD_THR_LOWEST_PRIORITY
+        plimit = pstart + 32 # POSIX
+        self.assertLessEqual(pstart, min(counts.keys()))
+        self.assertGreater(plimit, max(counts.keys()))
+
+        nthreads = 0
+        for priority in reversed(range(pstart, plimit)):
+            nthreads += counts.get(priority, 0)
+            self.TI_PRIORITY = priority
+            self.run_standard_test(nthreads)
-- 
1.7.1

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [RFC v2][PATCH 26/27] Add Infinity notes implementing libpthread::thr_get_lwpid
  2016-06-13 10:47 [RFC v2][PATCH 00/27] Infinity full-system preview Gary Benson
  2016-06-13 10:40 ` [RFC v2][PATCH 01/27] Add NT_GNU_INFINITY to elf.h Gary Benson
  2016-06-13 10:41 ` [RFC v2][PATCH 02/27] Add Infinity THREAD_SELF macros to sysdeps/aarch64/nptl/tls.h Gary Benson
@ 2016-06-13 10:41 ` Gary Benson
  2016-06-13 10:41 ` [RFC v2][PATCH 03/27] Add Infinity THREAD_SELF macros to sysdeps/alpha/nptl/tls.h Gary Benson
                   ` (23 subsequent siblings)
  26 siblings, 0 replies; 55+ messages in thread
From: Gary Benson @ 2016-06-13 10:41 UTC (permalink / raw)
  To: libc-alpha

This commit adds the Infinity function libpthread::thr_get_lwpid.
It has no libthread_db equivalent (in libthread_db the LWPID of
a thread is read from the ti_lid field of the td_thrinfo_t that
td_thr_get_info fills in).
---
 nptl/Makefile                      |    3 +-
 nptl/infinity-thr_get_lwpid.i8     |   38 ++++++++++++++++++++++++++++++++++++
 nptl/tst-infinity-thr_get_lwpid.py |   37 +++++++++++++++++++++++++++++++++++
 3 files changed, 77 insertions(+), 1 deletions(-)
 create mode 100644 nptl/infinity-thr_get_lwpid.i8
 create mode 100644 nptl/tst-infinity-thr_get_lwpid.py

diff --git a/nptl/Makefile b/nptl/Makefile
index 6967940..bdfe656 100644
--- a/nptl/Makefile
+++ b/nptl/Makefile
@@ -139,7 +139,8 @@ libpthread-routines = nptl-init vars events version pt-interp \
 #		      pthread_setresgid
 
 ifeq ($(build-infinity),yes)
-infinity-routines = infinity-map_lwp2thr infinity-thr_iter
+infinity-routines = infinity-map_lwp2thr infinity-thr_iter \
+		    infinity-thr_get_lwpid
 
 libpthread-routines += $(infinity-routines)
 endif
diff --git a/nptl/infinity-thr_get_lwpid.i8 b/nptl/infinity-thr_get_lwpid.i8
new file mode 100644
index 0000000..4755de7
--- /dev/null
+++ b/nptl/infinity-thr_get_lwpid.i8
@@ -0,0 +1,38 @@
+/* Get LWPID of a thread.
+   Copyright (C) 2016 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/>.  */
+
+#include "infinity-nptl.i8"
+
+/* Return the LWPID of this thread.  */
+
+define MODULE_NAME::thr_get_lwpid returns td_err_e, lwpid_t
+	argument pthread_t descr
+
+	dup
+	beq NULL, fake_descriptor
+
+real_descriptor:
+	add PTHREAD_TID_OFFSET
+	deref pid_t
+	load TD_OK
+	return
+
+fake_descriptor:
+	call procservice::getpid
+	load TD_OK
+	return
diff --git a/nptl/tst-infinity-thr_get_lwpid.py b/nptl/tst-infinity-thr_get_lwpid.py
new file mode 100644
index 0000000..150b6d1
--- /dev/null
+++ b/nptl/tst-infinity-thr_get_lwpid.py
@@ -0,0 +1,37 @@
+from i8c.runtime import TestCase
+
+TestCase.import_builtin_constants()
+TestCase.import_constants_from("infinity-nptl-constants.h")
+TestCase.import_constants_from("infinity-nptl_db-constants.h")
+
+class TestThrGetLWPID(TestCase):
+    TESTFUNC = "libpthread::thr_get_lwpid(p)ii"
+    MAIN_PID = 12345
+
+    def setUp(self):
+        self.ps_getpid_called = False
+
+    def call_procservice_getpid(self):
+        """Implementation of procservice::getpid."""
+        self.ps_getpid_called = True
+        return self.MAIN_PID
+
+    def __do_test(self, descr, expect_lwpid):
+        result = self.i8ctx.call(self.TESTFUNC, descr)
+        self.assertEqual(len(result), 2)
+        self.assertEqual(result[0], TD_OK)
+        self.assertEqual(result[1], expect_lwpid)
+
+    def test_faked(self):
+        """Test thr_get_lwpid with a faked descriptor"""
+        self.__do_test(NULL, self.MAIN_PID)
+        self.assertTrue(self.ps_getpid_called)
+
+    def test_real(self):
+        """Test thr_get_lwpid with a real descriptor"""
+        lwpid = self.MAIN_PID - 5
+        with self.memory.builder() as mem:
+            descr = mem.alloc()
+            descr.store_i32(PTHREAD_TID_OFFSET, lwpid)
+        self.__do_test(descr, lwpid)
+        self.assertFalse(self.ps_getpid_called)
-- 
1.7.1

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [RFC v2][PATCH 03/27] Add Infinity THREAD_SELF macros to sysdeps/alpha/nptl/tls.h
  2016-06-13 10:47 [RFC v2][PATCH 00/27] Infinity full-system preview Gary Benson
                   ` (2 preceding siblings ...)
  2016-06-13 10:41 ` [RFC v2][PATCH 26/27] Add Infinity notes implementing libpthread::thr_get_lwpid Gary Benson
@ 2016-06-13 10:41 ` Gary Benson
  2016-06-13 10:41 ` [RFC v2][PATCH 18/27] New gen-as-const-header infinity-thread_self.h Gary Benson
                   ` (22 subsequent siblings)
  26 siblings, 0 replies; 55+ messages in thread
From: Gary Benson @ 2016-06-13 10:41 UTC (permalink / raw)
  To: libc-alpha

This commit adds Infinity THREAD_SELF macros for alpha.
---
 sysdeps/alpha/nptl/tls.h |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/sysdeps/alpha/nptl/tls.h b/sysdeps/alpha/nptl/tls.h
index 90d98e1..33a0ed0 100644
--- a/sysdeps/alpha/nptl/tls.h
+++ b/sysdeps/alpha/nptl/tls.h
@@ -98,9 +98,14 @@ typedef struct
 # define THREAD_SELF \
  ((struct pthread *)__builtin_thread_pointer () - 1)
 
+/* Magic for Infinity to know how to do THREAD_SELF.  */
+# define I8_THREAD_SELF I8_TS_REGISTER
+# define I8_TS_REG_OFFSET 32 * 8
+# define I8_TS_REG_BIAS -sizeof (struct pthread)
+
 /* Magic for libthread_db to know how to do THREAD_SELF.  */
 # define DB_THREAD_SELF \
-  REGISTER (64, 64, 32 * 8, -sizeof (struct pthread))
+  REGISTER (64, 64, I8_TS_REG_OFFSET, I8_TS_REG_BIAS)
 
 /* Access to data in the thread descriptor is easy.  */
 #define THREAD_GETMEM(descr, member) \
-- 
1.7.1

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [RFC v2][PATCH 02/27] Add Infinity THREAD_SELF macros to sysdeps/aarch64/nptl/tls.h
  2016-06-13 10:47 [RFC v2][PATCH 00/27] Infinity full-system preview Gary Benson
  2016-06-13 10:40 ` [RFC v2][PATCH 01/27] Add NT_GNU_INFINITY to elf.h Gary Benson
@ 2016-06-13 10:41 ` Gary Benson
  2016-06-13 10:41 ` [RFC v2][PATCH 26/27] Add Infinity notes implementing libpthread::thr_get_lwpid Gary Benson
                   ` (24 subsequent siblings)
  26 siblings, 0 replies; 55+ messages in thread
From: Gary Benson @ 2016-06-13 10:41 UTC (permalink / raw)
  To: libc-alpha

This commit adds Infinity THREAD_SELF macros for aarch64.
---
 sysdeps/aarch64/nptl/tls.h |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/sysdeps/aarch64/nptl/tls.h b/sysdeps/aarch64/nptl/tls.h
index 95ea3f9..4a8709c 100644
--- a/sysdeps/aarch64/nptl/tls.h
+++ b/sysdeps/aarch64/nptl/tls.h
@@ -104,9 +104,13 @@ typedef struct
 # define THREAD_SELF \
  ((struct pthread *)__builtin_thread_pointer () - 1)
 
+/* Magic for Infinity to know how to do THREAD_SELF.  */
+# define I8_THREAD_SELF I8_TS_CONST_THREAD_AREA
+# define I8_TS_CTA_VALUE sizeof (struct pthread)
+
 /* Magic for libthread_db to know how to do THREAD_SELF.  */
 # define DB_THREAD_SELF \
-  CONST_THREAD_AREA (64, sizeof (struct pthread))
+  CONST_THREAD_AREA (64, I8_TS_CTA_VALUE)
 
 /* Access to data in the thread descriptor is easy.  */
 # define THREAD_GETMEM(descr, member) \
-- 
1.7.1

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [RFC v2][PATCH 18/27] New gen-as-const-header infinity-thread_self.h
  2016-06-13 10:47 [RFC v2][PATCH 00/27] Infinity full-system preview Gary Benson
                   ` (3 preceding siblings ...)
  2016-06-13 10:41 ` [RFC v2][PATCH 03/27] Add Infinity THREAD_SELF macros to sysdeps/alpha/nptl/tls.h Gary Benson
@ 2016-06-13 10:41 ` Gary Benson
  2016-06-13 10:41 ` [RFC v2][PATCH 04/27] Add Infinity THREAD_SELF macros to sysdeps/arm/nptl/tls.h Gary Benson
                   ` (21 subsequent siblings)
  26 siblings, 0 replies; 55+ messages in thread
From: Gary Benson @ 2016-06-13 10:41 UTC (permalink / raw)
  To: libc-alpha

This commit adds a new generated assembler constants header
infinity-thread_self.h, and adds a rule to build it to
sysdeps/generic/Makefile.  sysdeps/$cpu/nptl/tls.h files are
expected to define macros that mirror those defined for
libthread_db.  infinity-thread_self.sym contains various
compile-time checks to ensure a consistent set of Infinity
macros is defined.
---
 sysdeps/generic/Makefile                 |    2 +
 sysdeps/generic/infinity-thread_self.sym |   64 ++++++++++++++++++++++++++++++
 2 files changed, 66 insertions(+), 0 deletions(-)
 create mode 100644 sysdeps/generic/infinity-thread_self.sym

diff --git a/sysdeps/generic/Makefile b/sysdeps/generic/Makefile
index f68ac68..c6a4f57 100644
--- a/sysdeps/generic/Makefile
+++ b/sysdeps/generic/Makefile
@@ -26,3 +26,5 @@ sysdep_routines += framestate unwind-pe
 shared-only-routines += framestate unwind-pe
 endif
 endif
+
+gen-as-const-headers += infinity-thread_self.sym
diff --git a/sysdeps/generic/infinity-thread_self.sym b/sysdeps/generic/infinity-thread_self.sym
new file mode 100644
index 0000000..8e9f47f
--- /dev/null
+++ b/sysdeps/generic/infinity-thread_self.sym
@@ -0,0 +1,64 @@
+#include <tls.h>
+
+-- Each machine's tls.h should define I8_THREAD_SELF to one of these.
+#define I8_TS_CONST_THREAD_AREA         1
+#define I8_TS_REGISTER                  2
+#define I8_TS_REGISTER_THREAD_AREA      3
+
+#ifndef I8_THREAD_SELF
+# error "tls.h must #define I8_THREAD_SELF"
+#endif
+
+-- If tls.h defined DB_THREAD_SELF_INCLUDE then we need to include it.
+#ifdef DB_THREAD_SELF_INCLUDE
+# include DB_THREAD_SELF_INCLUDE
+#endif
+
+#if I8_THREAD_SELF == I8_TS_CONST_THREAD_AREA
+# ifndef I8_TS_CTA_VALUE
+#  error "I8_TS_CONST_THREAD_AREA machines must #define I8_TS_CTA_VALUE"
+# endif
+#else
+# define I8_TS_CTA_VALUE -1
+#endif
+
+#if I8_THREAD_SELF == I8_TS_REGISTER
+# ifndef I8_TS_REG_OFFSET
+#  error "I8_TS_REGISTER machines must #define I8_TS_REG_OFFSET"
+# endif
+# ifndef I8_TS_REG_BIAS
+#  error "I8_TS_REGISTER machines must #define I8_TS_REG_BIAS"
+# endif
+#else
+# define I8_TS_REG_OFFSET -1
+# define I8_TS_REG_BIAS -1
+#endif
+
+#if I8_THREAD_SELF == I8_TS_REGISTER_THREAD_AREA
+# ifndef I8_TS_RTA_OFFSET
+#  error "I8_TS_REGISTER_THREAD_AREA machines must #define I8_TS_RTA_OFFSET"
+# endif
+# ifndef I8_TS_RTA_SCALE
+#  error "I8_TS_REGISTER_THREAD_AREA machines must #define I8_TS_RTA_SCALE"
+# endif
+#else
+# define I8_TS_RTA_OFFSET -1
+# define I8_TS_RTA_SCALE -1
+#endif
+
+
+-- Constants to export
+
+I8_THREAD_SELF
+
+I8_TS_CONST_THREAD_AREA
+I8_TS_REGISTER
+I8_TS_REGISTER_THREAD_AREA
+
+I8_TS_CTA_VALUE
+
+I8_TS_REG_OFFSET
+I8_TS_REG_BIAS
+
+I8_TS_RTA_OFFSET
+I8_TS_RTA_SCALE
-- 
1.7.1

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [RFC v2][PATCH 22/27] Export stack_used as __stack_used
  2016-06-13 10:47 [RFC v2][PATCH 00/27] Infinity full-system preview Gary Benson
                   ` (6 preceding siblings ...)
  2016-06-13 10:41 ` [RFC v2][PATCH 20/27] Add ./configure checks for I8C and I8X Gary Benson
@ 2016-06-13 10:41 ` Gary Benson
  2016-06-13 11:03   ` Pedro Alves
  2016-06-13 10:41 ` [RFC v2][PATCH 25/27] Add Infinity notes implementing libpthread::thr_iter Gary Benson
                   ` (18 subsequent siblings)
  26 siblings, 1 reply; 55+ messages in thread
From: Gary Benson @ 2016-06-13 10:41 UTC (permalink / raw)
  To: libc-alpha

The Infinity note libpthread::thr_iter (broadly equivalent to
libthread_db's td_ta_thr_iter) requires access to both __stack_user
and stack_used, but only the former is visible to it.  This commit
renames "stack_used" as "__stack_used" and changes it from a static
variable in allocatestack.c to an internally exported symbol available
to all nptl source files.
---
 nptl/allocatestack.c      |   33 +++++++++++++++++----------------
 nptl/descr.h              |    2 +-
 nptl/nptl-init.c          |    1 +
 nptl/pthreadP.h           |    2 ++
 nptl/pthread_create.c     |    2 +-
 nptl_db/structs.def       |    2 +-
 nptl_db/td_ta_thr_iter.c  |   15 +++++++++++----
 nptl_db/td_thr_validate.c |    2 +-
 8 files changed, 35 insertions(+), 24 deletions(-)

diff --git a/nptl/allocatestack.c b/nptl/allocatestack.c
index c044b20..d384397 100644
--- a/nptl/allocatestack.c
+++ b/nptl/allocatestack.c
@@ -113,7 +113,8 @@ static int stack_cache_lock = LLL_LOCK_INITIALIZER;
 static LIST_HEAD (stack_cache);
 
 /* List of the stacks in use.  */
-static LIST_HEAD (stack_used);
+list_t (__stack_used) __attribute__ ((nocommon));
+hidden_data_def (__stack_used)
 
 /* We need to record what list operations we are going to do so that,
    in case of an asynchronous interruption due to a fork() call, we
@@ -223,7 +224,7 @@ get_cached_stack (size_t *sizep, void **memp)
   stack_list_del (&result->list);
 
   /* And add to the list of stacks in use.  */
-  stack_list_add (&result->list, &stack_used);
+  stack_list_add (&result->list, &__stack_used);
 
   /* And decrease the cache size.  */
   stack_cache_actsize -= result->stackblock_size;
@@ -592,7 +593,7 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp,
 	  lll_lock (stack_cache_lock, LLL_PRIVATE);
 
 	  /* And add to the list of stacks in use.  */
-	  stack_list_add (&pd->list, &stack_used);
+	  stack_list_add (&pd->list, &__stack_used);
 
 	  lll_unlock (stack_cache_lock, LLL_PRIVATE);
 
@@ -781,7 +782,7 @@ __make_stacks_executable (void **stack_endp)
   lll_lock (stack_cache_lock, LLL_PRIVATE);
 
   list_t *runp;
-  list_for_each (runp, &stack_used)
+  list_for_each (runp, &__stack_used)
     {
       err = change_stack_perm (list_entry (runp, struct pthread, list)
 #ifdef NEED_SEPARATE_REGISTER_STACK
@@ -838,8 +839,8 @@ __reclaim_stacks (void)
 	     pointers at the head of the list are inconsistent.  */
 	  list_t *l = NULL;
 
-	  if (stack_used.next->prev != &stack_used)
-	    l = &stack_used;
+	  if (__stack_used.next->prev != &__stack_used)
+	    l = &__stack_used;
 	  else if (stack_cache.next->prev != &stack_cache)
 	    l = &stack_cache;
 
@@ -861,7 +862,7 @@ __reclaim_stacks (void)
 
   /* Mark all stacks except the still running one as free.  */
   list_t *runp;
-  list_for_each (runp, &stack_used)
+  list_for_each (runp, &__stack_used)
     {
       struct pthread *curp = list_entry (runp, struct pthread, list);
       if (curp != self)
@@ -905,7 +906,7 @@ __reclaim_stacks (void)
     }
 
   /* Add the stack of all running threads to the cache.  */
-  list_splice (&stack_used, &stack_cache);
+  list_splice (&__stack_used, &stack_cache);
 
   /* Remove the entry for the current thread to from the cache list
      and add it to the list of running threads.  Which of the two
@@ -913,13 +914,13 @@ __reclaim_stacks (void)
   stack_list_del (&self->list);
 
   /* Re-initialize the lists for all the threads.  */
-  INIT_LIST_HEAD (&stack_used);
+  INIT_LIST_HEAD (&__stack_used);
   INIT_LIST_HEAD (&__stack_user);
 
   if (__glibc_unlikely (THREAD_GETMEM (self, user_stack)))
     list_add (&self->list, &__stack_user);
   else
-    list_add (&self->list, &stack_used);
+    list_add (&self->list, &__stack_used);
 
   /* There is one thread running.  */
   __nptl_nthreads = 1;
@@ -945,7 +946,7 @@ __find_thread_by_id (pid_t tid)
 
   /* Iterate over the list with system-allocated threads first.  */
   list_t *runp;
-  list_for_each (runp, &stack_used)
+  list_for_each (runp, &__stack_used)
     {
       struct pthread *curp;
 
@@ -1098,7 +1099,7 @@ __nptl_setxid (struct xid_command *cmdp)
 
   /* Iterate over the list with system-allocated threads first.  */
   list_t *runp;
-  list_for_each (runp, &stack_used)
+  list_for_each (runp, &__stack_used)
     {
       struct pthread *t = list_entry (runp, struct pthread, list);
       if (t == self)
@@ -1124,7 +1125,7 @@ __nptl_setxid (struct xid_command *cmdp)
     {
       signalled = 0;
 
-      list_for_each (runp, &stack_used)
+      list_for_each (runp, &__stack_used)
 	{
 	  struct pthread *t = list_entry (runp, struct pthread, list);
 	  if (t == self)
@@ -1154,7 +1155,7 @@ __nptl_setxid (struct xid_command *cmdp)
 
   /* Clean up flags, so that no thread blocks during exit waiting
      for a signal which will never come.  */
-  list_for_each (runp, &stack_used)
+  list_for_each (runp, &__stack_used)
     {
       struct pthread *t = list_entry (runp, struct pthread, list);
       if (t == self)
@@ -1218,7 +1219,7 @@ __pthread_init_static_tls (struct link_map *map)
 
   /* Iterate over the list with system-allocated threads first.  */
   list_t *runp;
-  list_for_each (runp, &stack_used)
+  list_for_each (runp, &__stack_used)
     init_one_static_tls (list_entry (runp, struct pthread, list), map);
 
   /* Now the list with threads using user-allocated stacks.  */
@@ -1239,7 +1240,7 @@ __wait_lookup_done (void)
 
   /* Iterate over the list with system-allocated threads first.  */
   list_t *runp;
-  list_for_each (runp, &stack_used)
+  list_for_each (runp, &__stack_used)
     {
       struct pthread *t = list_entry (runp, struct pthread, list);
       if (t == self || t->header.gscope_flag == THREAD_GSCOPE_FLAG_UNUSED)
diff --git a/nptl/descr.h b/nptl/descr.h
index 8e4938d..87c5354 100644
--- a/nptl/descr.h
+++ b/nptl/descr.h
@@ -160,7 +160,7 @@ struct pthread
     void *__padding[24];
   };
 
-  /* This descriptor's link on the `stack_used' or `__stack_user' list.  */
+  /* This descriptor's link on the `__stack_used' or `__stack_user' list.  */
   list_t list;
 
   /* Thread ID - which is also a 'is this thread descriptor (and
diff --git a/nptl/nptl-init.c b/nptl/nptl-init.c
index bdbdfed..9bde618 100644
--- a/nptl/nptl-init.c
+++ b/nptl/nptl-init.c
@@ -384,6 +384,7 @@ __pthread_initialize_minimal_internal (void)
   THREAD_SETMEM (pd, stackblock_size, (size_t) __libc_stack_end);
 
   /* Initialize the list of all running threads with the main thread.  */
+  INIT_LIST_HEAD (&__stack_used);
   INIT_LIST_HEAD (&__stack_user);
   list_add (&pd->list, &__stack_user);
 
diff --git a/nptl/pthreadP.h b/nptl/pthreadP.h
index 4edc74b..e762f94 100644
--- a/nptl/pthreadP.h
+++ b/nptl/pthreadP.h
@@ -183,7 +183,9 @@ extern int __is_smp attribute_hidden;
 
 /* Thread descriptor handling.  */
 extern list_t __stack_user;
+extern list_t __stack_used;
 hidden_proto (__stack_user)
+hidden_proto (__stack_used)
 
 /* Attribute handling.  */
 extern struct pthread_attr *__attr_list attribute_hidden;
diff --git a/nptl/pthread_create.c b/nptl/pthread_create.c
index 5216041..ec49b15 100644
--- a/nptl/pthread_create.c
+++ b/nptl/pthread_create.c
@@ -87,7 +87,7 @@ __find_in_stack_list (struct pthread *pd)
 
   lll_lock (stack_cache_lock, LLL_PRIVATE);
 
-  list_for_each (entry, &stack_used)
+  list_for_each (entry, &__stack_used)
     {
       struct pthread *curp;
 
diff --git a/nptl_db/structs.def b/nptl_db/structs.def
index a9b621b..ebcc065 100644
--- a/nptl_db/structs.def
+++ b/nptl_db/structs.def
@@ -70,7 +70,7 @@ DB_STRUCT (td_eventbuf_t)
 DB_STRUCT_FIELD (td_eventbuf_t, eventnum)
 DB_STRUCT_FIELD (td_eventbuf_t, eventdata)
 
-DB_SYMBOL (stack_used)
+DB_SYMBOL (__stack_used)
 DB_SYMBOL (__stack_user)
 DB_SYMBOL (nptl_version)
 DB_FUNCTION (__nptl_create_event)
diff --git a/nptl_db/td_ta_thr_iter.c b/nptl_db/td_ta_thr_iter.c
index a990fed..aae4dd2 100644
--- a/nptl_db/td_ta_thr_iter.c
+++ b/nptl_db/td_ta_thr_iter.c
@@ -38,15 +38,22 @@ iterate_thread_list (td_thragent_t *ta, td_thr_iter_f *callback,
   if (err != TD_OK)
     return err;
 
-  if (next == 0 && fake_empty)
+  if (next == 0)
     {
       /* __pthread_initialize_minimal has not run.  There is just the main
 	 thread to return.  We cannot rely on its thread register.  They
 	 sometimes contain garbage that would confuse us, left by the
 	 kernel at exec.  So if it looks like initialization is incomplete,
 	 we only fake a special descriptor for the initial thread.  */
-      td_thrhandle_t th = { ta, 0 };
-      return callback (&th, cbdata_p) != 0 ? TD_DBERR : TD_OK;
+      if (fake_empty)
+	{
+	  td_thrhandle_t th = { ta, 0 };
+
+	  if (callback (&th, cbdata_p) != 0)
+	    return TD_DBERR;
+	}
+
+      return TD_OK;
     }
 
   /* Cache the offset from struct pthread to its list_t member.  */
@@ -161,7 +168,7 @@ td_ta_thr_iter (const td_thragent_t *ta_arg, td_thr_iter_f *callback,
 
   /* And the threads with stacks allocated by the implementation.  */
   if (err == TD_OK)
-    err = DB_GET_SYMBOL (list, ta, stack_used);
+    err = DB_GET_SYMBOL (list, ta, __stack_used);
   if (err == TD_OK)
     err = iterate_thread_list (ta, callback, cbdata_p, state, ti_pri,
 			       list, false, pid);
diff --git a/nptl_db/td_thr_validate.c b/nptl_db/td_thr_validate.c
index f3c8a7b..34b6112 100644
--- a/nptl_db/td_thr_validate.c
+++ b/nptl_db/td_thr_validate.c
@@ -70,7 +70,7 @@ td_thr_validate (const td_thrhandle_t *th)
      using implementation allocated stacks.  */
   if (err == TD_NOTHR)
     {
-      err = DB_GET_SYMBOL (list, th->th_ta_p, stack_used);
+      err = DB_GET_SYMBOL (list, th->th_ta_p, __stack_used);
       if (err == TD_OK)
 	err = check_thread_list (th, list, &uninit);
 
-- 
1.7.1

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [RFC v2][PATCH 14/27] Add Infinity THREAD_SELF macros to sysdeps/sh/nptl/tls.h
  2016-06-13 10:47 [RFC v2][PATCH 00/27] Infinity full-system preview Gary Benson
                   ` (9 preceding siblings ...)
  2016-06-13 10:47 ` [RFC v2][PATCH 15/27] Add Infinity THREAD_SELF macros to sysdeps/sparc/nptl/tls.h Gary Benson
@ 2016-06-13 10:47 ` Gary Benson
  2016-06-13 10:47 ` [RFC v2][PATCH 17/27] Add Infinity THREAD_SELF macros to sysdeps/x86_64/nptl/tls.h Gary Benson
                   ` (15 subsequent siblings)
  26 siblings, 0 replies; 55+ messages in thread
From: Gary Benson @ 2016-06-13 10:47 UTC (permalink / raw)
  To: libc-alpha

This commit adds Infinity THREAD_SELF macros for sh.
---
 sysdeps/sh/nptl/tls.h |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/sysdeps/sh/nptl/tls.h b/sysdeps/sh/nptl/tls.h
index 6f128c9..ac427c8 100644
--- a/sysdeps/sh/nptl/tls.h
+++ b/sysdeps/sh/nptl/tls.h
@@ -119,9 +119,14 @@ typedef struct
      __asm ("stc gbr,%0" : "=r" (__self));				      \
      __self - 1;})
 
+/* Magic for Infinity to know how to do THREAD_SELF.  */
+# define I8_THREAD_SELF I8_TS_REGISTER
+# define I8_TS_REG_OFFSET REG_GBR * 4
+# define I8_TS_REG_BIAS -sizeof (struct pthread)
+
 /* Magic for libthread_db to know how to do THREAD_SELF.  */
 # define DB_THREAD_SELF \
-  REGISTER (32, 32, REG_GBR * 4, -sizeof (struct pthread))
+  REGISTER (32, 32, I8_TS_REG_OFFSET, I8_TS_REG_BIAS)
 
 /* Read member of the thread descriptor directly.  */
 # define THREAD_GETMEM(descr, member) (descr->member)
-- 
1.7.1

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [RFC v2][PATCH 11/27] Add Infinity THREAD_SELF macros to sysdeps/nios2/nptl/tls.h
  2016-06-13 10:47 [RFC v2][PATCH 00/27] Infinity full-system preview Gary Benson
                   ` (12 preceding siblings ...)
  2016-06-13 10:47 ` [RFC v2][PATCH 07/27] Add Infinity THREAD_SELF macros to sysdeps/ia64/nptl/tls.h Gary Benson
@ 2016-06-13 10:47 ` Gary Benson
  2016-06-13 10:48 ` [RFC v2][PATCH 10/27] Add Infinity THREAD_SELF macros to sysdeps/mips/nptl/tls.h Gary Benson
                   ` (12 subsequent siblings)
  26 siblings, 0 replies; 55+ messages in thread
From: Gary Benson @ 2016-06-13 10:47 UTC (permalink / raw)
  To: libc-alpha

This commit adds Infinity THREAD_SELF macros for nios2.
---
 sysdeps/nios2/nptl/tls.h |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/sysdeps/nios2/nptl/tls.h b/sysdeps/nios2/nptl/tls.h
index ad29ac5..1f9fb69 100644
--- a/sysdeps/nios2/nptl/tls.h
+++ b/sysdeps/nios2/nptl/tls.h
@@ -118,9 +118,14 @@ register struct pthread *__thread_self __asm__("r23");
  ((struct pthread *) (READ_THREAD_POINTER ()			     \
 		      - TLS_TCB_OFFSET - TLS_PRE_TCB_SIZE))
 
+/* Magic for Infinity to know how to do THREAD_SELF.  */
+# define I8_THREAD_SELF I8_TS_REGISTER
+# define I8_TS_REG_OFFSET 23 * 4
+# define I8_TS_REG_BIAS -TLS_PRE_TCB_SIZE - TLS_TCB_OFFSET
+
 /* Magic for libthread_db to know how to do THREAD_SELF.  */
 # define DB_THREAD_SELF \
-  REGISTER (32, 32, 23 * 4, -TLS_PRE_TCB_SIZE - TLS_TCB_OFFSET)
+  REGISTER (32, 32, I8_TS_REG_OFFSET, I8_TS_REG_BIAS)
 
 /* Access to data in the thread descriptor is easy.  */
 # define THREAD_GETMEM(descr, member) \
-- 
1.7.1

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [RFC v2][PATCH 07/27] Add Infinity THREAD_SELF macros to sysdeps/ia64/nptl/tls.h
  2016-06-13 10:47 [RFC v2][PATCH 00/27] Infinity full-system preview Gary Benson
                   ` (11 preceding siblings ...)
  2016-06-13 10:47 ` [RFC v2][PATCH 17/27] Add Infinity THREAD_SELF macros to sysdeps/x86_64/nptl/tls.h Gary Benson
@ 2016-06-13 10:47 ` Gary Benson
  2016-06-13 10:47 ` [RFC v2][PATCH 11/27] Add Infinity THREAD_SELF macros to sysdeps/nios2/nptl/tls.h Gary Benson
                   ` (13 subsequent siblings)
  26 siblings, 0 replies; 55+ messages in thread
From: Gary Benson @ 2016-06-13 10:47 UTC (permalink / raw)
  To: libc-alpha

This commit adds Infinity THREAD_SELF macros for ia64.
---
 sysdeps/ia64/nptl/tls.h |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/sysdeps/ia64/nptl/tls.h b/sysdeps/ia64/nptl/tls.h
index 54fddf5..044b7bf 100644
--- a/sysdeps/ia64/nptl/tls.h
+++ b/sysdeps/ia64/nptl/tls.h
@@ -137,8 +137,14 @@ register struct pthread *__thread_self __asm__("r13");
 # define THREAD_SELF \
   ((struct pthread *) ((char *) __thread_self - TLS_PRE_TCB_SIZE))
 
+/* Magic for Infinity to know how to do THREAD_SELF.  */
+# define I8_THREAD_SELF I8_TS_REGISTER
+# define I8_TS_REG_OFFSET 13 * 8
+# define I8_TS_REG_BIAS -TLS_PRE_TCB_SIZE
+
 /* Magic for libthread_db to know how to do THREAD_SELF.  */
-# define DB_THREAD_SELF REGISTER (64, 64, 13 * 8, -TLS_PRE_TCB_SIZE)
+# define DB_THREAD_SELF \
+  REGISTER (64, 64, I8_TS_REG_OFFSET, I8_TS_REG_BIAS)
 
 /* Access to data in the thread descriptor is easy.  */
 #define THREAD_GETMEM(descr, member) \
-- 
1.7.1

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [RFC v2][PATCH 00/27] Infinity full-system preview
@ 2016-06-13 10:47 Gary Benson
  2016-06-13 10:40 ` [RFC v2][PATCH 01/27] Add NT_GNU_INFINITY to elf.h Gary Benson
                   ` (26 more replies)
  0 siblings, 27 replies; 55+ messages in thread
From: Gary Benson @ 2016-06-13 10:47 UTC (permalink / raw)
  To: libc-alpha

Hi all,

I'm working on a platform-independent system for executables and
shared libraries to expose functionality to debug, monitoring, and
analysis tooling.  It's called Infinity.   It grew from a need for
GDB to be able to debug multithreaded inferiors without requiring
libthread_db, but it's suitable for other systems that need to expose
internals to debuggers such as the run-time linker (e.g. for dlmopen
support) and OpenMP.

Rather than requiring a plugin library that the debugger loads, in
Infinity debug functions are shipped as DWARF bytecode in ELF notes
in the actual library they are for, so, e.g., the notes implementing
what libthread_db.so currently implements live in libpthread.so.

This series is version 2 of a series I posted back in October:

  https://sourceware.org/ml/libc-alpha/2015-10/msg00690.html

The main difference is that the October series was build-only: there
was no way to execute the notes it built into libpthread.so.  This
series comes with the ability to try thread-debugging with the notes
using unmodified GDB.  Instructions here:

  https://infinitynotes.org/wiki/First_Flight

Most of the patches in this series are there to support the last few,
and are fairly uninteresting.  If you'd like to look in detail at this
series I'd suggest starting at patch 20:

 [PATCH 20/27] Add ./configure checks for I8C and I8X

   This patch adds configure checks for I8C (the Infinity note
   compiler) and I8X (the Infinity note testing framework).  This
   patch differs from the previous version as follows:

     * There is now a --with-infinity option.  If specified, configure
       will fail if I8C and I8X are not present or too old.  If
       --without-infinity is specified then no checks will be
       performed.  If neither is specified then --with-infinity will
       be assumed if I8C is found on the build system.

     * Minimum versions of I8C and I8X are listed in
       manual/install.texi and INSTALL.

 [PATCH 21/27] Add Makerules to build %.o and %.os from %.i8

   This patch adds make rules to build %.o and %.os files from %.i8
   Infinity note source code.  This patch differs from the previous
   version as follows:

     * Some no-longer-necessary rules have been removed.

     * "-include sysdep.h" is passed to I8C to ensure the correct
       assembler directives for ARM are included.

 [PATCH 22/27] Export stack_used as __stack_used

   This patch was not in the previous series.  It exports stack_used
   internally as __stack_used in the same way __stack_user is exported
   to makes it visible to the libpthread::thr_iter note function.

 [PATCH 24/27] Add Infinity notes implementing libpthread::map_lwp2thr
 [PATCH 25/27] Add Infinity notes implementing libpthread::thr_iter
 [PATCH 26/27] Add Infinity notes implementing libpthread::thr_get_lwpid
 [PATCH 27/27] Add Infinity notes implementing libpthread::thr_get_state

   These patches add the source code for 4 Infinity functions.  They
   also add test cases for those functions.

This series isn't complete.  With it GDB can attach to processes (and
load core files) and do "info threads", but two more libthread_db
functions need implementing as notes before GDB will be able to do
everything without libthread_db.  These are the two TLS accessors
td_thr_tlsbase and td_thr_tls_get_addr.

The current set of notes adds 880 bytes to libpthread.so on x86_64.
I anticipate the TLS functions adding as much again, so I'm expecting
the final overhead to be about 1.7k, some of which will be in the
runtime linker.  Please note that Infinity notes are NOT mapped into
memory.

I'm expecting the final version of this series to look pretty much as
this version does, but with ChangeLogs and with two extra patches for
the TLS accessors.

Infinity's mailing list is infinity@sourceware.org, so please
subscribe if you're interested by sending an empty message to
infinity-subsribe@.

Thanks,
Gary

--
http://gbenson.net/

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [RFC v2][PATCH 17/27] Add Infinity THREAD_SELF macros to sysdeps/x86_64/nptl/tls.h
  2016-06-13 10:47 [RFC v2][PATCH 00/27] Infinity full-system preview Gary Benson
                   ` (10 preceding siblings ...)
  2016-06-13 10:47 ` [RFC v2][PATCH 14/27] Add Infinity THREAD_SELF macros to sysdeps/sh/nptl/tls.h Gary Benson
@ 2016-06-13 10:47 ` Gary Benson
  2016-06-13 10:47 ` [RFC v2][PATCH 07/27] Add Infinity THREAD_SELF macros to sysdeps/ia64/nptl/tls.h Gary Benson
                   ` (14 subsequent siblings)
  26 siblings, 0 replies; 55+ messages in thread
From: Gary Benson @ 2016-06-13 10:47 UTC (permalink / raw)
  To: libc-alpha

This commit adds Infinity THREAD_SELF macros for x86_64.
---
 sysdeps/x86_64/nptl/tls.h |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/sysdeps/x86_64/nptl/tls.h b/sysdeps/x86_64/nptl/tls.h
index 2b061a0..08a087d 100644
--- a/sysdeps/x86_64/nptl/tls.h
+++ b/sysdeps/x86_64/nptl/tls.h
@@ -186,9 +186,13 @@ typedef struct
 	  : "i" (offsetof (struct pthread, header.self)));	 	      \
      __self;})
 
+/* Magic for Infinity to know how to do THREAD_SELF.  */
+# define I8_THREAD_SELF I8_TS_CONST_THREAD_AREA
+# define I8_TS_CTA_VALUE FS
+
 /* Magic for libthread_db to know how to do THREAD_SELF.  */
 # define DB_THREAD_SELF_INCLUDE  <sys/reg.h> /* For the FS constant.  */
-# define DB_THREAD_SELF CONST_THREAD_AREA (64, FS)
+# define DB_THREAD_SELF CONST_THREAD_AREA (64, I8_TS_CTA_VALUE)
 
 /* Read member of the thread descriptor directly.  */
 # define THREAD_GETMEM(descr, member) \
-- 
1.7.1

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [RFC v2][PATCH 15/27] Add Infinity THREAD_SELF macros to sysdeps/sparc/nptl/tls.h
  2016-06-13 10:47 [RFC v2][PATCH 00/27] Infinity full-system preview Gary Benson
                   ` (8 preceding siblings ...)
  2016-06-13 10:41 ` [RFC v2][PATCH 25/27] Add Infinity notes implementing libpthread::thr_iter Gary Benson
@ 2016-06-13 10:47 ` Gary Benson
  2016-06-13 11:51   ` Andreas Schwab
  2016-06-13 10:47 ` [RFC v2][PATCH 14/27] Add Infinity THREAD_SELF macros to sysdeps/sh/nptl/tls.h Gary Benson
                   ` (16 subsequent siblings)
  26 siblings, 1 reply; 55+ messages in thread
From: Gary Benson @ 2016-06-13 10:47 UTC (permalink / raw)
  To: libc-alpha

This commit adds Infinity THREAD_SELF macros for sparc.
---
 sysdeps/sparc/nptl/tls.h |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/sysdeps/sparc/nptl/tls.h b/sysdeps/sparc/nptl/tls.h
index 08c0552..d8a24b6 100644
--- a/sysdeps/sparc/nptl/tls.h
+++ b/sysdeps/sparc/nptl/tls.h
@@ -125,6 +125,15 @@ register struct pthread *__thread_self __asm__("%g7");
   REGISTER (32, 32, 10 * 4, 0) \
   REGISTER (64, __WORDSIZE, (6 * 8) + (__WORDSIZE==64?0:4), 0)
 
+/* Magic for Infinity to know how to do THREAD_SELF.  */
+# define I8_THREAD_SELF I8_TS_REGISTER
+# if __WORDSIZE == 32
+#  define I8_TS_REG_OFFSET 10 * 4
+# else
+#  define I8_TS_REG_OFFSET (6 * 8) + (__WORDSIZE==64?0:4)
+# endif
+# define I8_TS_REG_BIAS 0
+
 /* Access to data in the thread descriptor is easy.  */
 #define THREAD_GETMEM(descr, member) \
   descr->member
-- 
1.7.1

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [RFC v2][PATCH 16/27] Add Infinity THREAD_SELF macros to sysdeps/tile/nptl/tls.h
  2016-06-13 10:47 [RFC v2][PATCH 00/27] Infinity full-system preview Gary Benson
                   ` (17 preceding siblings ...)
  2016-06-13 10:48 ` [RFC v2][PATCH 13/27] Add Infinity THREAD_SELF macros to sysdeps/s390/nptl/tls.h Gary Benson
@ 2016-06-13 10:48 ` Gary Benson
  2016-06-13 10:57 ` [RFC v2][PATCH 05/27] Add Infinity THREAD_SELF macros to sysdeps/hppa/nptl/tls.h Gary Benson
                   ` (7 subsequent siblings)
  26 siblings, 0 replies; 55+ messages in thread
From: Gary Benson @ 2016-06-13 10:48 UTC (permalink / raw)
  To: libc-alpha

This commit adds Infinity THREAD_SELF macros for tile.
---
 sysdeps/tile/nptl/tls.h |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/sysdeps/tile/nptl/tls.h b/sysdeps/tile/nptl/tls.h
index c908fb8..c98761b 100644
--- a/sysdeps/tile/nptl/tls.h
+++ b/sysdeps/tile/nptl/tls.h
@@ -122,13 +122,18 @@ register void *__thread_pointer asm ("tp");
     ((struct pthread *) (__thread_pointer \
 			 - TLS_TCB_OFFSET - TLS_PRE_TCB_SIZE))
 
+/* Magic for Infinity to know how to do THREAD_SELF.  */
+# define I8_THREAD_SELF I8_TS_REGISTER
+# define I8_TS_REG_OFFSET REG_TP * sizeof (void *)
+# define I8_TS_REG_BIAS -(TLS_TCB_OFFSET + TLS_PRE_TCB_SIZE)
+
 /* Magic for libthread_db to know how to do THREAD_SELF.  */
 #ifdef __tilegx__
 # define DB_THREAD_SELF \
-  REGISTER (64, 64, REG_TP * 8, - TLS_TCB_OFFSET - TLS_PRE_TCB_SIZE)
+  REGISTER (64, 64, REG_TP * 8, I8_TS_REG_BIAS)
 #else
 # define DB_THREAD_SELF \
-  REGISTER (32, 32, REG_TP * 4, - TLS_TCB_OFFSET - TLS_PRE_TCB_SIZE)
+  REGISTER (32, 32, REG_TP * 4, I8_TS_REG_BIAS)
 #endif
 
 /* Read member of the thread descriptor directly.  */
-- 
1.7.1

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [RFC v2][PATCH 13/27] Add Infinity THREAD_SELF macros to sysdeps/s390/nptl/tls.h
  2016-06-13 10:47 [RFC v2][PATCH 00/27] Infinity full-system preview Gary Benson
                   ` (16 preceding siblings ...)
  2016-06-13 10:48 ` [RFC v2][PATCH 06/27] Add Infinity THREAD_SELF macros to sysdeps/i386/nptl/tls.h Gary Benson
@ 2016-06-13 10:48 ` Gary Benson
  2016-06-13 10:48 ` [RFC v2][PATCH 16/27] Add Infinity THREAD_SELF macros to sysdeps/tile/nptl/tls.h Gary Benson
                   ` (8 subsequent siblings)
  26 siblings, 0 replies; 55+ messages in thread
From: Gary Benson @ 2016-06-13 10:48 UTC (permalink / raw)
  To: libc-alpha

This commit adds Infinity THREAD_SELF macros for s390.
---
 sysdeps/s390/nptl/tls.h |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/sysdeps/s390/nptl/tls.h b/sysdeps/s390/nptl/tls.h
index e4c3ec7..d27a01e 100644
--- a/sysdeps/s390/nptl/tls.h
+++ b/sysdeps/s390/nptl/tls.h
@@ -147,9 +147,15 @@ typedef struct
 /* Return the thread descriptor for the current thread.  */
 # define THREAD_SELF ((struct pthread *) __builtin_thread_pointer ())
 
+/* Magic for Infinity to know how to do THREAD_SELF.  */
+# define I8_THREAD_SELF I8_TS_REGISTER
+# define I8_TS_REG_OFFSET 18 * sizeof (void *)
+# define I8_TS_REG_BIAS 0
+
 /* Magic for libthread_db to know how to do THREAD_SELF.  */
-# define DB_THREAD_SELF REGISTER (32, 32, 18 * 4, 0) \
-			REGISTER (64, __WORDSIZE, 18 * 8, 0)
+# define DB_THREAD_SELF \
+  REGISTER (32, 32, 18 * 4, I8_TS_REG_BIAS)				      \
+  REGISTER (64, __WORDSIZE, 18 * 8, I8_TS_REG_BIAS)
 
 /* Access to data in the thread descriptor is easy.  */
 #define THREAD_GETMEM(descr, member) \
-- 
1.7.1

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [RFC v2][PATCH 06/27] Add Infinity THREAD_SELF macros to sysdeps/i386/nptl/tls.h
  2016-06-13 10:47 [RFC v2][PATCH 00/27] Infinity full-system preview Gary Benson
                   ` (15 preceding siblings ...)
  2016-06-13 10:48 ` [RFC v2][PATCH 23/27] New Infinity header infinity-nptl.i8 Gary Benson
@ 2016-06-13 10:48 ` Gary Benson
  2016-06-13 10:48 ` [RFC v2][PATCH 13/27] Add Infinity THREAD_SELF macros to sysdeps/s390/nptl/tls.h Gary Benson
                   ` (9 subsequent siblings)
  26 siblings, 0 replies; 55+ messages in thread
From: Gary Benson @ 2016-06-13 10:48 UTC (permalink / raw)
  To: libc-alpha

This commit adds Infinity THREAD_SELF macros for i386.
---
 sysdeps/i386/nptl/tls.h |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/sysdeps/i386/nptl/tls.h b/sysdeps/i386/nptl/tls.h
index a6dfa9b..f504ef2 100644
--- a/sysdeps/i386/nptl/tls.h
+++ b/sysdeps/i386/nptl/tls.h
@@ -259,6 +259,14 @@ tls_fill_user_desc (union user_desc_init *desc,
   REGISTER_THREAD_AREA (32, offsetof (struct user_regs_struct, xgs), 3) \
   REGISTER_THREAD_AREA (64, 26 * 8, 3) /* x86-64's user_regs_struct->gs */
 
+/* Magic for Infinity to know how to do THREAD_SELF.  */
+# define I8_THREAD_SELF I8_TS_REGISTER_THREAD_AREA
+# ifdef __LP64__
+#  define I8_TS_RTA_OFFSET 26 * 8 /* x86-64's user_regs_struct->gs */
+# else
+#  define I8_TS_RTA_OFFSET offsetof (struct user_regs_struct, xgs)
+# endif
+# define I8_TS_RTA_SCALE 3
 
 /* Read member of the thread descriptor directly.  */
 # define THREAD_GETMEM(descr, member) \
-- 
1.7.1

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [RFC v2][PATCH 23/27] New Infinity header infinity-nptl.i8
  2016-06-13 10:47 [RFC v2][PATCH 00/27] Infinity full-system preview Gary Benson
                   ` (14 preceding siblings ...)
  2016-06-13 10:48 ` [RFC v2][PATCH 10/27] Add Infinity THREAD_SELF macros to sysdeps/mips/nptl/tls.h Gary Benson
@ 2016-06-13 10:48 ` Gary Benson
  2016-06-13 10:48 ` [RFC v2][PATCH 06/27] Add Infinity THREAD_SELF macros to sysdeps/i386/nptl/tls.h Gary Benson
                   ` (10 subsequent siblings)
  26 siblings, 0 replies; 55+ messages in thread
From: Gary Benson @ 2016-06-13 10:48 UTC (permalink / raw)
  To: libc-alpha

This commit adds the new Infinity header infinity-nptl.i8, which
contains definitions common to all libpthread Infinity notes.
---
 nptl/infinity-nptl.i8 |   58 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 58 insertions(+), 0 deletions(-)
 create mode 100644 nptl/infinity-nptl.i8

diff --git a/nptl/infinity-nptl.i8 b/nptl/infinity-nptl.i8
new file mode 100644
index 0000000..1ca320c
--- /dev/null
+++ b/nptl/infinity-nptl.i8
@@ -0,0 +1,58 @@
+/* Common definitions for NPTL Infinity functions.
+   Copyright (C) 2015-2016 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/>.  */
+
+/* libpthread and libthread_db generated constants.  */
+#include "infinity-nptl-constants.h"
+#include "infinity-nptl_db-constants.h"
+
+/* Wordsize of the platform, in bits.  */
+wordsize __WORDSIZE
+
+/* Process and LWP IDs.  */
+typedef i32 __pid_t
+typedef __pid_t pid_t
+typedef __pid_t lwpid_t
+
+/* Error codes defined in thread_db.h and proc_service.h.  */
+typedef i32 td_err_e
+typedef i32 ps_err_e
+
+/* A pointer to a struct pthread.  */
+typedef ptr pthread_t
+
+/* Possible thread states.  */
+typedef i32 td_thr_state_e
+
+/* Callback for iteration over threads.  */
+typedef func int (pthread_t, opaque) thr_iter_f
+
+/* The two thread lists.  */
+extern ptr __stack_user
+extern ptr __stack_used
+
+/* Return the PID of the process being accessed.  */
+extern func pid_t () procservice::getpid
+
+/* Fetch the value stored in the specified register of the given LWP.
+   The "int" parameter specifies an offset in bytes into prgregset_t.  */
+extern func ps_err_e, int (lwpid_t, int) procservice::get_register
+
+/* Fetch the special per-thread address associated with the given
+   LWP.  This call is not available on all platforms.  The meaning
+   of the "int" parameter is machine-dependent. */
+extern func ps_err_e, ptr (lwpid_t, int) procservice::get_thread_area
-- 
1.7.1

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [RFC v2][PATCH 10/27] Add Infinity THREAD_SELF macros to sysdeps/mips/nptl/tls.h
  2016-06-13 10:47 [RFC v2][PATCH 00/27] Infinity full-system preview Gary Benson
                   ` (13 preceding siblings ...)
  2016-06-13 10:47 ` [RFC v2][PATCH 11/27] Add Infinity THREAD_SELF macros to sysdeps/nios2/nptl/tls.h Gary Benson
@ 2016-06-13 10:48 ` Gary Benson
  2016-06-13 11:12   ` Pedro Alves
  2016-06-13 10:48 ` [RFC v2][PATCH 23/27] New Infinity header infinity-nptl.i8 Gary Benson
                   ` (11 subsequent siblings)
  26 siblings, 1 reply; 55+ messages in thread
From: Gary Benson @ 2016-06-13 10:48 UTC (permalink / raw)
  To: libc-alpha

This commit adds Infinity THREAD_SELF macros for mips.
---
 sysdeps/mips/nptl/tls.h |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/sysdeps/mips/nptl/tls.h b/sysdeps/mips/nptl/tls.h
index 10ca878..90d469c 100644
--- a/sysdeps/mips/nptl/tls.h
+++ b/sysdeps/mips/nptl/tls.h
@@ -149,9 +149,13 @@ typedef struct
  ((struct pthread *) (READ_THREAD_POINTER ()			     \
 		      - TLS_TCB_OFFSET - TLS_PRE_TCB_SIZE))
 
+/* Magic for Infinity to know how to do THREAD_SELF.  */
+# define I8_THREAD_SELF I8_TS_CONST_THREAD_AREA
+# define I8_TS_CTA_VALUE TLS_TCB_OFFSET + TLS_PRE_TCB_SIZE
+
 /* Magic for libthread_db to know how to do THREAD_SELF.  */
 # define DB_THREAD_SELF \
-  CONST_THREAD_AREA (32, TLS_TCB_OFFSET + TLS_PRE_TCB_SIZE)
+  CONST_THREAD_AREA (32, I8_TS_CTA_VALUE)
 
 /* Access to data in the thread descriptor is easy.  */
 # define THREAD_GETMEM(descr, member) \
-- 
1.7.1

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [RFC v2][PATCH 05/27] Add Infinity THREAD_SELF macros to sysdeps/hppa/nptl/tls.h
  2016-06-13 10:47 [RFC v2][PATCH 00/27] Infinity full-system preview Gary Benson
                   ` (18 preceding siblings ...)
  2016-06-13 10:48 ` [RFC v2][PATCH 16/27] Add Infinity THREAD_SELF macros to sysdeps/tile/nptl/tls.h Gary Benson
@ 2016-06-13 10:57 ` Gary Benson
  2016-06-13 10:57 ` [RFC v2][PATCH 09/27] Add Infinity THREAD_SELF macros to sysdeps/microblaze/nptl/tls.h Gary Benson
                   ` (6 subsequent siblings)
  26 siblings, 0 replies; 55+ messages in thread
From: Gary Benson @ 2016-06-13 10:57 UTC (permalink / raw)
  To: libc-alpha

This commit adds Infinity THREAD_SELF macros for hppa.
---
 sysdeps/hppa/nptl/tls.h |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/sysdeps/hppa/nptl/tls.h b/sysdeps/hppa/nptl/tls.h
index 2e0c861..2ed0ef1 100644
--- a/sysdeps/hppa/nptl/tls.h
+++ b/sysdeps/hppa/nptl/tls.h
@@ -111,11 +111,16 @@ typedef struct
 	__self - 1;				\
    })
 
-/* Magic for libthread_db to know how to do THREAD_SELF.
+/* Magic for Infinity to know how to do THREAD_SELF.
    Our thread pointer is stored in cr27.  See asm/elf.h for the offset into
    elf_gregset_t.  The thread descriptor is sizeof (struct pthread) away.  */
+# define I8_THREAD_SELF I8_TS_REGISTER
+# define I8_TS_REG_OFFSET 53 * 4
+# define I8_TS_REG_BIAS -sizeof (struct pthread)
+
+/* Magic for libthread_db to know how to do THREAD_SELF.  */
 # define DB_THREAD_SELF \
-  REGISTER (32, 32, 53 * 4, -sizeof (struct pthread))
+  REGISTER (32, 32, I8_TS_REG_OFFSET, I8_TS_REG_BIAS)
 
 /* Access to data in the thread descriptor is easy.  */
 # define THREAD_GETMEM(descr, member) \
-- 
1.7.1

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [RFC v2][PATCH 09/27] Add Infinity THREAD_SELF macros to sysdeps/microblaze/nptl/tls.h
  2016-06-13 10:47 [RFC v2][PATCH 00/27] Infinity full-system preview Gary Benson
                   ` (19 preceding siblings ...)
  2016-06-13 10:57 ` [RFC v2][PATCH 05/27] Add Infinity THREAD_SELF macros to sysdeps/hppa/nptl/tls.h Gary Benson
@ 2016-06-13 10:57 ` Gary Benson
  2016-06-13 10:58 ` [RFC v2][PATCH 27/27] Add Infinity notes implementing libpthread::thr_get_state Gary Benson
                   ` (5 subsequent siblings)
  26 siblings, 0 replies; 55+ messages in thread
From: Gary Benson @ 2016-06-13 10:57 UTC (permalink / raw)
  To: libc-alpha

This commit adds Infinity THREAD_SELF macros for microblaze.
---
 sysdeps/microblaze/nptl/tls.h |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/sysdeps/microblaze/nptl/tls.h b/sysdeps/microblaze/nptl/tls.h
index 8376f50..4127ba2 100644
--- a/sysdeps/microblaze/nptl/tls.h
+++ b/sysdeps/microblaze/nptl/tls.h
@@ -106,9 +106,13 @@ typedef struct
 # define THREAD_SELF \
   (((struct pthread *) READ_THREAD_POINTER()) - 1)
 
+/* Magic for Infinity to know how to do THREAD_SELF.  */
+# define I8_THREAD_SELF I8_TS_CONST_THREAD_AREA
+# define I8_TS_CTA_VALUE sizeof (struct pthread)
+
 /* Magic for libthread_db to know how to do THREAD_SELF.  */
 # define DB_THREAD_SELF \
-  CONST_THREAD_AREA (32, sizeof (struct pthread))
+  CONST_THREAD_AREA (32, I8_TS_CTA_VALUE)
 
 /* Read member of the thread descriptor directly.  */
 # define THREAD_GETMEM(descr, member) (descr->member)
-- 
1.7.1

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [RFC v2][PATCH 21/27] Add Makerules to build %.o and %.os from %.i8
  2016-06-13 10:47 [RFC v2][PATCH 00/27] Infinity full-system preview Gary Benson
                   ` (23 preceding siblings ...)
  2016-06-13 10:58 ` [RFC v2][PATCH 12/27] Add Infinity THREAD_SELF macros to sysdeps/powerpc/nptl/tls.h Gary Benson
@ 2016-06-13 10:58 ` Gary Benson
  2016-06-13 11:18 ` [RFC v2][PATCH 19/27] New gen-as-const-headers infinity-nptl{,_db}-constants.h Gary Benson
  2016-06-13 11:18 ` [RFC v2][PATCH 24/27] Add Infinity notes implementing libpthread::map_lwp2thr Gary Benson
  26 siblings, 0 replies; 55+ messages in thread
From: Gary Benson @ 2016-06-13 10:58 UTC (permalink / raw)
  To: libc-alpha

This commit adds make rules to build %.o and %.os files from %.i8
Infinity note source code.

In order to ensure the correct preprocessor and assembler are used
for cross-builds the compilation is done in three stages.  The target
preprocessor specified at ./configure time is used to preprocess the
%.i8 source; I8C consumes this preprocessed source and emits assembly
language; and finally the target assembler specified at ./configure
time is used to assemble the generated assembly language into object
code.

This patch differs from the previous version
<https://sourceware.org/ml/libc-alpha/2015-10/msg00705.html>
in the following ways:

 * The infinity-%.S => infinity-%.o and infinity-%.os rules are
   no longer necessary and have been removed.

 * "-include sysdep.h" is passed to I8C to ensure the correct
   assembler directives for ARM are included.
---
 Makerules |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/Makerules b/Makerules
index 53eabfa..cf74228 100644
--- a/Makerules
+++ b/Makerules
@@ -1539,6 +1539,14 @@ $(gpl2lgpl): %: $(..)gpl2lgpl.sed /home/gd/gnu/lib/%
 	mv -f $@-tmp $@
 endif
 endif
+\f
+$(objpfx)infinity-%.i8p: infinity-%.i8
+	$(CPP) -x c $(CFLAGS) $(CPPFLAGS) $^ -o $@
+
+$(objpfx)infinity-%.S: $(objpfx)infinity-%.i8p
+	$(I8C) -S -fpreprocessed -include sysdep.h $^ -o $@
+
+.PRECIOUS: $(addprefix $(objpfx)infinity-%,.i8p .S .o)
 
 # Local Variables:
 # mode: makefile
-- 
1.7.1

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [RFC v2][PATCH 27/27] Add Infinity notes implementing libpthread::thr_get_state
  2016-06-13 10:47 [RFC v2][PATCH 00/27] Infinity full-system preview Gary Benson
                   ` (20 preceding siblings ...)
  2016-06-13 10:57 ` [RFC v2][PATCH 09/27] Add Infinity THREAD_SELF macros to sysdeps/microblaze/nptl/tls.h Gary Benson
@ 2016-06-13 10:58 ` Gary Benson
  2016-06-13 10:58 ` [RFC v2][PATCH 08/27] Add Infinity THREAD_SELF macros to sysdeps/m68k/nptl/tls.h Gary Benson
                   ` (4 subsequent siblings)
  26 siblings, 0 replies; 55+ messages in thread
From: Gary Benson @ 2016-06-13 10:58 UTC (permalink / raw)
  To: libc-alpha

This commit adds the Infinity function libpthread::thr_get_state.
It has no libthread_db equivalent (in libthread_db the state of
a thread is read from the ti_state field of the td_thrinfo_t that
td_thr_get_info fills in).
---
 nptl/Makefile                      |    2 +-
 nptl/infinity-thr_get_state.i8     |   58 ++++++++++++++++++++++++++++++++++++
 nptl/tst-infinity-thr_get_state.py |   38 +++++++++++++++++++++++
 3 files changed, 97 insertions(+), 1 deletions(-)
 create mode 100644 nptl/infinity-thr_get_state.i8
 create mode 100644 nptl/tst-infinity-thr_get_state.py

diff --git a/nptl/Makefile b/nptl/Makefile
index bdfe656..1c10798 100644
--- a/nptl/Makefile
+++ b/nptl/Makefile
@@ -140,7 +140,7 @@ libpthread-routines = nptl-init vars events version pt-interp \
 
 ifeq ($(build-infinity),yes)
 infinity-routines = infinity-map_lwp2thr infinity-thr_iter \
-		    infinity-thr_get_lwpid
+		    infinity-thr_get_lwpid infinity-thr_get_state
 
 libpthread-routines += $(infinity-routines)
 endif
diff --git a/nptl/infinity-thr_get_state.i8 b/nptl/infinity-thr_get_state.i8
new file mode 100644
index 0000000..74b140d
--- /dev/null
+++ b/nptl/infinity-thr_get_state.i8
@@ -0,0 +1,58 @@
+/* Get the state of a thread.
+   Copyright (C) 2016 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/>.  */
+
+#include "infinity-nptl.i8"
+
+/* Return the state of a thread.  */
+
+define MODULE_NAME::thr_get_state returns td_err_e, td_thr_state_e
+	argument pthread_t descr
+
+	dup
+	beq NULL, fake_descriptor
+
+real_descriptor:
+	add PTHREAD_CANCELHANDLING_OFFSET
+	deref i32
+	goto got_value
+
+fake_descriptor:
+	drop  /* descr.  */
+	load 0
+	goto got_value
+
+got_value:
+	dup
+	and EXITING_BITMASK
+	bne 0, thread_exiting
+  /* XXX For now there is no way to get more information.  */
+	load TD_THR_ACTIVE
+	load TD_OK
+	return
+
+thread_exiting:
+	and TERMINATED_BITMASK
+	bne 0, thread_terminated
+	load TD_THR_UNKNOWN
+	load TD_OK
+	return
+
+thread_terminated:
+	load TD_THR_ZOMBIE
+	load TD_OK
+	return
diff --git a/nptl/tst-infinity-thr_get_state.py b/nptl/tst-infinity-thr_get_state.py
new file mode 100644
index 0000000..2ba3ab6
--- /dev/null
+++ b/nptl/tst-infinity-thr_get_state.py
@@ -0,0 +1,38 @@
+from i8c.runtime import TestCase
+
+TestCase.import_builtin_constants()
+TestCase.import_constants_from("infinity-nptl-constants.h")
+TestCase.import_constants_from("infinity-nptl_db-constants.h")
+
+class TestThrGetState(TestCase):
+    TESTFUNC = "libpthread::thr_get_state(p)ii"
+
+    def __do_test(self, descr, expect_state):
+        result = self.i8ctx.call(self.TESTFUNC, descr)
+        self.assertEqual(len(result), 2)
+        self.assertEqual(result[0], TD_OK)
+        self.assertEqual(result[1], expect_state)
+
+    def test_faked(self):
+        """Test thr_get_state with a faked descriptor"""
+        self.__do_test(NULL, TD_THR_ACTIVE)
+
+    def __do_test_real(self, cancelhandling, expect_state):
+        with self.memory.builder() as mem:
+            descr = mem.alloc()
+            descr.store_i32(PTHREAD_CANCELHANDLING_OFFSET,
+                            cancelhandling)
+        self.__do_test(descr, expect_state)
+
+    def test_active(self):
+        """Test thr_get_state with an active thread"""
+        self.__do_test_real(0, TD_THR_ACTIVE)
+
+    def test_exiting(self):
+        """Test thr_get_state with an exiting thread"""
+        self.__do_test_real(EXITING_BITMASK, TD_THR_UNKNOWN)
+
+    def test_exited(self):
+        """Test thr_get_state with an exited thread"""
+        self.__do_test_real(EXITING_BITMASK | TERMINATED_BITMASK,
+                            TD_THR_ZOMBIE)
-- 
1.7.1

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [RFC v2][PATCH 08/27] Add Infinity THREAD_SELF macros to sysdeps/m68k/nptl/tls.h
  2016-06-13 10:47 [RFC v2][PATCH 00/27] Infinity full-system preview Gary Benson
                   ` (21 preceding siblings ...)
  2016-06-13 10:58 ` [RFC v2][PATCH 27/27] Add Infinity notes implementing libpthread::thr_get_state Gary Benson
@ 2016-06-13 10:58 ` Gary Benson
  2016-06-13 10:58 ` [RFC v2][PATCH 12/27] Add Infinity THREAD_SELF macros to sysdeps/powerpc/nptl/tls.h Gary Benson
                   ` (3 subsequent siblings)
  26 siblings, 0 replies; 55+ messages in thread
From: Gary Benson @ 2016-06-13 10:58 UTC (permalink / raw)
  To: libc-alpha

This commit adds Infinity THREAD_SELF macros for m68k.
---
 sysdeps/m68k/nptl/tls.h |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/sysdeps/m68k/nptl/tls.h b/sysdeps/m68k/nptl/tls.h
index f932282..f5df7dd 100644
--- a/sysdeps/m68k/nptl/tls.h
+++ b/sysdeps/m68k/nptl/tls.h
@@ -125,9 +125,13 @@ extern void * __m68k_read_tp (void);
 # define THREAD_SELF \
   ((struct pthread *) (__m68k_read_tp () - TLS_TCB_OFFSET - TLS_PRE_TCB_SIZE))
 
+/* Magic for Infinity to know how to do THREAD_SELF.  */
+# define I8_THREAD_SELF I8_TS_CONST_THREAD_AREA
+# define I8_TS_CTA_VALUE TLS_TCB_OFFSET + TLS_PRE_TCB_SIZE
+
 /* Magic for libthread_db to know how to do THREAD_SELF.  */
 # define DB_THREAD_SELF \
-  CONST_THREAD_AREA (32, TLS_TCB_OFFSET + TLS_PRE_TCB_SIZE)
+  CONST_THREAD_AREA (32, I8_TS_CTA_VALUE)
 
 /* Access to data in the thread descriptor is easy.  */
 # define THREAD_GETMEM(descr, member) \
-- 
1.7.1

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [RFC v2][PATCH 12/27] Add Infinity THREAD_SELF macros to sysdeps/powerpc/nptl/tls.h
  2016-06-13 10:47 [RFC v2][PATCH 00/27] Infinity full-system preview Gary Benson
                   ` (22 preceding siblings ...)
  2016-06-13 10:58 ` [RFC v2][PATCH 08/27] Add Infinity THREAD_SELF macros to sysdeps/m68k/nptl/tls.h Gary Benson
@ 2016-06-13 10:58 ` Gary Benson
  2016-06-13 10:58 ` [RFC v2][PATCH 21/27] Add Makerules to build %.o and %.os from %.i8 Gary Benson
                   ` (2 subsequent siblings)
  26 siblings, 0 replies; 55+ messages in thread
From: Gary Benson @ 2016-06-13 10:58 UTC (permalink / raw)
  To: libc-alpha

This commit adds Infinity THREAD_SELF macros for powerpc.
---
 sysdeps/powerpc/nptl/tls.h |   11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/sysdeps/powerpc/nptl/tls.h b/sysdeps/powerpc/nptl/tls.h
index 0e889bc..67b8a55 100644
--- a/sysdeps/powerpc/nptl/tls.h
+++ b/sysdeps/powerpc/nptl/tls.h
@@ -177,12 +177,15 @@ register void *__thread_register __asm__ ("r13");
     ((struct pthread *) (__thread_register \
 			 - TLS_TCB_OFFSET - TLS_PRE_TCB_SIZE))
 
+/* Magic for Infinity to know how to do THREAD_SELF.  */
+# define I8_THREAD_SELF I8_TS_REGISTER
+# define I8_TS_REG_OFFSET PT_THREAD_POINTER * sizeof (void *)
+# define I8_TS_REG_BIAS -(TLS_TCB_OFFSET + TLS_PRE_TCB_SIZE)
+
 /* Magic for libthread_db to know how to do THREAD_SELF.  */
 # define DB_THREAD_SELF							      \
-  REGISTER (32, 32, PT_THREAD_POINTER * 4,				      \
-	    - TLS_TCB_OFFSET - TLS_PRE_TCB_SIZE)			      \
-  REGISTER (64, 64, PT_THREAD_POINTER * 8,				      \
-	    - TLS_TCB_OFFSET - TLS_PRE_TCB_SIZE)
+  REGISTER (32, 32, PT_THREAD_POINTER * 4, I8_TS_REG_BIAS)		      \
+  REGISTER (64, 64, PT_THREAD_POINTER * 8, I8_TS_REG_BIAS)
 
 /* Read member of the thread descriptor directly.  */
 # define THREAD_GETMEM(descr, member) ((void)(descr), (THREAD_SELF)->member)
-- 
1.7.1

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [RFC v2][PATCH 22/27] Export stack_used as __stack_used
  2016-06-13 10:41 ` [RFC v2][PATCH 22/27] Export stack_used as __stack_used Gary Benson
@ 2016-06-13 11:03   ` Pedro Alves
  2016-06-13 11:20     ` Gary Benson
  0 siblings, 1 reply; 55+ messages in thread
From: Pedro Alves @ 2016-06-13 11:03 UTC (permalink / raw)
  To: Gary Benson, libc-alpha

On 06/13/2016 11:38 AM, Gary Benson wrote:
> The Infinity note libpthread::thr_iter (broadly equivalent to
> libthread_db's td_ta_thr_iter) requires access to both __stack_user
> and stack_used, but only the former is visible to it.  This commit
> renames "stack_used" as "__stack_used" and changes it from a static
> variable in allocatestack.c to an internally exported symbol available
> to all nptl source files.

This rename alone should fix glibc PR 17629 (and thus GDB PR 9635).

 [put all symbols nptl_db looks up in the private namespace]
 https://sourceware.org/bugzilla/show_bug.cgi?id=17629

Thus I think it'd be reasonable (and good) to split the renaming part
of this patch out of the series, and get it into the tree.  I
think it could go in quickly.

BTW, the td_ta_thr_iter.c::iterate_thread_list hunk looks
like just a code style change unrelated to the subject of
the patch.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [RFC v2][PATCH 10/27] Add Infinity THREAD_SELF macros to sysdeps/mips/nptl/tls.h
  2016-06-13 10:48 ` [RFC v2][PATCH 10/27] Add Infinity THREAD_SELF macros to sysdeps/mips/nptl/tls.h Gary Benson
@ 2016-06-13 11:12   ` Pedro Alves
  2016-06-15 15:23     ` Gary Benson
  0 siblings, 1 reply; 55+ messages in thread
From: Pedro Alves @ 2016-06-13 11:12 UTC (permalink / raw)
  To: Gary Benson, libc-alpha

On 06/13/2016 11:38 AM, Gary Benson wrote:
> +/* Magic for Infinity to know how to do THREAD_SELF.  */
> +# define I8_THREAD_SELF I8_TS_CONST_THREAD_AREA
> +# define I8_TS_CTA_VALUE TLS_TCB_OFFSET + TLS_PRE_TCB_SIZE
> +

Wrap in parentheses to avoid precedence problems creeping in
in future:

# define I8_TS_CTA_VALUE (TLS_TCB_OFFSET + TLS_PRE_TCB_SIZE)

etc.

More instances throughout the series.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [RFC v2][PATCH 24/27] Add Infinity notes implementing libpthread::map_lwp2thr
  2016-06-13 10:47 [RFC v2][PATCH 00/27] Infinity full-system preview Gary Benson
                   ` (25 preceding siblings ...)
  2016-06-13 11:18 ` [RFC v2][PATCH 19/27] New gen-as-const-headers infinity-nptl{,_db}-constants.h Gary Benson
@ 2016-06-13 11:18 ` Gary Benson
  26 siblings, 0 replies; 55+ messages in thread
From: Gary Benson @ 2016-06-13 11:18 UTC (permalink / raw)
  To: libc-alpha

This commit adds the Infinity function libpthread::map_lwp2thr,
the Infinity equivalent of libthread_db's td_ta_map_lwp2thr.
---
 nptl/Makefile                         |   20 +++++
 nptl/infinity-lookup_th_unique_cta.i8 |   39 +++++++++
 nptl/infinity-lookup_th_unique_reg.i8 |   41 +++++++++
 nptl/infinity-lookup_th_unique_rta.i8 |   50 +++++++++++
 nptl/infinity-map_lwp2thr.i8          |   71 +++++++++++++++
 nptl/tst-infinity-map_lwp2thr.py      |  152 +++++++++++++++++++++++++++++++++
 6 files changed, 373 insertions(+), 0 deletions(-)
 create mode 100644 nptl/infinity-lookup_th_unique_cta.i8
 create mode 100644 nptl/infinity-lookup_th_unique_reg.i8
 create mode 100644 nptl/infinity-lookup_th_unique_rta.i8
 create mode 100644 nptl/infinity-map_lwp2thr.i8
 create mode 100644 nptl/tst-infinity-map_lwp2thr.py

diff --git a/nptl/Makefile b/nptl/Makefile
index 63976ec..9beb879 100644
--- a/nptl/Makefile
+++ b/nptl/Makefile
@@ -138,6 +138,12 @@ libpthread-routines = nptl-init vars events version pt-interp \
 #		      pthread_setgid pthread_setegid pthread_setregid \
 #		      pthread_setresgid
 
+ifeq ($(build-infinity),yes)
+infinity-routines = infinity-map_lwp2thr
+
+libpthread-routines += $(infinity-routines)
+endif
+
 libpthread-shared-only-routines = version pt-interp pt-allocrtsig \
 				  unwind-forcedunwind
 libpthread-static-only-routines = pthread_atfork
@@ -413,6 +419,20 @@ ifneq ($(have-cxx-thread_local),yes)
 tests-unsupported += tst-thread_local1
 endif
 
+tests += tst-infinity
+ifeq ($(build-infinity),yes)
+infinity-tests = $(addprefix tst-,$(addsuffix .py,$(infinity-routines)))
+
+$(objpfx)tst-infinity.out: $(objpfx)libpthread.so$(libpthread.so-version) \
+			   $(infinity-tests)
+	$(I8X) -i $< -I$(common-objpfx) $(infinity-tests) > $@; \
+	$(evaluate-test)
+
+tests-special += $(objpfx)tst-infinity.out
+else
+tests-unsupported += tst-infinity
+endif
+
 include ../Rules
 
 ifeq (yes,$(build-shared))
diff --git a/nptl/infinity-lookup_th_unique_cta.i8 b/nptl/infinity-lookup_th_unique_cta.i8
new file mode 100644
index 0000000..2c9879b
--- /dev/null
+++ b/nptl/infinity-lookup_th_unique_cta.i8
@@ -0,0 +1,39 @@
+/* Which thread is running on an LWP?
+   Copyright (C) 2003-2016 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/>.  */
+
+
+/* Given an lwpid_t identifying an LWP, return TD_OK and the
+   descriptor of the thread running on it, or a non-TD_OK
+   td_err_e code indicating the reason for failure and an
+   undefined value that must be ignored.  The caller must
+   ensure that __pthread_initialize_minimal has gotten far
+   enough; see the comments in infinity_map_lwp2thr.i8 for
+   specifics.  */
+
+define MODULE_NAME::__lookup_th_unique returns td_err_e, pthread_t
+	argument lwpid_t lwpid
+
+	load I8_TS_CTA_VALUE
+	call procservice::get_thread_area
+	bne PS_OK, get_thread_area_failed
+	load TD_OK
+	return
+
+get_thread_area_failed:
+	load TD_ERR
+	return
diff --git a/nptl/infinity-lookup_th_unique_reg.i8 b/nptl/infinity-lookup_th_unique_reg.i8
new file mode 100644
index 0000000..399308e
--- /dev/null
+++ b/nptl/infinity-lookup_th_unique_reg.i8
@@ -0,0 +1,41 @@
+/* Which thread is running on an LWP?
+   Copyright (C) 2003-2016 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/>.  */
+
+
+/* Given an lwpid_t identifying an LWP, return TD_OK and the
+   descriptor of the thread running on it, or a non-TD_OK
+   td_err_e code indicating the reason for failure and an
+   undefined value that must be ignored.  The caller must
+   ensure that __pthread_initialize_minimal has gotten far
+   enough; see the comments in infinity_map_lwp2thr.i8 for
+   specifics.  */
+
+define MODULE_NAME::__lookup_th_unique returns td_err_e, pthread_t
+	argument lwpid_t lwpid
+
+	load I8_TS_REG_OFFSET
+	call procservice::get_register
+	cast 1, ptr
+	bne PS_OK, get_register_failed
+	add I8_TS_REG_BIAS
+	load TD_OK
+	return
+
+get_register_failed:
+	load TD_ERR
+	return
diff --git a/nptl/infinity-lookup_th_unique_rta.i8 b/nptl/infinity-lookup_th_unique_rta.i8
new file mode 100644
index 0000000..c1d0ecc
--- /dev/null
+++ b/nptl/infinity-lookup_th_unique_rta.i8
@@ -0,0 +1,50 @@
+/* Which thread is running on an LWP?
+   Copyright (C) 2003-2016 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/>.  */
+
+
+/* Given an lwpid_t identifying an LWP, return TD_OK and the
+   descriptor of the thread running on it, or a non-TD_OK
+   td_err_e code indicating the reason for failure and an
+   undefined value that must be ignored.  The caller must
+   ensure that __pthread_initialize_minimal has gotten far
+   enough; see the comments in infinity_map_lwp2thr.i8 for
+   specifics.  */
+
+define MODULE_NAME::__lookup_th_unique returns td_err_e, pthread_t
+	argument lwpid_t lwpid
+
+	load lwpid
+	load I8_TS_RTA_OFFSET
+	call procservice::get_register
+	bne PS_OK, get_register_failed
+
+	shr I8_TS_RTA_SCALE
+	call procservice::get_thread_area
+	bne PS_OK, get_thread_area_failed
+
+	load TD_OK
+	return
+
+get_register_failed:
+	cast 0, ptr
+	load TD_ERR
+	return
+
+get_thread_area_failed:
+	load TD_ERR
+	return
diff --git a/nptl/infinity-map_lwp2thr.i8 b/nptl/infinity-map_lwp2thr.i8
new file mode 100644
index 0000000..4b33d72
--- /dev/null
+++ b/nptl/infinity-map_lwp2thr.i8
@@ -0,0 +1,71 @@
+/* Which thread is running on an LWP?
+   Copyright (C) 2003-2016 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/>.  */
+
+#include "infinity-nptl.i8"
+#include "infinity-thread_self.h"
+
+#if I8_THREAD_SELF == I8_TS_CONST_THREAD_AREA
+# include "infinity-lookup_th_unique_cta.i8"
+#endif
+#if I8_THREAD_SELF == I8_TS_REGISTER
+# include "infinity-lookup_th_unique_reg.i8"
+#endif
+#if I8_THREAD_SELF == I8_TS_REGISTER_THREAD_AREA
+# include "infinity-lookup_th_unique_rta.i8"
+#endif
+
+/* Given an lwpid_t identifying an LWP, return TD_OK and the
+   descriptor of the thread running on it, or a non-TD_OK
+   td_err_e code indicating the reason for failure and an
+   undefined value that must be ignored.  Thread descriptors
+   are opaque pointers and should not be dereferenced outside
+   of this library.  */
+
+define MODULE_NAME::map_lwp2thr returns td_err_e, pthread_t
+	argument lwpid_t lwpid
+
+  /* We cannot rely on thread registers and such information at all
+     before __pthread_initialize_minimal has gotten far enough: they
+     sometimes contain garbage left by the kernel at exec that would
+     confuse us.  If it looks like initialization is incomplete we
+     fake a special descriptor of NULL to indicate the initial thread.
+     Other routines in this library recognise this special descriptor
+     and act accordingly.  */
+	deref LIST_T_NEXT_OFFSET(__stack_user), ptr
+	beq NULL, libpthread_uninitialized
+	call __lookup_th_unique
+	return
+
+libpthread_uninitialized:
+
+  /* Load the pointer we'll return beneath lwpid.  I8C can't yet
+     hoist, but it'll optimize the branch away if we do the hoist
+     ourselves.  */
+	load NULL
+	swap
+
+	call procservice::getpid
+	beq is_main_thread
+
+not_main_thread:
+	load TD_ERR
+	return
+
+is_main_thread:
+	load TD_OK
+	return
diff --git a/nptl/tst-infinity-map_lwp2thr.py b/nptl/tst-infinity-map_lwp2thr.py
new file mode 100644
index 0000000..37989be
--- /dev/null
+++ b/nptl/tst-infinity-map_lwp2thr.py
@@ -0,0 +1,152 @@
+from i8c.runtime import TestCase
+import struct
+
+TestCase.import_builtin_constants()
+TestCase.import_constants_from("infinity-nptl-constants.h")
+TestCase.import_constants_from("infinity-nptl_db-constants.h")
+
+class TestMapLwp2Thr(TestCase):
+    TESTFUNC = "libpthread::map_lwp2thr(i)ip"
+    MAIN_PID = 30000
+
+    def setUp(self):
+        # Set up the test address space for the __stack_user.next
+        # dereference.
+        with self.memory.builder() as mem:
+            stack_user = mem.alloc("__stack_user")
+            if self.STACK_USER_SETUP:
+                stack_user_next = mem.alloc()
+            else:
+                stack_user_next = NULL
+            stack_user.store_ptr(LIST_T_NEXT_OFFSET, stack_user_next)
+        # Initialize flags so we can see what was called.
+        self.ps_get_register_called = False
+        self.ps_get_thread_area_called = False
+
+    def call_procservice_getpid(self):
+        """Implementation of procservice::getpid."""
+        return self.MAIN_PID
+
+    def call_procservice_get_register(self, lwpid, offset):
+        """Implementation of procservice::get_register."""
+        self.assertFalse(self.ps_get_register_called)
+        result = getattr(self, "PS_GETREG_RESULT", None)
+        if result is None:
+            self.fail("unexpected ps_get_register")
+        self.assertEqual(lwpid, self.lwpid)
+        self.assertNotEqual(offset, self.lwpid)
+        self.assertGreaterEqual(offset, 0)
+        # We can't really say much about offset.  It's an offset into
+        # a prgregset_t structure, so it's probably not huge and it's
+        # probably aligned to the machine's wordsize.
+        self.assertLess(offset, 128 * 8) # =128 64-bit registers (IA-64)
+        bytes_per_word, check = divmod(self.i8ctx.wordsize, 8)
+        self.assertNotEqual(bytes_per_word, 0)
+        self.assertEqual(check, 0)
+        self.assertEqual(offset % bytes_per_word, 0)
+        self.ps_get_register_called = True
+        return result
+
+    def call_procservice_get_thread_area(self, lwpid, idx):
+        """Implementation of procservice::get_thread_area."""
+        self.assertFalse(self.ps_get_thread_area_called)
+        result = getattr(self, "PS_GET_TA_RESULT", None)
+        if result is None:
+            self.fail("unexpected ps_get_thread_area")
+        self.assertEqual(lwpid, self.lwpid)
+        self.assertNotEqual(idx, self.lwpid)
+        self.ps_get_thread_area_called = True
+        return result
+
+    def check_I8_TS_CONST_THREAD_AREA_result(self, result):
+        # The result is whatever ps_get_thread_area returned.
+        self.assertTrue(self.ps_get_thread_area_called)
+        self.assertEqual(result[0], TD_OK)
+        self.assertNotEqual(result[1], 0)
+        self.assertEqual(result[1], self.PS_GET_TA_RESULT[1])
+
+    def check_I8_TS_REGISTER_result(self, result):
+        # The result is what ps_get_register returned with some
+        # bias added.  We'll assume the bias is fairly small.
+        self.assertTrue(self.ps_get_register_called)
+        self.assertEqual(result[0], TD_OK)
+        self.assertNotEqual(result[1], 0)
+        bias = result[1] - self.PS_GETREG_RESULT[1]
+        self.assertLess(abs(bias), 0x10000)
+
+    def check_I8_TS_REGISTER_THREAD_AREA_result(self, result):
+        # The result is whatever ps_get_thread_area returned.
+        self.assertTrue(self.ps_get_register_called)
+        self.assertTrue(self.ps_get_thread_area_called)
+        self.assertEqual(result[0], TD_OK)
+        self.assertNotEqual(result[1], 0)
+        self.assertEqual(result[1], self.PS_GET_TA_RESULT[1])
+
+class TestMapLwp2Thr_uninit(TestMapLwp2Thr):
+    STACK_USER_SETUP = False
+
+    def test_uninit(self):
+        """Test map_lwp2thr with NPTL uninitialized"""
+        result = self.i8ctx.call(self.TESTFUNC, self.MAIN_PID)
+        self.assertEqual(len(result), 2)
+        self.assertEqual(result[0], TD_OK)
+        self.assertEqual(result[1], NULL)
+
+class TestMapLwp2Thr_uninit_wrongpid(TestMapLwp2Thr):
+    STACK_USER_SETUP = False
+
+    def test_uninit_wrongpid(self):
+        """Test map_lwp2thr with NPTL uninitialized and lwpid != main pid"""
+        result = self.i8ctx.call(self.TESTFUNC, self.MAIN_PID + 1)
+        self.assertEqual(len(result), 2)
+        self.assertEqual(result[0], TD_ERR)
+
+class TestMapLwp2Thr_getreg_fail(TestMapLwp2Thr):
+    STACK_USER_SETUP = True
+    PS_GETREG_RESULT = PS_ERR, 0x23ff00fa
+    PS_GET_TA_RESULT = PS_OK, 0x89ab1234
+
+    def test_ps_getreg_fail(self):
+        """Check map_lwp2thr handles ps_get_register failures"""
+        self.lwpid = self.MAIN_PID + 1
+        result = self.i8ctx.call(self.TESTFUNC, self.lwpid)
+        self.assertEqual(len(result), 2)
+        if self.ps_get_register_called:
+            self.assertEqual(result[0], TD_ERR)
+        else:
+            # This failure isn't a problem for this platform.
+            self.check_I8_TS_CONST_THREAD_AREA_result(result)
+
+class TestMapLwp2Thr_gta_fail(TestMapLwp2Thr):
+    STACK_USER_SETUP = True
+    PS_GETREG_RESULT = PS_OK, 0x23ff00fa
+    PS_GET_TA_RESULT = PS_ERR, 0x89ab1234
+
+    def test_ps_gta_fail(self):
+        """Check map_lwp2thr handles ps_get_thread_area failures"""
+        self.lwpid = self.MAIN_PID + 1
+        result = self.i8ctx.call(self.TESTFUNC, self.lwpid)
+        self.assertEqual(len(result), 2)
+        if self.ps_get_thread_area_called:
+            self.assertEqual(result[0], TD_ERR)
+        else:
+            # This failure isn't a problem for this platform.
+            self.check_I8_TS_REGISTER_result(result)
+
+class TestMapLwp2Thr_mainpath(TestMapLwp2Thr):
+    STACK_USER_SETUP = True
+    PS_GETREG_RESULT = PS_OK, 0x23ff00fa
+    PS_GET_TA_RESULT = PS_OK, 0x89ab1234
+
+    def test_mainpath(self):
+        """Test the main path through map_lwp2thr"""
+        self.lwpid = self.MAIN_PID + 1
+        result = self.i8ctx.call(self.TESTFUNC, self.lwpid)
+        self.assertEqual(len(result), 2)
+        if self.ps_get_thread_area_called:
+            if self.ps_get_register_called:
+                self.check_I8_TS_REGISTER_THREAD_AREA_result(result)
+            else:
+                self.check_I8_TS_CONST_THREAD_AREA_result(result)
+        else:
+            self.check_I8_TS_REGISTER_result(result)
-- 
1.7.1

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [RFC v2][PATCH 19/27] New gen-as-const-headers infinity-nptl{,_db}-constants.h
  2016-06-13 10:47 [RFC v2][PATCH 00/27] Infinity full-system preview Gary Benson
                   ` (24 preceding siblings ...)
  2016-06-13 10:58 ` [RFC v2][PATCH 21/27] Add Makerules to build %.o and %.os from %.i8 Gary Benson
@ 2016-06-13 11:18 ` Gary Benson
  2016-06-13 11:18 ` [RFC v2][PATCH 24/27] Add Infinity notes implementing libpthread::map_lwp2thr Gary Benson
  26 siblings, 0 replies; 55+ messages in thread
From: Gary Benson @ 2016-06-13 11:18 UTC (permalink / raw)
  To: libc-alpha

This commit adds two new generated assembler constants headers to
export constants used while building libpthread.so and
libthread_db.so.  It also adds a rule to build them to nptl/Makefile.

I would prefer to have infinity-nptl_db-constants.sym in nptl_db
and have it built by nptl_db/Makefile but the ordering of the build
seems to make this impossible: nptl_db needs to be built after nptl,
but infinity-nptl_db-constants.h is required to build the infinity
notes for libpthread.so.  If it's possible to change this then I
will.  In the meantime I had to add breadcrumb header files for
nptl_db's proc_service.h and thread_db.h for use during the build.
---
 include/proc_service.h              |    1 +
 include/thread_db.h                 |    1 +
 nptl/Makefile                       |    4 +++-
 nptl/infinity-nptl-constants.sym    |   26 ++++++++++++++++++++++++++
 nptl/infinity-nptl_db-constants.sym |   24 ++++++++++++++++++++++++
 5 files changed, 55 insertions(+), 1 deletions(-)
 create mode 100644 include/proc_service.h
 create mode 100644 include/thread_db.h
 create mode 100644 nptl/infinity-nptl-constants.sym
 create mode 100644 nptl/infinity-nptl_db-constants.sym

diff --git a/include/proc_service.h b/include/proc_service.h
new file mode 100644
index 0000000..325082e
--- /dev/null
+++ b/include/proc_service.h
@@ -0,0 +1 @@
+#include <nptl_db/proc_service.h>
diff --git a/include/thread_db.h b/include/thread_db.h
new file mode 100644
index 0000000..518d79e
--- /dev/null
+++ b/include/thread_db.h
@@ -0,0 +1 @@
+#include <nptl_db/thread_db.h>
diff --git a/nptl/Makefile b/nptl/Makefile
index dc3ccab..63976ec 100644
--- a/nptl/Makefile
+++ b/nptl/Makefile
@@ -303,7 +303,9 @@ tests-nolibpthread = tst-unload
 gen-as-const-headers = pthread-errnos.sym \
 		       lowlevelcond.sym lowlevelrwlock.sym \
 		       unwindbuf.sym \
-		       lowlevelrobustlock.sym pthread-pi-defines.sym
+		       lowlevelrobustlock.sym pthread-pi-defines.sym \
+		       infinity-nptl-constants.sym \
+		       infinity-nptl_db-constants.sym
 
 
 LDFLAGS-pthread.so = -Wl,--enable-new-dtags,-z,nodelete,-z,initfirst
diff --git a/nptl/infinity-nptl-constants.sym b/nptl/infinity-nptl-constants.sym
new file mode 100644
index 0000000..4c9fdfd
--- /dev/null
+++ b/nptl/infinity-nptl-constants.sym
@@ -0,0 +1,26 @@
+#include <pthreadP.h>
+
+-- general information
+
+__WORDSIZE
+
+-- structure offsets
+
+LIST_T_NEXT_OFFSET		offsetof (list_t, next)
+PTHREAD_CANCELHANDLING_OFFSET	offsetof (struct pthread, cancelhandling)
+PTHREAD_LIST_OFFSET		offsetof (struct pthread, list)
+PTHREAD_PID_OFFSET		offsetof (struct pthread, pid)
+PTHREAD_TID_OFFSET		offsetof (struct pthread, tid)
+PTHREAD_SCHEDPARAM_SCHED_PRIORITY_OFFSET offsetof (struct pthread, schedparam) + offsetof (struct sched_param, __sched_priority)
+PTHREAD_SCHEDPOLICY_OFFSET	offsetof (struct pthread, schedpolicy)
+
+-- scheduling algorithms
+
+SCHED_OTHER
+SCHED_FIFO
+SCHED_RR
+
+-- cancellation processing flags
+
+EXITING_BITMASK
+TERMINATED_BITMASK
diff --git a/nptl/infinity-nptl_db-constants.sym b/nptl/infinity-nptl_db-constants.sym
new file mode 100644
index 0000000..56abf98
--- /dev/null
+++ b/nptl/infinity-nptl_db-constants.sym
@@ -0,0 +1,24 @@
+#include <thread_db.h>
+#include <proc_service.h>
+
+-- td_err_e values
+
+TD_OK
+TD_ERR
+TD_DBERR
+TD_NOCAPAB
+
+-- ps_err_e values
+
+PS_OK
+PS_ERR
+
+-- td_thr_state_e values
+
+TD_THR_UNKNOWN
+TD_THR_ACTIVE
+TD_THR_ZOMBIE
+
+-- Flags for thr_iter
+
+TD_THR_LOWEST_PRIORITY
-- 
1.7.1

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [RFC v2][PATCH 22/27] Export stack_used as __stack_used
  2016-06-13 11:03   ` Pedro Alves
@ 2016-06-13 11:20     ` Gary Benson
  2016-06-13 11:24       ` Gary Benson
  0 siblings, 1 reply; 55+ messages in thread
From: Gary Benson @ 2016-06-13 11:20 UTC (permalink / raw)
  To: Pedro Alves; +Cc: libc-alpha

Pedro Alves wrote:
> On 06/13/2016 11:38 AM, Gary Benson wrote:
> > The Infinity note libpthread::thr_iter (broadly equivalent to
> > libthread_db's td_ta_thr_iter) requires access to both
> > __stack_user and stack_used, but only the former is visible to it.
> > This commit renames "stack_used" as "__stack_used" and changes it
> > from a static variable in allocatestack.c to an internally
> > exported symbol available to all nptl source files.
> 
> This rename alone should fix glibc PR 17629 (and thus GDB PR 9635).
> 
>  [put all symbols nptl_db looks up in the private namespace]
>  https://sourceware.org/bugzilla/show_bug.cgi?id=17629
> 
> Thus I think it'd be reasonable (and good) to split the renaming
> part of this patch out of the series, and get it into the tree.  I
> think it could go in quickly.

I wasn't aware of that bug.  I'll leave it a day or so to see if
anyone has any comments, then I'll mail just this change alone.

> BTW, the td_ta_thr_iter.c::iterate_thread_list hunk looks like just
> a code style change unrelated to the subject of the patch.

It's not a style change, it stops it falling through into the rest
of the function if next == 0 and !fake_empty.

I agree it should be a separate patch though.

Cheers,
Gary

-- 
http://gbenson.net/

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [RFC v2][PATCH 22/27] Export stack_used as __stack_used
  2016-06-13 11:20     ` Gary Benson
@ 2016-06-13 11:24       ` Gary Benson
  2016-06-17 11:38         ` [PATCH] " Gary Benson
  0 siblings, 1 reply; 55+ messages in thread
From: Gary Benson @ 2016-06-13 11:24 UTC (permalink / raw)
  To: Pedro Alves; +Cc: libc-alpha

Gary Benson wrote:
> Pedro Alves wrote:
> > BTW, the td_ta_thr_iter.c::iterate_thread_list hunk looks like
> > just a code style change unrelated to the subject of the patch.
> 
> It's not a style change, it stops it falling through into the rest
> of the function if next == 0 and !fake_empty.
> 
> I agree it should be a separate patch though.

Oh, wait, no, I remember: the reason it's not a separate patch is
that stack_user is statically initialized, so next == 0 never
occurred.  But, changing it to __stack_user changed how it has to
be initialized, so next == 0 can now occur.

So it should be the same patch (but maybe it needs documenting!)

Cheers,
Gary

-- 
http://gbenson.net/

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [RFC v2][PATCH 15/27] Add Infinity THREAD_SELF macros to sysdeps/sparc/nptl/tls.h
  2016-06-13 10:47 ` [RFC v2][PATCH 15/27] Add Infinity THREAD_SELF macros to sysdeps/sparc/nptl/tls.h Gary Benson
@ 2016-06-13 11:51   ` Andreas Schwab
  2016-06-13 14:05     ` Gary Benson
  0 siblings, 1 reply; 55+ messages in thread
From: Andreas Schwab @ 2016-06-13 11:51 UTC (permalink / raw)
  To: Gary Benson; +Cc: libc-alpha

Gary Benson <gbenson@redhat.com> writes:

> +/* Magic for Infinity to know how to do THREAD_SELF.  */
> +# define I8_THREAD_SELF I8_TS_REGISTER
> +# if __WORDSIZE == 32
> +#  define I8_TS_REG_OFFSET 10 * 4
> +# else
> +#  define I8_TS_REG_OFFSET (6 * 8) + (__WORDSIZE==64?0:4)

__WORDSIZE is always 64 here.

Andreas.

-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [RFC v2][PATCH 15/27] Add Infinity THREAD_SELF macros to sysdeps/sparc/nptl/tls.h
  2016-06-13 11:51   ` Andreas Schwab
@ 2016-06-13 14:05     ` Gary Benson
  2016-06-13 15:08       ` Andreas Schwab
  0 siblings, 1 reply; 55+ messages in thread
From: Gary Benson @ 2016-06-13 14:05 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: libc-alpha

Hi Andreas,

Andreas Schwab wrote:
> Gary Benson <gbenson@redhat.com> writes:
> > +/* Magic for Infinity to know how to do THREAD_SELF.  */
> > +# define I8_THREAD_SELF I8_TS_REGISTER
> > +# if __WORDSIZE == 32
> > +#  define I8_TS_REG_OFFSET 10 * 4
> > +# else
> > +#  define I8_TS_REG_OFFSET (6 * 8) + (__WORDSIZE==64?0:4)
> 
> __WORDSIZE is always 64 here.

I was trying to make sense of what sparc is doing for libthread_db
too.  It has:

  # define DB_THREAD_SELF \
    REGISTER (32, 32, 10 * 4, 0) \
    REGISTER (64, __WORDSIZE, (6 * 8) + (__WORDSIZE==64?0:4), 0)

Similarly s390 has:

  # define DB_THREAD_SELF REGISTER (32, 32, 18 * 4, 0) \
                          REGISTER (64, __WORDSIZE, 18 * 8, 0)

Could the __WORDSIZE in both of those be replaced with 64?

Thanks,
Gary

-- 
http://gbenson.net/

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [RFC v2][PATCH 15/27] Add Infinity THREAD_SELF macros to sysdeps/sparc/nptl/tls.h
  2016-06-13 14:05     ` Gary Benson
@ 2016-06-13 15:08       ` Andreas Schwab
  2016-06-15  8:50         ` Gary Benson
  0 siblings, 1 reply; 55+ messages in thread
From: Andreas Schwab @ 2016-06-13 15:08 UTC (permalink / raw)
  To: Gary Benson; +Cc: libc-alpha

Gary Benson <gbenson@redhat.com> writes:

> I was trying to make sense of what sparc is doing for libthread_db
> too.  It has:
>
>   # define DB_THREAD_SELF \
>     REGISTER (32, 32, 10 * 4, 0) \
>     REGISTER (64, __WORDSIZE, (6 * 8) + (__WORDSIZE==64?0:4), 0)
>
> Similarly s390 has:
>
>   # define DB_THREAD_SELF REGISTER (32, 32, 18 * 4, 0) \
>                           REGISTER (64, __WORDSIZE, 18 * 8, 0)
>
> Could the __WORDSIZE in both of those be replaced with 64?

No, of course not.  It is 32 in a 32-bit process.

Andreas.

-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [RFC v2][PATCH 15/27] Add Infinity THREAD_SELF macros to sysdeps/sparc/nptl/tls.h
  2016-06-13 15:08       ` Andreas Schwab
@ 2016-06-15  8:50         ` Gary Benson
  0 siblings, 0 replies; 55+ messages in thread
From: Gary Benson @ 2016-06-15  8:50 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: libc-alpha

Andreas Schwab wrote:
> Gary Benson <gbenson@redhat.com> writes:
> > I was trying to make sense of what sparc is doing for libthread_db
> > too.  It has:
> >
> >   # define DB_THREAD_SELF \
> >     REGISTER (32, 32, 10 * 4, 0) \
> >     REGISTER (64, __WORDSIZE, (6 * 8) + (__WORDSIZE==64?0:4), 0)
> >
> > Similarly s390 has:
> >
> >   # define DB_THREAD_SELF REGISTER (32, 32, 18 * 4, 0) \
> >                           REGISTER (64, __WORDSIZE, 18 * 8, 0)
> >
> > Could the __WORDSIZE in both of those be replaced with 64?
> 
> No, of course not.  It is 32 in a 32-bit process.

Ah, I see what's happening now.

What's being passed to libthread_db (and to Infinity in this series)
is a byte offset in bytes into prgregset_t.  That doesn't work for
Infinity if the offsets change depending on the wordsize of the
debugger.  I'll change these patches to pass a DWARF register number
and let the debugger figure out how to get the value.

Thanks for helping me work this out.

Cheers,
Gary

-- 
http://gbenson.net/

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [RFC v2][PATCH 10/27] Add Infinity THREAD_SELF macros to sysdeps/mips/nptl/tls.h
  2016-06-13 11:12   ` Pedro Alves
@ 2016-06-15 15:23     ` Gary Benson
  0 siblings, 0 replies; 55+ messages in thread
From: Gary Benson @ 2016-06-15 15:23 UTC (permalink / raw)
  To: Pedro Alves; +Cc: libc-alpha

Pedro Alves wrote:
> On 06/13/2016 11:38 AM, Gary Benson wrote:
> > +/* Magic for Infinity to know how to do THREAD_SELF.  */
> > +# define I8_THREAD_SELF I8_TS_CONST_THREAD_AREA
> > +# define I8_TS_CTA_VALUE TLS_TCB_OFFSET + TLS_PRE_TCB_SIZE
> > +
> 
> Wrap in parentheses to avoid precedence problems creeping in
> in future:
> 
> # define I8_TS_CTA_VALUE (TLS_TCB_OFFSET + TLS_PRE_TCB_SIZE)
> 
> etc.
> 
> More instances throughout the series.

Thanks Pedro, I've updated my tree.

Cheers,
Gary

-- 
http://gbenson.net/

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [PATCH] Export stack_used as __stack_used
  2016-06-13 11:24       ` Gary Benson
@ 2016-06-17 11:38         ` Gary Benson
  2016-06-17 11:51           ` Pedro Alves
  2016-06-17 12:33           ` Florian Weimer
  0 siblings, 2 replies; 55+ messages in thread
From: Gary Benson @ 2016-06-17 11:38 UTC (permalink / raw)
  To: libc-alpha; +Cc: Pedro Alves

Hi all,

This commit renames "stack_used" as "__stack_used" and changes it from
a static variable in allocatestack.c to an internally exported symbol
available to all nptl source files.  This fixes bug 17629 (and thus
GDB PR 9635).

Is this ok to commit?

Cheers,
Gary

---

	[BZ #17629]
	* nptl/allocatestack.c (stack_used): Rename as...
	(__stack_used): Renamed from stack_used and made non-static.
	All uses updated.
	* nptl/nptl-init.c: Initialize __stack_used.
	* nptl/pthreadP.h (__stack_used): New declaration.
	* nptl_db/td_ta_thr_iter.c (iterate_thread_list): Cope with
	__stack_used == NULL.
---
 ChangeLog                 |   11 +++++++++++
 nptl/allocatestack.c      |   33 +++++++++++++++++----------------
 nptl/descr.h              |    2 +-
 nptl/nptl-init.c          |    1 +
 nptl/pthreadP.h           |    2 ++
 nptl/pthread_create.c     |    2 +-
 nptl_db/structs.def       |    2 +-
 nptl_db/td_ta_thr_iter.c  |   15 +++++++++++----
 nptl_db/td_thr_validate.c |    2 +-
 9 files changed, 46 insertions(+), 24 deletions(-)

diff --git a/nptl/allocatestack.c b/nptl/allocatestack.c
index c044b20..d384397 100644
--- a/nptl/allocatestack.c
+++ b/nptl/allocatestack.c
@@ -113,7 +113,8 @@ static int stack_cache_lock = LLL_LOCK_INITIALIZER;
 static LIST_HEAD (stack_cache);
 
 /* List of the stacks in use.  */
-static LIST_HEAD (stack_used);
+list_t (__stack_used) __attribute__ ((nocommon));
+hidden_data_def (__stack_used)
 
 /* We need to record what list operations we are going to do so that,
    in case of an asynchronous interruption due to a fork() call, we
@@ -223,7 +224,7 @@ get_cached_stack (size_t *sizep, void **memp)
   stack_list_del (&result->list);
 
   /* And add to the list of stacks in use.  */
-  stack_list_add (&result->list, &stack_used);
+  stack_list_add (&result->list, &__stack_used);
 
   /* And decrease the cache size.  */
   stack_cache_actsize -= result->stackblock_size;
@@ -592,7 +593,7 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp,
 	  lll_lock (stack_cache_lock, LLL_PRIVATE);
 
 	  /* And add to the list of stacks in use.  */
-	  stack_list_add (&pd->list, &stack_used);
+	  stack_list_add (&pd->list, &__stack_used);
 
 	  lll_unlock (stack_cache_lock, LLL_PRIVATE);
 
@@ -781,7 +782,7 @@ __make_stacks_executable (void **stack_endp)
   lll_lock (stack_cache_lock, LLL_PRIVATE);
 
   list_t *runp;
-  list_for_each (runp, &stack_used)
+  list_for_each (runp, &__stack_used)
     {
       err = change_stack_perm (list_entry (runp, struct pthread, list)
 #ifdef NEED_SEPARATE_REGISTER_STACK
@@ -838,8 +839,8 @@ __reclaim_stacks (void)
 	     pointers at the head of the list are inconsistent.  */
 	  list_t *l = NULL;
 
-	  if (stack_used.next->prev != &stack_used)
-	    l = &stack_used;
+	  if (__stack_used.next->prev != &__stack_used)
+	    l = &__stack_used;
 	  else if (stack_cache.next->prev != &stack_cache)
 	    l = &stack_cache;
 
@@ -861,7 +862,7 @@ __reclaim_stacks (void)
 
   /* Mark all stacks except the still running one as free.  */
   list_t *runp;
-  list_for_each (runp, &stack_used)
+  list_for_each (runp, &__stack_used)
     {
       struct pthread *curp = list_entry (runp, struct pthread, list);
       if (curp != self)
@@ -905,7 +906,7 @@ __reclaim_stacks (void)
     }
 
   /* Add the stack of all running threads to the cache.  */
-  list_splice (&stack_used, &stack_cache);
+  list_splice (&__stack_used, &stack_cache);
 
   /* Remove the entry for the current thread to from the cache list
      and add it to the list of running threads.  Which of the two
@@ -913,13 +914,13 @@ __reclaim_stacks (void)
   stack_list_del (&self->list);
 
   /* Re-initialize the lists for all the threads.  */
-  INIT_LIST_HEAD (&stack_used);
+  INIT_LIST_HEAD (&__stack_used);
   INIT_LIST_HEAD (&__stack_user);
 
   if (__glibc_unlikely (THREAD_GETMEM (self, user_stack)))
     list_add (&self->list, &__stack_user);
   else
-    list_add (&self->list, &stack_used);
+    list_add (&self->list, &__stack_used);
 
   /* There is one thread running.  */
   __nptl_nthreads = 1;
@@ -945,7 +946,7 @@ __find_thread_by_id (pid_t tid)
 
   /* Iterate over the list with system-allocated threads first.  */
   list_t *runp;
-  list_for_each (runp, &stack_used)
+  list_for_each (runp, &__stack_used)
     {
       struct pthread *curp;
 
@@ -1098,7 +1099,7 @@ __nptl_setxid (struct xid_command *cmdp)
 
   /* Iterate over the list with system-allocated threads first.  */
   list_t *runp;
-  list_for_each (runp, &stack_used)
+  list_for_each (runp, &__stack_used)
     {
       struct pthread *t = list_entry (runp, struct pthread, list);
       if (t == self)
@@ -1124,7 +1125,7 @@ __nptl_setxid (struct xid_command *cmdp)
     {
       signalled = 0;
 
-      list_for_each (runp, &stack_used)
+      list_for_each (runp, &__stack_used)
 	{
 	  struct pthread *t = list_entry (runp, struct pthread, list);
 	  if (t == self)
@@ -1154,7 +1155,7 @@ __nptl_setxid (struct xid_command *cmdp)
 
   /* Clean up flags, so that no thread blocks during exit waiting
      for a signal which will never come.  */
-  list_for_each (runp, &stack_used)
+  list_for_each (runp, &__stack_used)
     {
       struct pthread *t = list_entry (runp, struct pthread, list);
       if (t == self)
@@ -1218,7 +1219,7 @@ __pthread_init_static_tls (struct link_map *map)
 
   /* Iterate over the list with system-allocated threads first.  */
   list_t *runp;
-  list_for_each (runp, &stack_used)
+  list_for_each (runp, &__stack_used)
     init_one_static_tls (list_entry (runp, struct pthread, list), map);
 
   /* Now the list with threads using user-allocated stacks.  */
@@ -1239,7 +1240,7 @@ __wait_lookup_done (void)
 
   /* Iterate over the list with system-allocated threads first.  */
   list_t *runp;
-  list_for_each (runp, &stack_used)
+  list_for_each (runp, &__stack_used)
     {
       struct pthread *t = list_entry (runp, struct pthread, list);
       if (t == self || t->header.gscope_flag == THREAD_GSCOPE_FLAG_UNUSED)
diff --git a/nptl/descr.h b/nptl/descr.h
index 8e4938d..87c5354 100644
--- a/nptl/descr.h
+++ b/nptl/descr.h
@@ -160,7 +160,7 @@ struct pthread
     void *__padding[24];
   };
 
-  /* This descriptor's link on the `stack_used' or `__stack_user' list.  */
+  /* This descriptor's link on the `__stack_used' or `__stack_user' list.  */
   list_t list;
 
   /* Thread ID - which is also a 'is this thread descriptor (and
diff --git a/nptl/nptl-init.c b/nptl/nptl-init.c
index bdbdfed..9bde618 100644
--- a/nptl/nptl-init.c
+++ b/nptl/nptl-init.c
@@ -384,6 +384,7 @@ __pthread_initialize_minimal_internal (void)
   THREAD_SETMEM (pd, stackblock_size, (size_t) __libc_stack_end);
 
   /* Initialize the list of all running threads with the main thread.  */
+  INIT_LIST_HEAD (&__stack_used);
   INIT_LIST_HEAD (&__stack_user);
   list_add (&pd->list, &__stack_user);
 
diff --git a/nptl/pthreadP.h b/nptl/pthreadP.h
index 4edc74b..e762f94 100644
--- a/nptl/pthreadP.h
+++ b/nptl/pthreadP.h
@@ -183,7 +183,9 @@ extern int __is_smp attribute_hidden;
 
 /* Thread descriptor handling.  */
 extern list_t __stack_user;
+extern list_t __stack_used;
 hidden_proto (__stack_user)
+hidden_proto (__stack_used)
 
 /* Attribute handling.  */
 extern struct pthread_attr *__attr_list attribute_hidden;
diff --git a/nptl/pthread_create.c b/nptl/pthread_create.c
index 5216041..ec49b15 100644
--- a/nptl/pthread_create.c
+++ b/nptl/pthread_create.c
@@ -87,7 +87,7 @@ __find_in_stack_list (struct pthread *pd)
 
   lll_lock (stack_cache_lock, LLL_PRIVATE);
 
-  list_for_each (entry, &stack_used)
+  list_for_each (entry, &__stack_used)
     {
       struct pthread *curp;
 
diff --git a/nptl_db/structs.def b/nptl_db/structs.def
index a9b621b..ebcc065 100644
--- a/nptl_db/structs.def
+++ b/nptl_db/structs.def
@@ -70,7 +70,7 @@ DB_STRUCT (td_eventbuf_t)
 DB_STRUCT_FIELD (td_eventbuf_t, eventnum)
 DB_STRUCT_FIELD (td_eventbuf_t, eventdata)
 
-DB_SYMBOL (stack_used)
+DB_SYMBOL (__stack_used)
 DB_SYMBOL (__stack_user)
 DB_SYMBOL (nptl_version)
 DB_FUNCTION (__nptl_create_event)
diff --git a/nptl_db/td_ta_thr_iter.c b/nptl_db/td_ta_thr_iter.c
index a990fed..aae4dd2 100644
--- a/nptl_db/td_ta_thr_iter.c
+++ b/nptl_db/td_ta_thr_iter.c
@@ -38,15 +38,22 @@ iterate_thread_list (td_thragent_t *ta, td_thr_iter_f *callback,
   if (err != TD_OK)
     return err;
 
-  if (next == 0 && fake_empty)
+  if (next == 0)
     {
       /* __pthread_initialize_minimal has not run.  There is just the main
 	 thread to return.  We cannot rely on its thread register.  They
 	 sometimes contain garbage that would confuse us, left by the
 	 kernel at exec.  So if it looks like initialization is incomplete,
 	 we only fake a special descriptor for the initial thread.  */
-      td_thrhandle_t th = { ta, 0 };
-      return callback (&th, cbdata_p) != 0 ? TD_DBERR : TD_OK;
+      if (fake_empty)
+	{
+	  td_thrhandle_t th = { ta, 0 };
+
+	  if (callback (&th, cbdata_p) != 0)
+	    return TD_DBERR;
+	}
+
+      return TD_OK;
     }
 
   /* Cache the offset from struct pthread to its list_t member.  */
@@ -161,7 +168,7 @@ td_ta_thr_iter (const td_thragent_t *ta_arg, td_thr_iter_f *callback,
 
   /* And the threads with stacks allocated by the implementation.  */
   if (err == TD_OK)
-    err = DB_GET_SYMBOL (list, ta, stack_used);
+    err = DB_GET_SYMBOL (list, ta, __stack_used);
   if (err == TD_OK)
     err = iterate_thread_list (ta, callback, cbdata_p, state, ti_pri,
 			       list, false, pid);
diff --git a/nptl_db/td_thr_validate.c b/nptl_db/td_thr_validate.c
index f3c8a7b..34b6112 100644
--- a/nptl_db/td_thr_validate.c
+++ b/nptl_db/td_thr_validate.c
@@ -70,7 +70,7 @@ td_thr_validate (const td_thrhandle_t *th)
      using implementation allocated stacks.  */
   if (err == TD_NOTHR)
     {
-      err = DB_GET_SYMBOL (list, th->th_ta_p, stack_used);
+      err = DB_GET_SYMBOL (list, th->th_ta_p, __stack_used);
       if (err == TD_OK)
 	err = check_thread_list (th, list, &uninit);
 
-- 
1.7.1

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH] Export stack_used as __stack_used
  2016-06-17 11:38         ` [PATCH] " Gary Benson
@ 2016-06-17 11:51           ` Pedro Alves
  2016-06-17 12:33           ` Florian Weimer
  1 sibling, 0 replies; 55+ messages in thread
From: Pedro Alves @ 2016-06-17 11:51 UTC (permalink / raw)
  To: Gary Benson, libc-alpha

On 06/17/2016 12:37 PM, Gary Benson wrote:
> Hi all,
> 
> This commit renames "stack_used" as "__stack_used" and changes it from
> a static variable in allocatestack.c to an internally exported symbol
> available to all nptl source files.  This fixes bug 17629 (and thus
> GDB PR 9635).

Thanks!

> 
> Is this ok to commit?

I'd have preferred to split the renaming bits out, alone, as that's
the part that actually fixes the bug, and leave the (internally) exporting
the symbol and the iterate_thread_list hunk as a patch of the Infinity
series, where it's needed.

-- 
Pedro Alves

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH] Export stack_used as __stack_used
  2016-06-17 11:38         ` [PATCH] " Gary Benson
  2016-06-17 11:51           ` Pedro Alves
@ 2016-06-17 12:33           ` Florian Weimer
  2016-06-17 19:50             ` Gary Benson
  1 sibling, 1 reply; 55+ messages in thread
From: Florian Weimer @ 2016-06-17 12:33 UTC (permalink / raw)
  To: Gary Benson; +Cc: libc-alpha, Pedro Alves

On 06/17/2016 01:37 PM, Gary Benson wrote:
> Hi all,
>
> This commit renames "stack_used" as "__stack_used" and changes it from
> a static variable in allocatestack.c to an internally exported symbol
> available to all nptl source files.  This fixes bug 17629 (and thus
> GDB PR 9635).

What do you mean by “export”?  The __ prefix suggests that you want to 
export it as a symbol (probably GLIBC_PRIVATE), but I think you'd need 
to update nptl/Versions in this case.

If the variable remains nptl-internal, I expect that you could turn it 
into a hidden symbol, and keep its current name.

Thanks,
Florian

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH] Export stack_used as __stack_used
  2016-06-17 12:33           ` Florian Weimer
@ 2016-06-17 19:50             ` Gary Benson
  2016-06-17 20:17               ` Florian Weimer
  2016-06-17 20:17               ` Gary Benson
  0 siblings, 2 replies; 55+ messages in thread
From: Gary Benson @ 2016-06-17 19:50 UTC (permalink / raw)
  To: Florian Weimer; +Cc: libc-alpha, Pedro Alves

Florian Weimer wrote:
> On 06/17/2016 01:37 PM, Gary Benson wrote:
> > This commit renames "stack_used" as "__stack_used" and changes it
> > from a static variable in allocatestack.c to an internally
> > exported symbol available to all nptl source files.  This fixes
> > bug 17629 (and thus GDB PR 9635).
> 
> What do you mean by “export”?  The __ prefix suggests that you want
> to export it as a symbol (probably GLIBC_PRIVATE), but I think you'd
> need to update nptl/Versions in this case.

No, I don't need that, it needs to be visible outside allocatestack.c
but it doesn't need to be visible in, e.g., the output of "objdump -T".

> If the variable remains nptl-internal, I expect that you could turn
> it into a hidden symbol, and keep its current name.

I may be wrong but I think its the rename that fixes the GDB bug.

If it's visible outside of allocatestack.c (i.e. it's not "static")
then it should be named with a double-underscore, no?

Thanks,
Gary

-- 
http://gbenson.net/

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH] Export stack_used as __stack_used
  2016-06-17 19:50             ` Gary Benson
  2016-06-17 20:17               ` Florian Weimer
@ 2016-06-17 20:17               ` Gary Benson
  2016-06-17 20:31                 ` Florian Weimer
  1 sibling, 1 reply; 55+ messages in thread
From: Gary Benson @ 2016-06-17 20:17 UTC (permalink / raw)
  To: Florian Weimer; +Cc: libc-alpha, Pedro Alves

Gary Benson wrote:
> Florian Weimer wrote:
> > On 06/17/2016 01:37 PM, Gary Benson wrote:
> > > This commit renames "stack_used" as "__stack_used" and changes it
> > > from a static variable in allocatestack.c to an internally
> > > exported symbol available to all nptl source files.  This fixes
> > > bug 17629 (and thus GDB PR 9635).
> > 
> > What do you mean by “export”?  The __ prefix suggests that you want
> > to export it as a symbol (probably GLIBC_PRIVATE), but I think you'd
> > need to update nptl/Versions in this case.
> 
> No, I don't need that, it needs to be visible outside allocatestack.c
> but it doesn't need to be visible in, e.g., the output of "objdump -T".
> 
> > If the variable remains nptl-internal, I expect that you could turn
> > it into a hidden symbol, and keep its current name.
> 
> I may be wrong but I think its the rename that fixes the GDB bug.
> 
> If it's visible outside of allocatestack.c (i.e. it's not "static")
> then it should be named with a double-underscore, no?

Oh, hang on, libthread_db looks it up _by_name_.  How is that working
currently?

Cheers,
Gary

-- 
http://gbenson.net/

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH] Export stack_used as __stack_used
  2016-06-17 19:50             ` Gary Benson
@ 2016-06-17 20:17               ` Florian Weimer
  2016-06-17 22:15                 ` Pedro Alves
  2016-06-17 20:17               ` Gary Benson
  1 sibling, 1 reply; 55+ messages in thread
From: Florian Weimer @ 2016-06-17 20:17 UTC (permalink / raw)
  To: Gary Benson; +Cc: libc-alpha, Pedro Alves

On 06/17/2016 09:50 PM, Gary Benson wrote:
> Florian Weimer wrote:
>> On 06/17/2016 01:37 PM, Gary Benson wrote:
>>> This commit renames "stack_used" as "__stack_used" and changes it
>>> from a static variable in allocatestack.c to an internally
>>> exported symbol available to all nptl source files.  This fixes
>>> bug 17629 (and thus GDB PR 9635).
>>
>> What do you mean by “export”?  The __ prefix suggests that you want
>> to export it as a symbol (probably GLIBC_PRIVATE), but I think you'd
>> need to update nptl/Versions in this case.
>
> No, I don't need that, it needs to be visible outside allocatestack.c
> but it doesn't need to be visible in, e.g., the output of "objdump -T".

Okay, then please declare it attribute_hidden.

>> If the variable remains nptl-internal, I expect that you could turn
>> it into a hidden symbol, and keep its current name.
>
> I may be wrong but I think its the rename that fixes the GDB bug.

Only if GDB explicitly searches for __stack_used (and that with the help 
of debugging information because it's not exported).

There isn't even a reference from libthread_db.

> If it's visible outside of allocatestack.c (i.e. it's not "static")
> then it should be named with a double-underscore, no?

Hmm, yes for the benefit of static linking and namespace cleanliness. 
So perhaps keep __stack_used, but make it hidden as well.  (I don't 
understand the nocommon business and what this addresses.)

Florian

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH] Export stack_used as __stack_used
  2016-06-17 20:17               ` Gary Benson
@ 2016-06-17 20:31                 ` Florian Weimer
  2016-06-17 22:01                   ` Pedro Alves
  0 siblings, 1 reply; 55+ messages in thread
From: Florian Weimer @ 2016-06-17 20:31 UTC (permalink / raw)
  To: Gary Benson; +Cc: libc-alpha, Pedro Alves

On 06/17/2016 10:17 PM, Gary Benson wrote:
> Gary Benson wrote:
>> Florian Weimer wrote:
>>> On 06/17/2016 01:37 PM, Gary Benson wrote:
>>>> This commit renames "stack_used" as "__stack_used" and changes it
>>>> from a static variable in allocatestack.c to an internally
>>>> exported symbol available to all nptl source files.  This fixes
>>>> bug 17629 (and thus GDB PR 9635).
>>>
>>> What do you mean by “export”?  The __ prefix suggests that you want
>>> to export it as a symbol (probably GLIBC_PRIVATE), but I think you'd
>>> need to update nptl/Versions in this case.
>>
>> No, I don't need that, it needs to be visible outside allocatestack.c
>> but it doesn't need to be visible in, e.g., the output of "objdump -T".
>>
>>> If the variable remains nptl-internal, I expect that you could turn
>>> it into a hidden symbol, and keep its current name.
>>
>> I may be wrong but I think its the rename that fixes the GDB bug.
>>
>> If it's visible outside of allocatestack.c (i.e. it's not "static")
>> then it should be named with a double-underscore, no?
>
> Oh, hang on, libthread_db looks it up _by_name_.  How is that working
> currently?

It seems that libpthread_db calls ps_pglobal_lookup, which is provided 
by the “application” (so GDB).  The mechanism is a bit weird: it almost 
looks as if someone thought about caching the name-based lookups in an 
array (with an index known at compile-time), but then never wrote the 
code to use a cache.

We check that the symbols can be found in the .symtab section (so via 
debugging information, I assume, not .dynsym).

Florian

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH] Export stack_used as __stack_used
  2016-06-17 20:31                 ` Florian Weimer
@ 2016-06-17 22:01                   ` Pedro Alves
  0 siblings, 0 replies; 55+ messages in thread
From: Pedro Alves @ 2016-06-17 22:01 UTC (permalink / raw)
  To: Florian Weimer, Gary Benson; +Cc: libc-alpha

On 06/17/2016 09:31 PM, Florian Weimer wrote:
> On 06/17/2016 10:17 PM, Gary Benson wrote:
>> Gary Benson wrote:
>>> Florian Weimer wrote:
>>>> On 06/17/2016 01:37 PM, Gary Benson wrote:
>>>>> This commit renames "stack_used" as "__stack_used" and changes it
>>>>> from a static variable in allocatestack.c to an internally
>>>>> exported symbol available to all nptl source files.  This fixes
>>>>> bug 17629 (and thus GDB PR 9635).
>>>>
>>>> What do you mean by “export”?  The __ prefix suggests that you want
>>>> to export it as a symbol (probably GLIBC_PRIVATE), but I think you'd
>>>> need to update nptl/Versions in this case.
>>>
>>> No, I don't need that, it needs to be visible outside allocatestack.c
>>> but it doesn't need to be visible in, e.g., the output of "objdump -T".
>>>
>>>> If the variable remains nptl-internal, I expect that you could turn
>>>> it into a hidden symbol, and keep its current name.
>>>
>>> I may be wrong but I think its the rename that fixes the GDB bug.

Yes it is.

Should be trivial to reproduce.  Simply write a test program that has
a global named "stack_used".  The program is totally free to do that,
because that is a symbol name not in the implementation namespace.

See:
 https://sourceware.org/bugzilla/show_bug.cgi?id=9635
And the small reproducer:
 https://sourceware.org/bugzilla/attachment.cgi?id=5756

>>>
>>> If it's visible outside of allocatestack.c (i.e. it's not "static")
>>> then it should be named with a double-underscore, no?
>>
>> Oh, hang on, libthread_db looks it up _by_name_.  How is that working
>> currently?
> 
> It seems that libpthread_db calls ps_pglobal_lookup, which is provided
> by the “application” (so GDB).  

Right.  libthread_db.so is loaded as a plugin inside gdb's address
space.  That library knows the layouts of the target's libpthread's
internals, but doesn't know where the addresses of the inferior's globals
are.  So when libthread_db.so needs to know the address of
the target inferior's libpthread's "stack_used" symbol, it asks gdb,
via the proc-service interface.

The problem is that if the program being debugged defines its own
unrelated "stack_used" symbol, gdb can well return the address of
that unrelated global to libthread_db.so.

My initial attempt was to try to fix this in gdb, by restricting gdb's global
lookup to symbols defined in libpthread.so.  However, it turned out that
that doesn't work when the inferior being debugged has been statically
linked, because in that case, libpthread is really linked inside 
the main program, and thus there's no separate "libpthread.so" gdb can
restrict the symbol lookup in.  So we're back to the same problem.

The solution I suggested in the PR then, is to rename the libpthread's
"stack_used" symbol, giving it a name that is in the implementation namespace.

I think it'd be reasonable if libthread_db's DB_GET_SYMBOL macro
had an assert that ensured that only symbols in the implementation
name space are looked up, even.

(Note that most of the libpthread symbols that libthread_db looks up
are prefixed "__nptl_"; such a prefix makes it even less likely to trip
on a conflict -- there's a remote but non-zero change that libgcc or
some other library part of the implementation has another symbol
named "__stack_used".)


> The mechanism is a bit weird: it almost
> looks as if someone thought about caching the name-based lookups in an
> array (with an index known at compile-time), but then never wrote the
> code to use a cache.
> 
> We check that the symbols can be found in the .symtab section (so via
> debugging information, I assume, not .dynsym).

Here I'm afraid you lost me.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH] Export stack_used as __stack_used
  2016-06-17 20:17               ` Florian Weimer
@ 2016-06-17 22:15                 ` Pedro Alves
  2016-06-18  6:52                   ` Andreas Schwab
  0 siblings, 1 reply; 55+ messages in thread
From: Pedro Alves @ 2016-06-17 22:15 UTC (permalink / raw)
  To: Florian Weimer, Gary Benson; +Cc: libc-alpha

On 06/17/2016 09:17 PM, Florian Weimer wrote:
> 
>>> If the variable remains nptl-internal, I expect that you could turn
>>> it into a hidden symbol, and keep its current name.
>>
>> I may be wrong but I think its the rename that fixes the GDB bug.
> 
> Only if GDB explicitly searches for __stack_used (and that with the help
> of debugging information because it's not exported).

Note that it's not GDB that _wants_ to search for the symbol, it's
libthread_db.so itself.  GDB just serves libthread_db.so's request,
through the proc_service [1] interface (nptl_db/proc_service.h).  That is,
through callbacks that serve as interface between libthread_db and
the debugger that loads it.

[1] based on Solaris's interface of the same name:
 http://docs.oracle.com/cd/E26505_01/html/816-5171/proc-service-3proc.html

> 
> There isn't even a reference from libthread_db.

AFAICS, the look ups in question are here:

 nptl_db/td_thr_validate.c:73:      err = DB_GET_SYMBOL (list, th->th_ta_p, stack_used);
 nptl_db/td_ta_thr_iter.c:164:    err = DB_GET_SYMBOL (list, ta, stack_used);

I think that nptl_version is another symbol that can potentially
cause the same problem:

 nptl_db/structs.def:51:DB_SYMBOL (stack_used)
 nptl_db/structs.def:52:DB_SYMBOL (__stack_user)
 nptl_db/structs.def:53:DB_SYMBOL (nptl_version)
 nptl_db/structs.def:56:DB_SYMBOL (__nptl_threads_events)

(Obviously it's less likely, given the "nptl" prefix, but still...)

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH] Export stack_used as __stack_used
  2016-06-17 22:15                 ` Pedro Alves
@ 2016-06-18  6:52                   ` Andreas Schwab
  2016-06-18 11:09                     ` Pedro Alves
  0 siblings, 1 reply; 55+ messages in thread
From: Andreas Schwab @ 2016-06-18  6:52 UTC (permalink / raw)
  To: Pedro Alves; +Cc: Florian Weimer, Gary Benson, libc-alpha

Pedro Alves <palves@redhat.com> writes:

> I think that nptl_version is another symbol that can potentially
> cause the same problem:
>
>  nptl_db/structs.def:51:DB_SYMBOL (stack_used)
>  nptl_db/structs.def:52:DB_SYMBOL (__stack_user)
>  nptl_db/structs.def:53:DB_SYMBOL (nptl_version)
>  nptl_db/structs.def:56:DB_SYMBOL (__nptl_threads_events)

I think that DB_SYMBOL should use aliases with a unique prefix instead
of the variable names directly, and those aliases should be put in the
dynamic symbol table so that lookup still works if libthread is
stripped.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH] Export stack_used as __stack_used
  2016-06-18  6:52                   ` Andreas Schwab
@ 2016-06-18 11:09                     ` Pedro Alves
  2016-06-20  8:53                       ` Florian Weimer
  0 siblings, 1 reply; 55+ messages in thread
From: Pedro Alves @ 2016-06-18 11:09 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: Florian Weimer, Gary Benson, libc-alpha

On 06/18/2016 07:52 AM, Andreas Schwab wrote:
> Pedro Alves <palves@redhat.com> writes:
> 
>> I think that nptl_version is another symbol that can potentially
>> cause the same problem:
>>
>>  nptl_db/structs.def:51:DB_SYMBOL (stack_used)
>>  nptl_db/structs.def:52:DB_SYMBOL (__stack_user)
>>  nptl_db/structs.def:53:DB_SYMBOL (nptl_version)
>>  nptl_db/structs.def:56:DB_SYMBOL (__nptl_threads_events)
> 
> I think that DB_SYMBOL should use aliases with a unique prefix instead
> of the variable names directly, and those aliases should be put in the
> dynamic symbol table so that lookup still works if libthread is
> stripped.

Agreed.  Requiring not-stripped libpthread used to
be a constant source of trouble for integrators, enough that gdb has a
FAQ entry about it:
 https://sourceware.org/gdb/wiki/FAQ#GDB_does_not_see_any_threads_besides_the_one_in_which_crash_occurred.3B_or_SIGTRAP_kills_my_program_when_I_set_a_breakpoint
We don't hear about this problem a lot anymore though, I believe because
gdb nowadays does not rely on libthread_db for so many things as it used to.

I seem to remember this having been proposed in the past, but there having
been pushback against putting these symbols in the dynamic symbol table,
because that increases the dynamic symbol table size just for debugging...
If this is no longer a concern, I'm all for it.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH] Export stack_used as __stack_used
  2016-06-18 11:09                     ` Pedro Alves
@ 2016-06-20  8:53                       ` Florian Weimer
  2016-06-20  9:04                         ` Andreas Schwab
  0 siblings, 1 reply; 55+ messages in thread
From: Florian Weimer @ 2016-06-20  8:53 UTC (permalink / raw)
  To: Pedro Alves, Andreas Schwab; +Cc: Gary Benson, libc-alpha

On 06/18/2016 01:08 PM, Pedro Alves wrote:

> Agreed.  Requiring not-stripped libpthread used to
> be a constant source of trouble for integrators, enough that gdb has a
> FAQ entry about it:
>  https://sourceware.org/gdb/wiki/FAQ#GDB_does_not_see_any_threads_besides_the_one_in_which_crash_occurred.3B_or_SIGTRAP_kills_my_program_when_I_set_a_breakpoint

Uh-oh.

> I seem to remember this having been proposed in the past, but there having
> been pushback against putting these symbols in the dynamic symbol table,
> because that increases the dynamic symbol table size just for debugging...
> If this is no longer a concern, I'm all for it.

Could we export a single symbol which is a struct and contains all the 
data we need?  Then the impact on dynamic symbol table size would be 
minimal.

Florian

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH] Export stack_used as __stack_used
  2016-06-20  8:53                       ` Florian Weimer
@ 2016-06-20  9:04                         ` Andreas Schwab
  2016-06-20 17:54                           ` Pedro Alves
  2016-06-21  9:15                           ` Florian Weimer
  0 siblings, 2 replies; 55+ messages in thread
From: Andreas Schwab @ 2016-06-20  9:04 UTC (permalink / raw)
  To: Florian Weimer; +Cc: Pedro Alves, Gary Benson, libc-alpha

Florian Weimer <fweimer@redhat.com> writes:

> Could we export a single symbol which is a struct and contains all the
> data we need?  Then the impact on dynamic symbol table size would be
> minimal.

That would raise the issue of compatibility. Probing each symbol
separately is much easier than trying to extend the struct.  What
exactly _is_ the impact of making the dynamic symtab a few entries
bigger?

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH] Export stack_used as __stack_used
  2016-06-20  9:04                         ` Andreas Schwab
@ 2016-06-20 17:54                           ` Pedro Alves
  2016-06-21  9:15                           ` Florian Weimer
  1 sibling, 0 replies; 55+ messages in thread
From: Pedro Alves @ 2016-06-20 17:54 UTC (permalink / raw)
  To: Andreas Schwab, Florian Weimer; +Cc: Gary Benson, libc-alpha

On 06/20/2016 10:04 AM, Andreas Schwab wrote:
> Florian Weimer <fweimer@redhat.com> writes:
> 
>> Could we export a single symbol which is a struct and contains all the
>> data we need?  Then the impact on dynamic symbol table size would be
>> minimal.
> 
> That would raise the issue of compatibility. Probing each symbol
> separately is much easier than trying to extend the struct.  What
> exactly _is_ the impact of making the dynamic symtab a few entries
> bigger?

I think this is what I was remembering:

 https://sourceware.org/ml/libc-alpha/2003-11/msg00007.html

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH] Export stack_used as __stack_used
  2016-06-20  9:04                         ` Andreas Schwab
  2016-06-20 17:54                           ` Pedro Alves
@ 2016-06-21  9:15                           ` Florian Weimer
  2016-06-21 17:31                             ` Andreas Schwab
  1 sibling, 1 reply; 55+ messages in thread
From: Florian Weimer @ 2016-06-21  9:15 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: Pedro Alves, Gary Benson, libc-alpha

On 06/20/2016 11:04 AM, Andreas Schwab wrote:
> Florian Weimer <fweimer@redhat.com> writes:
>
>> Could we export a single symbol which is a struct and contains all the
>> data we need?  Then the impact on dynamic symbol table size would be
>> minimal.
>
> That would raise the issue of compatibility. Probing each symbol
> separately is much easier than trying to extend the struct.  What
> exactly _is_ the impact of making the dynamic symtab a few entries
> bigger?

Does compatibility really matter?  I thought you need exactly matching 
libpthread and libthread_db versions anyway.  I suppose we could even 
compile the offsets into libthread_db.

I assume that for compatibility across multiple versions, we will need 
something like Infinity.

Thanks,
Florian

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH] Export stack_used as __stack_used
  2016-06-21  9:15                           ` Florian Weimer
@ 2016-06-21 17:31                             ` Andreas Schwab
  2016-06-22 10:57                               ` Mike Frysinger
  0 siblings, 1 reply; 55+ messages in thread
From: Andreas Schwab @ 2016-06-21 17:31 UTC (permalink / raw)
  To: Florian Weimer; +Cc: Pedro Alves, Gary Benson, libc-alpha

Florian Weimer <fweimer@redhat.com> writes:

> Does compatibility really matter?  I thought you need exactly matching
> libpthread and libthread_db versions anyway.  I suppose we could even
> compile the offsets into libthread_db.

The thread_db interface appears to be generic enough to be able to cope
with different versions.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH] Export stack_used as __stack_used
  2016-06-21 17:31                             ` Andreas Schwab
@ 2016-06-22 10:57                               ` Mike Frysinger
  2016-06-22 14:30                                 ` Pedro Alves
  0 siblings, 1 reply; 55+ messages in thread
From: Mike Frysinger @ 2016-06-22 10:57 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: Florian Weimer, Pedro Alves, Gary Benson, libc-alpha

[-- Attachment #1: Type: text/plain, Size: 648 bytes --]

On 21 Jun 2016 19:31, Andreas Schwab wrote:
> Florian Weimer <fweimer@redhat.com> writes:
> > Does compatibility really matter?  I thought you need exactly matching
> > libpthread and libthread_db versions anyway.  I suppose we could even
> > compile the offsets into libthread_db.
> 
> The thread_db interface appears to be generic enough to be able to cope
> with different versions.

while true, i don't think that means you can mix & match.  we've always
said glibc libs must be coherent (can't mix 2.15 libpthread with a 2.17
libc), so i'm not sure why thread_db is any different.  they're shipped
together by distros too.
-mike

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH] Export stack_used as __stack_used
  2016-06-22 10:57                               ` Mike Frysinger
@ 2016-06-22 14:30                                 ` Pedro Alves
  0 siblings, 0 replies; 55+ messages in thread
From: Pedro Alves @ 2016-06-22 14:30 UTC (permalink / raw)
  To: Andreas Schwab, Florian Weimer, Gary Benson, libc-alpha

On 06/22/2016 11:57 AM, Mike Frysinger wrote:
> On 21 Jun 2016 19:31, Andreas Schwab wrote:
>> Florian Weimer <fweimer@redhat.com> writes:
>>> Does compatibility really matter?  I thought you need exactly matching
>>> libpthread and libthread_db versions anyway.  I suppose we could even
>>> compile the offsets into libthread_db.
>>
>> The thread_db interface appears to be generic enough to be able to cope
>> with different versions.
> 
> while true, i don't think that means you can mix & match.  we've always
> said glibc libs must be coherent (can't mix 2.15 libpthread with a 2.17
> libc), so i'm not sure why thread_db is any different.  

Yeah, I don't think it's any different.

Making libthread_db cope with multiple versions would be a bad design decision, IMO.
It'd be easy-ish to make it cope if just some constant offsets in data structures
change (e.g., to cope with new fields in structures) between glibc versions, but
if the data structures themselves change, like moving from linked lists to vectors
to hash tables, etc. things get complicated.

Sorting all that out, along with debugger x debuggee arch- and ABI-independence,
is the whole point of Infinity.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 55+ messages in thread

end of thread, other threads:[~2016-06-22 14:30 UTC | newest]

Thread overview: 55+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-13 10:47 [RFC v2][PATCH 00/27] Infinity full-system preview Gary Benson
2016-06-13 10:40 ` [RFC v2][PATCH 01/27] Add NT_GNU_INFINITY to elf.h Gary Benson
2016-06-13 10:41 ` [RFC v2][PATCH 02/27] Add Infinity THREAD_SELF macros to sysdeps/aarch64/nptl/tls.h Gary Benson
2016-06-13 10:41 ` [RFC v2][PATCH 26/27] Add Infinity notes implementing libpthread::thr_get_lwpid Gary Benson
2016-06-13 10:41 ` [RFC v2][PATCH 03/27] Add Infinity THREAD_SELF macros to sysdeps/alpha/nptl/tls.h Gary Benson
2016-06-13 10:41 ` [RFC v2][PATCH 18/27] New gen-as-const-header infinity-thread_self.h Gary Benson
2016-06-13 10:41 ` [RFC v2][PATCH 04/27] Add Infinity THREAD_SELF macros to sysdeps/arm/nptl/tls.h Gary Benson
2016-06-13 10:41 ` [RFC v2][PATCH 20/27] Add ./configure checks for I8C and I8X Gary Benson
2016-06-13 10:41 ` [RFC v2][PATCH 22/27] Export stack_used as __stack_used Gary Benson
2016-06-13 11:03   ` Pedro Alves
2016-06-13 11:20     ` Gary Benson
2016-06-13 11:24       ` Gary Benson
2016-06-17 11:38         ` [PATCH] " Gary Benson
2016-06-17 11:51           ` Pedro Alves
2016-06-17 12:33           ` Florian Weimer
2016-06-17 19:50             ` Gary Benson
2016-06-17 20:17               ` Florian Weimer
2016-06-17 22:15                 ` Pedro Alves
2016-06-18  6:52                   ` Andreas Schwab
2016-06-18 11:09                     ` Pedro Alves
2016-06-20  8:53                       ` Florian Weimer
2016-06-20  9:04                         ` Andreas Schwab
2016-06-20 17:54                           ` Pedro Alves
2016-06-21  9:15                           ` Florian Weimer
2016-06-21 17:31                             ` Andreas Schwab
2016-06-22 10:57                               ` Mike Frysinger
2016-06-22 14:30                                 ` Pedro Alves
2016-06-17 20:17               ` Gary Benson
2016-06-17 20:31                 ` Florian Weimer
2016-06-17 22:01                   ` Pedro Alves
2016-06-13 10:41 ` [RFC v2][PATCH 25/27] Add Infinity notes implementing libpthread::thr_iter Gary Benson
2016-06-13 10:47 ` [RFC v2][PATCH 15/27] Add Infinity THREAD_SELF macros to sysdeps/sparc/nptl/tls.h Gary Benson
2016-06-13 11:51   ` Andreas Schwab
2016-06-13 14:05     ` Gary Benson
2016-06-13 15:08       ` Andreas Schwab
2016-06-15  8:50         ` Gary Benson
2016-06-13 10:47 ` [RFC v2][PATCH 14/27] Add Infinity THREAD_SELF macros to sysdeps/sh/nptl/tls.h Gary Benson
2016-06-13 10:47 ` [RFC v2][PATCH 17/27] Add Infinity THREAD_SELF macros to sysdeps/x86_64/nptl/tls.h Gary Benson
2016-06-13 10:47 ` [RFC v2][PATCH 07/27] Add Infinity THREAD_SELF macros to sysdeps/ia64/nptl/tls.h Gary Benson
2016-06-13 10:47 ` [RFC v2][PATCH 11/27] Add Infinity THREAD_SELF macros to sysdeps/nios2/nptl/tls.h Gary Benson
2016-06-13 10:48 ` [RFC v2][PATCH 10/27] Add Infinity THREAD_SELF macros to sysdeps/mips/nptl/tls.h Gary Benson
2016-06-13 11:12   ` Pedro Alves
2016-06-15 15:23     ` Gary Benson
2016-06-13 10:48 ` [RFC v2][PATCH 23/27] New Infinity header infinity-nptl.i8 Gary Benson
2016-06-13 10:48 ` [RFC v2][PATCH 06/27] Add Infinity THREAD_SELF macros to sysdeps/i386/nptl/tls.h Gary Benson
2016-06-13 10:48 ` [RFC v2][PATCH 13/27] Add Infinity THREAD_SELF macros to sysdeps/s390/nptl/tls.h Gary Benson
2016-06-13 10:48 ` [RFC v2][PATCH 16/27] Add Infinity THREAD_SELF macros to sysdeps/tile/nptl/tls.h Gary Benson
2016-06-13 10:57 ` [RFC v2][PATCH 05/27] Add Infinity THREAD_SELF macros to sysdeps/hppa/nptl/tls.h Gary Benson
2016-06-13 10:57 ` [RFC v2][PATCH 09/27] Add Infinity THREAD_SELF macros to sysdeps/microblaze/nptl/tls.h Gary Benson
2016-06-13 10:58 ` [RFC v2][PATCH 27/27] Add Infinity notes implementing libpthread::thr_get_state Gary Benson
2016-06-13 10:58 ` [RFC v2][PATCH 08/27] Add Infinity THREAD_SELF macros to sysdeps/m68k/nptl/tls.h Gary Benson
2016-06-13 10:58 ` [RFC v2][PATCH 12/27] Add Infinity THREAD_SELF macros to sysdeps/powerpc/nptl/tls.h Gary Benson
2016-06-13 10:58 ` [RFC v2][PATCH 21/27] Add Makerules to build %.o and %.os from %.i8 Gary Benson
2016-06-13 11:18 ` [RFC v2][PATCH 19/27] New gen-as-const-headers infinity-nptl{,_db}-constants.h Gary Benson
2016-06-13 11:18 ` [RFC v2][PATCH 24/27] Add Infinity notes implementing libpthread::map_lwp2thr Gary Benson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).