Add m4/pc_from_ucontext.m4. It supports NetBSD and OpenBSD as well.
author <shinichiro.hamaji@gmail.com> <>
Wed, 8 Jul 2009 15:41:38 +0000 (15:41 +0000)
committer <shinichiro.hamaji@gmail.com> <>
Wed, 8 Jul 2009 15:41:38 +0000 (15:41 +0000)
Also, update the version of acx_pthread.m4

git-svn-id: https://google-glog.googlecode.com/svn/trunk@55 eb4d4688-79bd-11dd-afb4-1d65580434c0

Makefile.in
aclocal.m4
configure
configure.ac
m4/acx_pthread.m4
m4/pc_from_ucontext.m4 [new file with mode: 0644]

index 3988e28..6457dc1 100644 (file)
@@ -67,6 +67,7 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/ac_have_attribute.m4 \
        $(top_srcdir)/m4/ac_rwlock.m4 $(top_srcdir)/m4/acx_pthread.m4 \
        $(top_srcdir)/m4/google_namespace.m4 \
        $(top_srcdir)/m4/namespaces.m4 \
+       $(top_srcdir)/m4/pc_from_ucontext.m4 \
        $(top_srcdir)/m4/stl_namespace.m4 \
        $(top_srcdir)/m4/using_operator.m4 $(top_srcdir)/configure.ac
 am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
index db868e0..5515306 100644 (file)
@@ -7537,5 +7537,6 @@ m4_include([m4/ac_rwlock.m4])
 m4_include([m4/acx_pthread.m4])
 m4_include([m4/google_namespace.m4])
 m4_include([m4/namespaces.m4])
+m4_include([m4/pc_from_ucontext.m4])
 m4_include([m4/stl_namespace.m4])
 m4_include([m4/using_operator.m4])
index b920007..9d15c1a 100755 (executable)
--- a/configure
+++ b/configure
@@ -23526,50 +23526,97 @@ test -n "$PTHREAD_CC" || PTHREAD_CC="${CC}"
           PTHREAD_CC=$CC
        fi
 
-   # The next part tries to detect GCC inconsistency with -shared on some
-   # architectures and systems. The problem is that in certain
-   # configurations, when -shared is specified, GCC "forgets" to
-   # internally use various flags which are still necessary.
+       # The next part tries to detect GCC inconsistency with -shared on some
+       # architectures and systems. The problem is that in certain
+       # configurations, when -shared is specified, GCC "forgets" to
+       # internally use various flags which are still necessary.
 
-   { echo "$as_me:$LINENO: checking whether to check for GCC pthread/shared inconsistencies" >&5
+       #
+       # Prepare the flags
+       #
+       save_CFLAGS="$CFLAGS"
+       save_LIBS="$LIBS"
+       save_CC="$CC"
+
+       # Try with the flags determined by the earlier checks.
+       #
+       # -Wl,-z,defs forces link-time symbol resolution, so that the
+       # linking checks with -shared actually have any value
+       #
+       # FIXME: -fPIC is required for -shared on many architectures,
+       # so we specify it here, but the right way would probably be to
+       # properly detect whether it is actually required.
+       CFLAGS="-shared -fPIC -Wl,-z,defs $CFLAGS $PTHREAD_CFLAGS"
+       LIBS="$PTHREAD_LIBS $LIBS"
+       CC="$PTHREAD_CC"
+
+       # In order not to create several levels of indentation, we test
+       # the value of "$done" until we find the cure or run out of ideas.
+       done="no"
+
+       # First, make sure the CFLAGS we added are actually accepted by our
+       # compiler.  If not (and OS X's ld, for instance, does not accept -z),
+       # then we can't do this test.
+       if test x"$done" = xno; then
+          { echo "$as_me:$LINENO: checking whether to check for GCC pthread/shared inconsistencies" >&5
 echo $ECHO_N "checking whether to check for GCC pthread/shared inconsistencies... $ECHO_C" >&6; }
-   check_inconsistencies=yes
-   case "${host_cpu}-${host_os}" in
-     *-darwin*) check_inconsistencies=no ;;
-   esac
-   if test x"$GCC" != xyes -o "x$check_inconsistencies" != xyes ; then
-      { echo "$as_me:$LINENO: result: no" >&5
+          cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+        test -z "$ac_c_werror_flag" ||
+        test ! -s conftest.err
+       } && test -s conftest$ac_exeext &&
+       $as_test_x conftest$ac_exeext; then
+  :
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+       done=yes
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
+
+          if test "x$done" = xyes ; then
+             { echo "$as_me:$LINENO: result: no" >&5
 echo "${ECHO_T}no" >&6; }
