From patchwork Thu Jul 31 20:32:51 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roland McGrath X-Patchwork-Id: 2263 Received: (qmail 30090 invoked by alias); 31 Jul 2014 20:32:56 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 30028 invoked by uid 89); 31 Jul 2014 20:32:55 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=AWL, BAYES_00 autolearn=ham version=3.3.2 X-HELO: topped-with-meat.com MIME-Version: 1.0 From: Roland McGrath To: "GNU C. Library" Subject: [COMMITTED PATCH] Use __builtin_trap for ABORT_INSTRUCTION. Message-Id: <20140731203251.10CE62C3996@topped-with-meat.com> Date: Thu, 31 Jul 2014 13:32:51 -0700 (PDT) X-CMAE-Score: 0 X-CMAE-Analysis: v=2.1 cv=SvUDtp+0 c=1 sm=1 tr=0 a=WkljmVdYkabdwxfqvArNOQ==:117 a=14OXPxybAAAA:8 a=DPQ_CAtQJ4QA:10 a=TPu5erhaZIwA:10 a=Z6MIti7PxpgA:10 a=kj9zAlcOel0A:10 a=hOe2yjtxAAAA:8 a=mDV3o1hIAAAA:8 a=iN35w5JaVxb_QXN1aMgA:9 a=CjuIK1q_8ugA:10 Verified no code changes on x86_64-linux-gnu (where the generic abort-instr.h is not used, though the configure test succeeds) and arm-linux-gnueabihf (where the generic file is used, but the configure test fails under gcc-4.6 because __builtin_trap calls abort). * 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. --- 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 --- 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. --- 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. --- 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 */