From 9fe7e787adc4f41201c441014fbad318eaae6f80 Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Thu, 31 Jul 2014 13:07:19 -0700 Subject: [PATCH] Use __builtin_trap for ABORT_INSTRUCTION. --- ChangeLog | 6 ++++++ config.h.in | 4 ++++ configure | 38 ++++++++++++++++++++++++++++++++++++++ configure.ac | 17 +++++++++++++++++ sysdeps/generic/abort-instr.h | 31 ++++++++++++++++++++++++++++++- 5 files changed, 95 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index d50535c6fb..e359c139d9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2014-07-31 Roland McGrath + * config.h.in (HAVE_BUILTIN_TRAP): New #define to 0. + * configure.ac (libc_cv_builtin_trap): New test. + * configure: Regenerated. + * sysdeps/generic/abort-instr.h [HAVE_BUILTIN_TRAP] + (ABORT_INSTRUCTION): Define using __builtin_trap. + * nptl/pthreadP.h (SIGCANCEL, SIGTIMER, SIGSETXID, __xidcmd): Moved ... * sysdeps/unix/sysv/linux/nptl-signals.h: ... to this new file. * sysdeps/nptl/nptl-signals.h: New file. diff --git a/config.h.in b/config.h.in index d612a04fe8..7da1a9f6f8 100644 --- a/config.h.in +++ b/config.h.in @@ -249,6 +249,10 @@ /* The pt_chown binary is being built and used by grantpt. */ #define HAVE_PT_CHOWN 0 +/* Define if the compiler supports __builtin_trap without + any external dependencies such as making a function call. */ +#define HAVE_BUILTIN_TRAP 0 + /* ports/sysdeps/mips/configure.in */ /* Define if using the IEEE 754-2008 NaN encoding on the MIPS target. */ #undef HAVE_MIPS_NAN2008 diff --git a/configure b/configure index c8d2967f9e..646e0bc9af 100755 --- a/configure +++ b/configure @@ -7003,6 +7003,44 @@ if test $libc_cv_ehdr_start = yes; then fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for __builtin_trap with no external dependencies" >&5 +$as_echo_n "checking for __builtin_trap with no external dependencies... " >&6; } +if ${libc_cv_builtin_trap+:} false; then : + $as_echo_n "(cached) " >&6 +else + libc_cv_builtin_trap=no +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ +__builtin_trap () + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + +libc_undefs=`$NM -u conftest.o | + LC_ALL=C $AWK '$1 == "U" { print $2 | "sort -u"; next } { exit(1) }' \ + 2>&5` || { + as_fn_error $? "confusing output from $NM -u" "$LINENO" 5 +} +echo >&5 "libc_undefs='$libc_undefs'" +if test -z "$libc_undefs"; then + libc_cv_builtin_trap=yes +fi +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_builtin_trap" >&5 +$as_echo "$libc_cv_builtin_trap" >&6; } +if test $libc_cv_builtin_trap = yes; then + $as_echo "#define HAVE_BUILTIN_TRAP 1" >>confdefs.h + +fi + ### End of automated tests. ### Now run sysdeps configure fragments. diff --git a/configure.ac b/configure.ac index 566ecb276d..e89faa0dfe 100644 --- a/configure.ac +++ b/configure.ac @@ -1901,6 +1901,23 @@ if test $libc_cv_ehdr_start = yes; then AC_DEFINE([HAVE_EHDR_START]) fi +AC_CACHE_CHECK(for __builtin_trap with no external dependencies, + libc_cv_builtin_trap, [dnl +libc_cv_builtin_trap=no +AC_TRY_COMPILE([], [__builtin_trap ()], [ +libc_undefs=`$NM -u conftest.o | + LC_ALL=C $AWK '$1 == "U" { print $2 | "sort -u"; next } { exit(1) }' \ + 2>&AS_MESSAGE_LOG_FD` || { + AC_MSG_ERROR([confusing output from $NM -u]) +} +echo >&AS_MESSAGE_LOG_FD "libc_undefs='$libc_undefs'" +if test -z "$libc_undefs"; then + libc_cv_builtin_trap=yes +fi])]) +if test $libc_cv_builtin_trap = yes; then + AC_DEFINE([HAVE_BUILTIN_TRAP]) +fi + ### End of automated tests. ### Now run sysdeps configure fragments. diff --git a/sysdeps/generic/abort-instr.h b/sysdeps/generic/abort-instr.h index 106a330b2b..4ac11d2ea5 100644 --- a/sysdeps/generic/abort-instr.h +++ b/sysdeps/generic/abort-instr.h @@ -1,2 +1,31 @@ +/* Magic instruction to crash quickly and reliably. Generic/stub version. + Copyright (C) 2014 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 + . */ + +#ifndef _ABORT_INSTR_H +#define _ABORT_INSTR_H 1 + +/* If the compiler provides the generic way to generate the right + instruction, we can use that without any machine-specific knowledge. */ +#if HAVE_BUILTIN_TRAP +# define ABORT_INSTRUCTION __builtin_trap () +#else /* We cannot give any generic instruction to crash the program. - abort() will have to make sure it never returns. */ + abort will have to make sure it never returns. */ +#endif + +#endif /* abort-instr.h */ -- 2.11.4.GIT