-   else
-      { echo "$as_me:$LINENO: result: yes" >&5
+          else
+             { echo "$as_me:$LINENO: result: yes" >&5
 echo "${ECHO_T}yes" >&6; }
+          fi
+       fi
 
-      # In order not to create several levels of indentation, we test
-      # the value of "$ok" until we find out the cure or run out of
-      # ideas.
-      ok="no"
-
-      #
-      # Prepare the flags
-      #
-      save_CFLAGS="$CFLAGS"
-      save_LIBS="$LIBS"
-      save_CC="$CC"
-      # Try with the flags determined by the earlier checks.
-      #
-      # -Wl,-z,defs forces link-time symbol resolution, so that the
-      # linking checks with -shared actually have any value
-      #
-      # FIXME: -fPIC is required for -shared on many architectures,
-      # so we specify it here, but the right way would probably be to
-      # properly detect whether it is actually required.
-      CFLAGS="-shared -fPIC -Wl,-z,defs $CFLAGS $PTHREAD_CFLAGS"
-      LIBS="$PTHREAD_LIBS $LIBS"
-      CC="$PTHREAD_CC"
-
-      { echo "$as_me:$LINENO: checking whether -pthread is sufficient with -shared" >&5
+       if test x"$done" = xno; then
+          { echo "$as_me:$LINENO: checking whether -pthread is sufficient with -shared" >&5
 echo $ECHO_N "checking whether -pthread is sufficient with -shared... $ECHO_C" >&6; }
-      cat >conftest.$ac_ext <<_ACEOF
+          cat >conftest.$ac_ext <<_ACEOF
 /* confdefs.h.  */
 _ACEOF
 cat confdefs.h >>conftest.$ac_ext
@@ -23580,8 +23627,8 @@ int
 main ()
 {
 pthread_t th; pthread_join(th, 0);
-         pthread_attr_init(0); pthread_cleanup_push(0, 0);
-         pthread_create(0,0,0,0); pthread_cleanup_pop(0);
+             pthread_attr_init(0); pthread_cleanup_push(0, 0);
+             pthread_create(0,0,0,0); pthread_cleanup_pop(0);
   ;
   return 0;
 }
@@ -23604,7 +23651,7 @@ eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
         test ! -s conftest.err
        } && test -s conftest$ac_exeext &&
        $as_test_x conftest$ac_exeext; then
-  ok=yes
+  done=yes
 else
   echo "$as_me: failed program was:" >&5
 sed 's/^/| /' conftest.$ac_ext >&5
 rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
       conftest$ac_exeext conftest.$ac_ext
 
-      if test "x$ok" = xyes; then
-         { echo "$as_me:$LINENO: result: yes" >&5
+          if test "x$done" = xyes; then
+             { echo "$as_me:$LINENO: result: yes" >&5
 echo "${ECHO_T}yes" >&6; }
-      else
-         { echo "$as_me:$LINENO: result: no" >&5
+          else
+             { echo "$as_me:$LINENO: result: no" >&5
 echo "${ECHO_T}no" >&6; }
-      fi
+          fi
+       fi
 
-      #
-      # Linux gcc on some architectures such as mips/mipsel forgets
-      # about -lpthread
-      #
-      if test x"$ok" = xno; then
-         { echo "$as_me:$LINENO: checking whether -lpthread fixes that" >&5
+       #
+       # Linux gcc on some architectures such as mips/mipsel forgets
+       # about -lpthread
+       #
+       if test x"$done" = xno; then
+          { echo "$as_me:$LINENO: checking whether -lpthread fixes that" >&5
 echo $ECHO_N "checking whether -lpthread fixes that... $ECHO_C" >&6; }
-         LIBS="-lpthread $PTHREAD_LIBS $save_LIBS"
-         cat >conftest.$ac_ext <<_ACEOF
+          LIBS="-lpthread $PTHREAD_LIBS $save_LIBS"
+          cat >conftest.$ac_ext <<_ACEOF
 /* confdefs.h.  */
 _ACEOF
 cat confdefs.h >>conftest.$ac_ext
@@ -23642,8 +23690,8 @@ int
 main ()
 {
 pthread_t th; pthread_join(th, 0);
-            pthread_attr_init(0); pthread_cleanup_push(0, 0);
-            pthread_create(0,0,0,0); pthread_cleanup_pop(0);
+             pthread_attr_init(0); pthread_cleanup_push(0, 0);
+             pthread_create(0,0,0,0); pthread_cleanup_pop(0);
   ;
   return 0;
 }
@@ -23666,7 +23714,7 @@ eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
         test ! -s conftest.err
        } && test -s conftest$ac_exeext &&
        $as_test_x conftest$ac_exeext; then
-  ok=yes
+  done=yes
 else
   echo "$as_me: failed program was:" >&5
 sed 's/^/| /' conftest.$ac_ext >&5
 rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
       conftest$ac_exeext conftest.$ac_ext
 
-         if test "x$ok" = xyes; then
-            { echo "$as_me:$LINENO: result: yes" >&5
+          if test "x$done" = xyes; then
+             { echo "$as_me:$LINENO: result: yes" >&5
 echo "${ECHO_T}yes" >&6; }
-            PTHREAD_LIBS="-lpthread $PTHREAD_LIBS"
-         else
-            { echo "$as_me:$LINENO: result: no" >&5
+             PTHREAD_LIBS="-lpthread $PTHREAD_LIBS"
+          else
+             { echo "$as_me:$LINENO: result: no" >&5
 echo "${ECHO_T}no" >&6; }
-         fi
-      fi
-      #
-      # FreeBSD 4.10 gcc forgets to use -lc_r instead of -lc
-      #
-      if test x"$ok" = xno; then
-         { echo "$as_me:$LINENO: checking whether -lc_r fixes that" >&5
+          fi
+       fi
+       #
+       # FreeBSD 4.10 gcc forgets to use -lc_r instead of -lc
+       #
+       if test x"$done" = xno; then
+          { echo "$as_me:$LINENO: checking whether -lc_r fixes that" >&5
 echo $ECHO_N "checking whether -lc_r fixes that... $ECHO_C" >&6; }
-         LIBS="-lc_r $PTHREAD_LIBS $save_LIBS"
-         cat >conftest.$ac_ext <<_ACEOF
+          LIBS="-lc_r $PTHREAD_LIBS $save_LIBS"
+          cat >conftest.$ac_ext <<_ACEOF
 /* confdefs.h.  */
 _ACEOF
 cat confdefs.h >>conftest.$ac_ext
@@ -23704,8 +23752,8 @@ int
 main ()
 {
 pthread_t th; pthread_join(th, 0);
-              pthread_attr_init(0); pthread_cleanup_push(0, 0);
-              pthread_create(0,0,0,0); pthread_cleanup_pop(0);
+               pthread_attr_init(0); pthread_cleanup_push(0, 0);
+               pthread_create(0,0,0,0); pthread_cleanup_pop(0);
   ;
   return 0;
 }
@@ -23728,7 +23776,7 @@ eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
         test ! -s conftest.err
        } && test -s conftest$ac_exeext &&
        $as_test_x conftest$ac_exeext; then
-  ok=yes
+  done=yes
 else
   echo "$as_me: failed program was:" >&5
 sed 's/^/| /' conftest.$ac_ext >&5
 rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
       conftest$ac_exeext conftest.$ac_ext
 
-         if test "x$ok" = xyes; then
-            { echo "$as_me:$LINENO: result: yes" >&5
+          if test "x$done" = xyes; then
+             { echo "$as_me:$LINENO: result: yes" >&5
 echo "${ECHO_T}yes" >&6; }
-            PTHREAD_LIBS="-lc_r $PTHREAD_LIBS"
-         else
-            { echo "$as_me:$LINENO: result: no" >&5
+             PTHREAD_LIBS="-lc_r $PTHREAD_LIBS"
+          else
+             { echo "$as_me:$LINENO: result: no" >&5
 echo "${ECHO_T}no" >&6; }
-         fi
-      fi
-      if test x"$ok" = xno; then
-         # OK, we have run out of ideas
-         { echo "$as_me:$LINENO: WARNING: Impossible to determine how to use pthreads with shared libraries" >&5
+          fi
+       fi
+       if test x"$done" = xno; then
+          # OK, we have run out of ideas
+          { echo "$as_me:$LINENO: WARNING: Impossible to determine how to use pthreads with shared libraries" >&5
 echo "$as_me: WARNING: Impossible to determine how to use pthreads with shared libraries" >&2;}
 
-         # so it's not safe to assume that we may use pthreads
-         acx_pthread_ok=no
-      fi
+          # so it's not safe to assume that we may use pthreads
+          acx_pthread_ok=no
+       fi
 
-      CFLAGS="$save_CFLAGS"
-      LIBS="$save_LIBS"
-      CC="$save_CC"
-   fi
+       CFLAGS="$save_CFLAGS"
+       LIBS="$save_LIBS"
+       CC="$save_CC"
 else
         PTHREAD_CC="$CC"
 fi
@@ -24527,38 +24574,36 @@ _ACEOF
 
   fi
 
-# We want to access the "PC" (Program Counter) register from a struct
-# ucontext.  Every system has its own way of doing that.  We try all the
-# possibilities we know about.  Note REG_PC should come first (REG_RIP
-# is also defined on solaris, but does the wrong thing).
 { echo "$as_me:$LINENO: checking how to access the program counter from a struct ucontext" >&5
 echo $ECHO_N "checking how to access the program counter from a struct ucontext... $ECHO_C" >&6; }
-pc_fields="           uc_mcontext.gregs[REG_PC]"  # Solaris x86 (32 + 64 bit)
-pc_fields="$pc_fields uc_mcontext.gregs[REG_EIP]" # Linux (i386)
-pc_fields="$pc_fields uc_mcontext.gregs[REG_RIP]" # Linux (x86_64)
-pc_fields="$pc_fields uc_mcontext.sc_ip"            # Linux (ia64)
-pc_fields="$pc_fields uc_mcontext.uc_regs->gregs[PT_NIP]" # Linux (ppc)
-pc_fields="$pc_fields uc_mcontext.gregs[R15]"     # Linux (arm old [untested])
-pc_fields="$pc_fields uc_mcontext.arm_pc"           # Linux (arm new [untested])
-pc_fields="$pc_fields uc_mcontext.mc_eip"           # FreeBSD (i386)
-pc_fields="$pc_fields uc_mcontext.mc_rip"           # FreeBSD (x86_64 [untested])
-pc_fields="$pc_fields uc_mcontext->ss.eip"          # OS X (i386, <=10.4)
-pc_fields="$pc_fields uc_mcontext->__ss.__eip"      # OS X (i386, >=10.5)
-pc_fields="$pc_fields uc_mcontext->ss.rip"          # OS X (x86_64)
-pc_fields="$pc_fields uc_mcontext->__ss.__rip"      # OS X (>=10.5 [untested])
-pc_fields="$pc_fields uc_mcontext->ss.srr0"         # OS X (ppc, ppc64 [untested])
-pc_fields="$pc_fields uc_mcontext->__ss.__srr0"     # OS X (>=10.5 [untested])
-pc_field_found=false
-for pc_field in $pc_fields; do
-  if ! $pc_field_found; then
-    cat >conftest.$ac_ext <<_ACEOF
+   pc_fields="           uc_mcontext.gregs[REG_PC]"  # Solaris x86 (32 + 64 bit)
+   pc_fields="$pc_fields uc_mcontext.gregs[REG_EIP]" # Linux (i386)
+   pc_fields="$pc_fields uc_mcontext.gregs[REG_RIP]" # Linux (x86_64)
+   pc_fields="$pc_fields uc_mcontext.sc_ip"            # Linux (ia64)
+   pc_fields="$pc_fields uc_mcontext.uc_regs->gregs[PT_NIP]" # Linux (ppc)
+   pc_fields="$pc_fields uc_mcontext.gregs[R15]"     # Linux (arm old [untested])
+   pc_fields="$pc_fields uc_mcontext.arm_pc"           # Linux (arm new [untested])
+   pc_fields="$pc_fields uc_mcontext.mc_eip"           # FreeBSD (i386)
+   pc_fields="$pc_fields uc_mcontext.mc_rip"           # FreeBSD (x86_64 [untested])
+   pc_fields="$pc_fields uc_mcontext.__gregs[_REG_EIP]"  # NetBSD (i386)
+   pc_fields="$pc_fields uc_mcontext.__gregs[_REG_RIP]"  # NetBSD (x86_64)
+   pc_fields="$pc_fields uc_mcontext->ss.eip"          # OS X (i386, <=10.4)
+   pc_fields="$pc_fields uc_mcontext->__ss.__eip"      # OS X (i386, >=10.5)
+   pc_fields="$pc_fields uc_mcontext->ss.rip"          # OS X (x86_64)
+   pc_fields="$pc_fields uc_mcontext->__ss.__rip"      # OS X (>=10.5 [untested])
+   pc_fields="$pc_fields uc_mcontext->ss.srr0"         # OS X (ppc, ppc64 [untested])
+   pc_fields="$pc_fields uc_mcontext->__ss.__srr0"     # OS X (>=10.5 [untested])
+   pc_field_found=false
+   for pc_field in $pc_fields; do
+     if ! $pc_field_found; then
+       cat >conftest.$ac_ext <<_ACEOF
 /* confdefs.h.  */
 _ACEOF
 cat confdefs.h >>conftest.$ac_ext
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 #define _GNU_SOURCE 1
-                    #include <ucontext.h>
+                       #include <ucontext.h>
 int
 main ()
 {
@@ -24589,9 +24634,9 @@ cat >>confdefs.h <<_ACEOF
 #define PC_FROM_UCONTEXT $pc_field
 _ACEOF
 
-                   { echo "$as_me:$LINENO: result: $pc_field" >&5
+                      { echo "$as_me:$LINENO: result: $pc_field" >&5
 echo "${ECHO_T}$pc_field" >&6; }
-                pc_field_found=true
+                      pc_field_found=true
 else
   echo "$as_me: failed program was:" >&5
 sed 's/^/| /' conftest.$ac_ext >&5
@@ -24600,13 +24645,69 @@ sed 's/^/| /' conftest.$ac_ext >&5
 fi
 
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-  fi
-done
-if ! $pc_field_found; then
-  { echo "$as_me:$LINENO: WARNING: Could not find the PC.  Will not output failed addresses..." >&5
-echo "$as_me: WARNING: Could not find the PC.  Will not output failed addresses..." >&2;}
+     fi
+   done
+   if ! $pc_field_found; then
+     pc_fields="           sc_eip"  # OpenBSD (i386)
+     pc_fields="$pc_fields sc_rip"  # OpenBSD (x86_64)
+     for pc_field in $pc_fields; do
+       if ! $pc_field_found; then
+         cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <signal.h>
+int
+main ()
+{
+ucontext_t u; return u.$pc_field == 0;
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+        test -z "$ac_c_werror_flag" ||
+        test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+
+cat >>confdefs.h <<_ACEOF
+#define PC_FROM_UCONTEXT $pc_field
+_ACEOF
+
+                        { echo "$as_me:$LINENO: result: $pc_field" >&5
+echo "${ECHO_T}$pc_field" >&6; }
+                        pc_field_found=true
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+
 fi
 
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+       fi
+     done
+   fi
+   if ! $pc_field_found; then
+     { echo "$as_me:$LINENO: WARNING: Could not find the PC.  Will not output failed addresses..." >&5
+echo "$as_me: WARNING: Could not find the PC.  Will not output failed addresses..." >&2;}
+   fi
+
 # These are what's needed by logging.h.in and raw_logging.h.in
 
 
index 60466df..9435084 100644 (file)
@@ -172,41 +172,7 @@ AC_DEFINE_GOOGLE_NAMESPACE(google)
 
 AC_CXX_USING_OPERATOR
 
-# We want to access the "PC" (Program Counter) register from a struct
-# ucontext.  Every system has its own way of doing that.  We try all the
-# possibilities we know about.  Note REG_PC should come first (REG_RIP
-# is also defined on solaris, but does the wrong thing).
-AC_MSG_CHECKING([how to access the program counter from a struct ucontext])
-pc_fields="           uc_mcontext.gregs[[REG_PC]]"  # Solaris x86 (32 + 64 bit)
-pc_fields="$pc_fields uc_mcontext.gregs[[REG_EIP]]" # Linux (i386)
-pc_fields="$pc_fields uc_mcontext.gregs[[REG_RIP]]" # Linux (x86_64)
-pc_fields="$pc_fields uc_mcontext.sc_ip"            # Linux (ia64)
-pc_fields="$pc_fields uc_mcontext.uc_regs->gregs[[PT_NIP]]" # Linux (ppc)
-pc_fields="$pc_fields uc_mcontext.gregs[[R15]]"     # Linux (arm old [untested])
-pc_fields="$pc_fields uc_mcontext.arm_pc"           # Linux (arm new [untested])
-pc_fields="$pc_fields uc_mcontext.mc_eip"           # FreeBSD (i386)
-pc_fields="$pc_fields uc_mcontext.mc_rip"           # FreeBSD (x86_64 [untested])
-pc_fields="$pc_fields uc_mcontext->ss.eip"          # OS X (i386, <=10.4)
-pc_fields="$pc_fields uc_mcontext->__ss.__eip"      # OS X (i386, >=10.5)
-pc_fields="$pc_fields uc_mcontext->ss.rip"          # OS X (x86_64)
-pc_fields="$pc_fields uc_mcontext->__ss.__rip"      # OS X (>=10.5 [untested])
-pc_fields="$pc_fields uc_mcontext->ss.srr0"         # OS X (ppc, ppc64 [untested])
-pc_fields="$pc_fields uc_mcontext->__ss.__srr0"     # OS X (>=10.5 [untested])
-pc_field_found=false
-for pc_field in $pc_fields; do
-  if ! $pc_field_found; then
-    AC_TRY_COMPILE([#define _GNU_SOURCE 1
-                    #include <ucontext.h>],
-                   [ucontext_t u; return u.$pc_field == 0;],
-                   AC_DEFINE_UNQUOTED(PC_FROM_UCONTEXT, $pc_field,
-                                      How to access the PC from a struct ucontext)
-                   AC_MSG_RESULT([$pc_field])
-                pc_field_found=true)
-  fi
-done
-if ! $pc_field_found; then
-  AC_MSG_WARN(Could not find the PC.  Will not output failed addresses...)
-fi
+AC_PC_FROM_UCONTEXT(AC_MSG_WARN(Could not find the PC.  Will not output failed addresses...))
 
 # These are what's needed by logging.h.in and raw_logging.h.in
 AC_SUBST(ac_google_start_namespace)
index f5db4f0..2cf20de 100644 (file)
@@ -1,7 +1,12 @@
 # This was retrieved from
-#    http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/common/acx_pthread.m4?rev=1227
+#    http://svn.0pointer.de/viewvc/trunk/common/acx_pthread.m4?revision=1277&root=avahi
 # See also (perhaps for new versions?)
-#    http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/common/acx_pthread.m4
+#    http://svn.0pointer.de/viewvc/trunk/common/acx_pthread.m4?root=avahi
+#
+# We've rewritten the inconsistency check code (from avahi), to work
+# more broadly.  In particular, it no longer assumes ld accepts -zdefs.
+# This caused a restructing of the code, but the functionality has only
+# changed a little.
 
 dnl @synopsis ACX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
 dnl
@@ -231,108 +236,113 @@ if test "x$acx_pthread_ok" = xyes; then
           PTHREAD_CC=$CC
        fi
 
-   # The next part tries to detect GCC inconsistency with -shared on some
-   # architectures and systems. The problem is that in certain
-   # configurations, when -shared is specified, GCC "forgets" to
-   # internally use various flags which are still necessary.
-   
-   AC_MSG_CHECKING([whether to check for GCC pthread/shared inconsistencies])
-   check_inconsistencies=yes
-   case "${host_cpu}-${host_os}" in
-     *-darwin*) check_inconsistencies=no ;;
-   esac
-   if test x"$GCC" != xyes -o "x$check_inconsistencies" != xyes ; then
-      AC_MSG_RESULT([no])
-   else
-      AC_MSG_RESULT([yes])
-
-      # In order not to create several levels of indentation, we test
-      # the value of "$ok" until we find out the cure or run out of
-      # ideas.
-      ok="no"
-
-      #
-      # Prepare the flags
-      #
-      save_CFLAGS="$CFLAGS"
-      save_LIBS="$LIBS"
-      save_CC="$CC"
-      # Try with the flags determined by the earlier checks.
-      #
-      # -Wl,-z,defs forces link-time symbol resolution, so that the
-      # linking checks with -shared actually have any value
-      #
-      # FIXME: -fPIC is required for -shared on many architectures,
-      # so we specify it here, but the right way would probably be to
-      # properly detect whether it is actually required.
-      CFLAGS="-shared -fPIC -Wl,-z,defs $CFLAGS $PTHREAD_CFLAGS"
-      LIBS="$PTHREAD_LIBS $LIBS"
-      CC="$PTHREAD_CC"
-
-      AC_MSG_CHECKING([whether -pthread is sufficient with -shared])
-      AC_TRY_LINK([#include <pthread.h>],
-         [pthread_t th; pthread_join(th, 0);
-         pthread_attr_init(0); pthread_cleanup_push(0, 0);
-         pthread_create(0,0,0,0); pthread_cleanup_pop(0); ],
-         [ok=yes])
-      
-      if test "x$ok" = xyes; then
-         AC_MSG_RESULT([yes])
-      else
-         AC_MSG_RESULT([no])
-      fi
-   
-      #
-      # Linux gcc on some architectures such as mips/mipsel forgets
-      # about -lpthread
-      #
-      if test x"$ok" = xno; then
-         AC_MSG_CHECKING([whether -lpthread fixes that])
-         LIBS="-lpthread $PTHREAD_LIBS $save_LIBS"
-         AC_TRY_LINK([#include <pthread.h>],
-            [pthread_t th; pthread_join(th, 0);
-            pthread_attr_init(0); pthread_cleanup_push(0, 0);
-            pthread_create(0,0,0,0); pthread_cleanup_pop(0); ],
-            [ok=yes])
-   
-         if test "x$ok" = xyes; then
-            AC_MSG_RESULT([yes])
-            PTHREAD_LIBS="-lpthread $PTHREAD_LIBS"
-         else
-            AC_MSG_RESULT([no])
-         fi
-      fi
-      #
-      # FreeBSD 4.10 gcc forgets to use -lc_r instead of -lc
-      #
-      if test x"$ok" = xno; then
-         AC_MSG_CHECKING([whether -lc_r fixes that])
-         LIBS="-lc_r $PTHREAD_LIBS $save_LIBS"
-         AC_TRY_LINK([#include <pthread.h>],
-             [pthread_t th; pthread_join(th, 0);
-              pthread_attr_init(0); pthread_cleanup_push(0, 0);
-              pthread_create(0,0,0,0); pthread_cleanup_pop(0); ],
-             [ok=yes])
-   
-         if test "x$ok" = xyes; then
-            AC_MSG_RESULT([yes])
-            PTHREAD_LIBS="-lc_r $PTHREAD_LIBS"
-         else
-            AC_MSG_RESULT([no])
-         fi
-      fi
-      if test x"$ok" = xno; then
-         # OK, we have run out of ideas
-         AC_MSG_WARN([Impossible to determine how to use pthreads with shared libraries])
-
-         # so it's not safe to assume that we may use pthreads
-         acx_pthread_ok=no
-      fi
-
-      CFLAGS="$save_CFLAGS"
-      LIBS="$save_LIBS"
-      CC="$save_CC"
-   fi
+       # The next part tries to detect GCC inconsistency with -shared on some
+       # architectures and systems. The problem is that in certain
+       # configurations, when -shared is specified, GCC "forgets" to
+       # internally use various flags which are still necessary.
+       
+       #
+       # Prepare the flags
+       #
+       save_CFLAGS="$CFLAGS"
+       save_LIBS="$LIBS"
+       save_CC="$CC"
+       
+       # Try with the flags determined by the earlier checks.
+       #
+       # -Wl,-z,defs forces link-time symbol resolution, so that the
+       # linking checks with -shared actually have any value
+       #
+       # FIXME: -fPIC is required for -shared on many architectures,
+       # so we specify it here, but the right way would probably be to
+       # properly detect whether it is actually required.
+       CFLAGS="-shared -fPIC -Wl,-z,defs $CFLAGS $PTHREAD_CFLAGS"
+       LIBS="$PTHREAD_LIBS $LIBS"
+       CC="$PTHREAD_CC"
+       
+       # In order not to create several levels of indentation, we test
+       # the value of "$done" until we find the cure or run out of ideas.
+       done="no"
+       
+       # First, make sure the CFLAGS we added are actually accepted by our
+       # compiler.  If not (and OS X's ld, for instance, does not accept -z),
+       # then we can't do this test.
+       if test x"$done" = xno; then
+          AC_MSG_CHECKING([whether to check for GCC pthread/shared inconsistencies])
+          AC_TRY_LINK(,, , [done=yes])
+       
+          if test "x$done" = xyes ; then
+             AC_MSG_RESULT([no])
+          else
+             AC_MSG_RESULT([yes])
+          fi
+       fi
+       
+       if test x"$done" = xno; then
+          AC_MSG_CHECKING([whether -pthread is sufficient with -shared])
+          AC_TRY_LINK([#include <pthread.h>],
+             [pthread_t th; pthread_join(th, 0);
+             pthread_attr_init(0); pthread_cleanup_push(0, 0);
+             pthread_create(0,0,0,0); pthread_cleanup_pop(0); ],
+             [done=yes])
+          
+          if test "x$done" = xyes; then
+             AC_MSG_RESULT([yes])
+          else
+             AC_MSG_RESULT([no])
+          fi
+       fi
+       
+       #
+       # Linux gcc on some architectures such as mips/mipsel forgets
+       # about -lpthread
+       #
+       if test x"$done" = xno; then
+          AC_MSG_CHECKING([whether -lpthread fixes that])
+          LIBS="-lpthread $PTHREAD_LIBS $save_LIBS"
+          AC_TRY_LINK([#include <pthread.h>],
+             [pthread_t th; pthread_join(th, 0);
+             pthread_attr_init(0); pthread_cleanup_push(0, 0);
+             pthread_create(0,0,0,0); pthread_cleanup_pop(0); ],
+             [done=yes])
+       
+          if test "x$done" = xyes; then
+             AC_MSG_RESULT([yes])
+             PTHREAD_LIBS="-lpthread $PTHREAD_LIBS"
+          else
+             AC_MSG_RESULT([no])
+          fi
+       fi
+       #
+       # FreeBSD 4.10 gcc forgets to use -lc_r instead of -lc
+       #
+       if test x"$done" = xno; then
+          AC_MSG_CHECKING([whether -lc_r fixes that])
+          LIBS="-lc_r $PTHREAD_LIBS $save_LIBS"
+          AC_TRY_LINK([#include <pthread.h>],
+              [pthread_t th; pthread_join(th, 0);
+               pthread_attr_init(0); pthread_cleanup_push(0, 0);
+               pthread_create(0,0,0,0); pthread_cleanup_pop(0); ],
+              [done=yes])
+       
+          if test "x$done" = xyes; then
+             AC_MSG_RESULT([yes])
+             PTHREAD_LIBS="-lc_r $PTHREAD_LIBS"
+          else
+             AC_MSG_RESULT([no])
+          fi
+       fi
+       if test x"$done" = xno; then
+          # OK, we have run out of ideas
+          AC_MSG_WARN([Impossible to determine how to use pthreads with shared libraries])
+       
+          # so it's not safe to assume that we may use pthreads
+          acx_pthread_ok=no
+       fi
+       
+       CFLAGS="$save_CFLAGS"
+       LIBS="$save_LIBS"
+       CC="$save_CC"
 else
         PTHREAD_CC="$CC"
 fi
diff --git a/m4/pc_from_ucontext.m4 b/m4/pc_from_ucontext.m4
new file mode 100644 (file)
index 0000000..8c4c5ce
--- /dev/null
@@ -0,0 +1,56 @@
+# We want to access the "PC" (Program Counter) register from a struct
+# ucontext.  Every system has its own way of doing that.  We try all the
+# possibilities we know about.  Note REG_PC should come first (REG_RIP
+# is also defined on solaris, but does the wrong thing).
+
+# OpenBSD doesn't have ucontext.h, but we can get PC from ucontext_t
+# by using signal.h.
+
+AC_DEFUN([AC_PC_FROM_UCONTEXT],
+  [AC_MSG_CHECKING([how to access the program counter from a struct ucontext])
+   pc_fields="           uc_mcontext.gregs[[REG_PC]]"  # Solaris x86 (32 + 64 bit)
+   pc_fields="$pc_fields uc_mcontext.gregs[[REG_EIP]]" # Linux (i386)
+   pc_fields="$pc_fields uc_mcontext.gregs[[REG_RIP]]" # Linux (x86_64)
+   pc_fields="$pc_fields uc_mcontext.sc_ip"            # Linux (ia64)
+   pc_fields="$pc_fields uc_mcontext.uc_regs->gregs[[PT_NIP]]" # Linux (ppc)
+   pc_fields="$pc_fields uc_mcontext.gregs[[R15]]"     # Linux (arm old [untested])
+   pc_fields="$pc_fields uc_mcontext.arm_pc"           # Linux (arm new [untested])
+   pc_fields="$pc_fields uc_mcontext.mc_eip"           # FreeBSD (i386)
+   pc_fields="$pc_fields uc_mcontext.mc_rip"           # FreeBSD (x86_64 [untested])
+   pc_fields="$pc_fields uc_mcontext.__gregs[[_REG_EIP]]"  # NetBSD (i386)
+   pc_fields="$pc_fields uc_mcontext.__gregs[[_REG_RIP]]"  # NetBSD (x86_64)
+   pc_fields="$pc_fields uc_mcontext->ss.eip"          # OS X (i386, <=10.4)
+   pc_fields="$pc_fields uc_mcontext->__ss.__eip"      # OS X (i386, >=10.5)
+   pc_fields="$pc_fields uc_mcontext->ss.rip"          # OS X (x86_64)
+   pc_fields="$pc_fields uc_mcontext->__ss.__rip"      # OS X (>=10.5 [untested])
+   pc_fields="$pc_fields uc_mcontext->ss.srr0"         # OS X (ppc, ppc64 [untested])
+   pc_fields="$pc_fields uc_mcontext->__ss.__srr0"     # OS X (>=10.5 [untested])
+   pc_field_found=false
+   for pc_field in $pc_fields; do
+     if ! $pc_field_found; then
+       AC_TRY_COMPILE([#define _GNU_SOURCE 1
+                       #include <ucontext.h>],
+                      [ucontext_t u; return u.$pc_field == 0;],
+                      AC_DEFINE_UNQUOTED(PC_FROM_UCONTEXT, $pc_field,
+                                         How to access the PC from a struct ucontext)
+                      AC_MSG_RESULT([$pc_field])
+                      pc_field_found=true)
+     fi
+   done
+   if ! $pc_field_found; then
+     pc_fields="           sc_eip"  # OpenBSD (i386)
+     pc_fields="$pc_fields sc_rip"  # OpenBSD (x86_64)
+     for pc_field in $pc_fields; do
+       if ! $pc_field_found; then
+         AC_TRY_COMPILE([#include <signal.h>],
+                        [ucontext_t u; return u.$pc_field == 0;],
+                        AC_DEFINE_UNQUOTED(PC_FROM_UCONTEXT, $pc_field,
+                                           How to access the PC from a struct ucontext)
+                        AC_MSG_RESULT([$pc_field])
+                        pc_field_found=true)
+       fi
+     done
+   fi
+   if ! $pc_field_found; then
+     AC_MSG_WARN(Could not find the PC.  Will not output failed addresses...)
+   fi])