Commit 4cd83814 authored by 's avatar

Add m4/pc_from_ucontext.m4. It supports NetBSD and OpenBSD as well.

Also, update the version of acx_pthread.m4


git-svn-id: https://google-glog.googlecode.com/svn/trunk@55 eb4d4688-79bd-11dd-afb4-1d65580434c0
parent 424c6fc5
...@@ -67,6 +67,7 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/ac_have_attribute.m4 \ ...@@ -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/ac_rwlock.m4 $(top_srcdir)/m4/acx_pthread.m4 \
$(top_srcdir)/m4/google_namespace.m4 \ $(top_srcdir)/m4/google_namespace.m4 \
$(top_srcdir)/m4/namespaces.m4 \ $(top_srcdir)/m4/namespaces.m4 \
$(top_srcdir)/m4/pc_from_ucontext.m4 \
$(top_srcdir)/m4/stl_namespace.m4 \ $(top_srcdir)/m4/stl_namespace.m4 \
$(top_srcdir)/m4/using_operator.m4 $(top_srcdir)/configure.ac $(top_srcdir)/m4/using_operator.m4 $(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
......
...@@ -7537,5 +7537,6 @@ m4_include([m4/ac_rwlock.m4]) ...@@ -7537,5 +7537,6 @@ m4_include([m4/ac_rwlock.m4])
m4_include([m4/acx_pthread.m4]) m4_include([m4/acx_pthread.m4])
m4_include([m4/google_namespace.m4]) m4_include([m4/google_namespace.m4])
m4_include([m4/namespaces.m4]) m4_include([m4/namespaces.m4])
m4_include([m4/pc_from_ucontext.m4])
m4_include([m4/stl_namespace.m4]) m4_include([m4/stl_namespace.m4])
m4_include([m4/using_operator.m4]) m4_include([m4/using_operator.m4])
This diff is collapsed.
...@@ -172,41 +172,7 @@ AC_DEFINE_GOOGLE_NAMESPACE(google) ...@@ -172,41 +172,7 @@ AC_DEFINE_GOOGLE_NAMESPACE(google)
AC_CXX_USING_OPERATOR AC_CXX_USING_OPERATOR
# We want to access the "PC" (Program Counter) register from a struct AC_PC_FROM_UCONTEXT(AC_MSG_WARN(Could not find the PC. Will not output failed addresses...))
# 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
# These are what's needed by logging.h.in and raw_logging.h.in # These are what's needed by logging.h.in and raw_logging.h.in
AC_SUBST(ac_google_start_namespace) AC_SUBST(ac_google_start_namespace)
......
# This was retrieved from # 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?) # 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 @synopsis ACX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
dnl dnl
...@@ -231,108 +236,113 @@ if test "x$acx_pthread_ok" = xyes; then ...@@ -231,108 +236,113 @@ if test "x$acx_pthread_ok" = xyes; then
PTHREAD_CC=$CC PTHREAD_CC=$CC
fi fi
# The next part tries to detect GCC inconsistency with -shared on some # The next part tries to detect GCC inconsistency with -shared on some
# architectures and systems. The problem is that in certain # architectures and systems. The problem is that in certain
# configurations, when -shared is specified, GCC "forgets" to # configurations, when -shared is specified, GCC "forgets" to
# internally use various flags which are still necessary. # internally use various flags which are still necessary.
AC_MSG_CHECKING([whether to check for GCC pthread/shared inconsistencies]) #
check_inconsistencies=yes # Prepare the flags
case "${host_cpu}-${host_os}" in #
*-darwin*) check_inconsistencies=no ;; save_CFLAGS="$CFLAGS"
esac save_LIBS="$LIBS"
if test x"$GCC" != xyes -o "x$check_inconsistencies" != xyes ; then save_CC="$CC"
AC_MSG_RESULT([no])
else # Try with the flags determined by the earlier checks.
AC_MSG_RESULT([yes]) #
# -Wl,-z,defs forces link-time symbol resolution, so that the
# In order not to create several levels of indentation, we test # linking checks with -shared actually have any value
# the value of "$ok" until we find out the cure or run out of #
# ideas. # FIXME: -fPIC is required for -shared on many architectures,
ok="no" # 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"
# Prepare the flags LIBS="$PTHREAD_LIBS $LIBS"
# CC="$PTHREAD_CC"
save_CFLAGS="$CFLAGS"
save_LIBS="$LIBS" # In order not to create several levels of indentation, we test
save_CC="$CC" # the value of "$done" until we find the cure or run out of ideas.
# Try with the flags determined by the earlier checks. done="no"
#
# -Wl,-z,defs forces link-time symbol resolution, so that the # First, make sure the CFLAGS we added are actually accepted by our
# linking checks with -shared actually have any value # compiler. If not (and OS X's ld, for instance, does not accept -z),
# # then we can't do this test.
# FIXME: -fPIC is required for -shared on many architectures, if test x"$done" = xno; then
# so we specify it here, but the right way would probably be to AC_MSG_CHECKING([whether to check for GCC pthread/shared inconsistencies])
# properly detect whether it is actually required. AC_TRY_LINK(,, , [done=yes])
CFLAGS="-shared -fPIC -Wl,-z,defs $CFLAGS $PTHREAD_CFLAGS"
LIBS="$PTHREAD_LIBS $LIBS" if test "x$done" = xyes ; then
CC="$PTHREAD_CC" AC_MSG_RESULT([no])
else
AC_MSG_CHECKING([whether -pthread is sufficient with -shared]) AC_MSG_RESULT([yes])
AC_TRY_LINK([#include <pthread.h>], fi
[pthread_t th; pthread_join(th, 0); fi
pthread_attr_init(0); pthread_cleanup_push(0, 0);
pthread_create(0,0,0,0); pthread_cleanup_pop(0); ], if test x"$done" = xno; then
[ok=yes]) AC_MSG_CHECKING([whether -pthread is sufficient with -shared])
AC_TRY_LINK([#include <pthread.h>],
if test "x$ok" = xyes; then [pthread_t th; pthread_join(th, 0);
AC_MSG_RESULT([yes]) pthread_attr_init(0); pthread_cleanup_push(0, 0);
else pthread_create(0,0,0,0); pthread_cleanup_pop(0); ],
AC_MSG_RESULT([no]) [done=yes])
fi
if test "x$done" = xyes; then
# AC_MSG_RESULT([yes])
# Linux gcc on some architectures such as mips/mipsel forgets else
# about -lpthread AC_MSG_RESULT([no])
# fi
if test x"$ok" = xno; then fi
AC_MSG_CHECKING([whether -lpthread fixes that])
LIBS="-lpthread $PTHREAD_LIBS $save_LIBS" #
AC_TRY_LINK([#include <pthread.h>], # Linux gcc on some architectures such as mips/mipsel forgets
[pthread_t th; pthread_join(th, 0); # about -lpthread
pthread_attr_init(0); pthread_cleanup_push(0, 0); #
pthread_create(0,0,0,0); pthread_cleanup_pop(0); ], if test x"$done" = xno; then
[ok=yes]) AC_MSG_CHECKING([whether -lpthread fixes that])
LIBS="-lpthread $PTHREAD_LIBS $save_LIBS"
if test "x$ok" = xyes; then AC_TRY_LINK([#include <pthread.h>],
AC_MSG_RESULT([yes]) [pthread_t th; pthread_join(th, 0);
PTHREAD_LIBS="-lpthread $PTHREAD_LIBS" pthread_attr_init(0); pthread_cleanup_push(0, 0);
else pthread_create(0,0,0,0); pthread_cleanup_pop(0); ],
AC_MSG_RESULT([no]) [done=yes])
fi
fi if test "x$done" = xyes; then
# AC_MSG_RESULT([yes])
# FreeBSD 4.10 gcc forgets to use -lc_r instead of -lc PTHREAD_LIBS="-lpthread $PTHREAD_LIBS"
# else
if test x"$ok" = xno; then AC_MSG_RESULT([no])
AC_MSG_CHECKING([whether -lc_r fixes that]) fi
LIBS="-lc_r $PTHREAD_LIBS $save_LIBS" fi
AC_TRY_LINK([#include <pthread.h>], #
[pthread_t th; pthread_join(th, 0); # FreeBSD 4.10 gcc forgets to use -lc_r instead of -lc
pthread_attr_init(0); pthread_cleanup_push(0, 0); #
pthread_create(0,0,0,0); pthread_cleanup_pop(0); ], if test x"$done" = xno; then
[ok=yes]) AC_MSG_CHECKING([whether -lc_r fixes that])
LIBS="-lc_r $PTHREAD_LIBS $save_LIBS"
if test "x$ok" = xyes; then AC_TRY_LINK([#include <pthread.h>],
AC_MSG_RESULT([yes]) [pthread_t th; pthread_join(th, 0);
PTHREAD_LIBS="-lc_r $PTHREAD_LIBS" pthread_attr_init(0); pthread_cleanup_push(0, 0);
else pthread_create(0,0,0,0); pthread_cleanup_pop(0); ],
AC_MSG_RESULT([no]) [done=yes])
fi
fi if test "x$done" = xyes; then
if test x"$ok" = xno; then AC_MSG_RESULT([yes])
# OK, we have run out of ideas PTHREAD_LIBS="-lc_r $PTHREAD_LIBS"
AC_MSG_WARN([Impossible to determine how to use pthreads with shared libraries]) else
AC_MSG_RESULT([no])
# so it's not safe to assume that we may use pthreads fi
acx_pthread_ok=no fi
fi if test x"$done" = xno; then
# OK, we have run out of ideas
CFLAGS="$save_CFLAGS" AC_MSG_WARN([Impossible to determine how to use pthreads with shared libraries])
LIBS="$save_LIBS"
CC="$save_CC" # so it's not safe to assume that we may use pthreads
fi acx_pthread_ok=no
fi
CFLAGS="$save_CFLAGS"
LIBS="$save_LIBS"
CC="$save_CC"
else else
PTHREAD_CC="$CC" PTHREAD_CC="$CC"
fi 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).
# 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])
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment