public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* RFA: ARM: Implement __builtin_trap
@ 2010-09-08  6:10 Mark Mitchell
  2010-09-08 23:05 ` Mike Stump
  0 siblings, 1 reply; 16+ messages in thread
From: Mark Mitchell @ 2010-09-08  6:10 UTC (permalink / raw)
  To: gcc-patches, rearnshaw, paul


This patch implements __builtin_trap for ARM.  The default, for
architectures that do not provide a "trap" instruction, is to call
abort.  Executing an invalid instruction is a faster, smaller way to
crash.

OK to apply?

--
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713

2010-09-07  Mark Mitchell  <mark@codesourcery.com>

	* config/arm/arm.md (trap): New pattern.

2010-09-07  Mark Mitchell  <mark@codesourcery.com>

	* gcc.target/arm/builtin-trap.c: New.
	* gcc.target/arm/thumb-builtin-trap.c: Likewise.

# gcc diff
pushd /scratch/mitchell/builds/fsf-mainline/src/gcc-mainline
svn diff
Index: gcc/testsuite/gcc.target/arm/thumb-builtin-trap.c
===================================================================
--- gcc/testsuite/gcc.target/arm/thumb-builtin-trap.c	(revision 0)
+++ gcc/testsuite/gcc.target/arm/thumb-builtin-trap.c	(revision 0)
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+/* { dg-options "-mthumb" }  */
+
+void trap ()
+{
+  __builtin_trap ();
+}
+
+/* { dg-final { scan-assembler "0xdeff" } } */
Index: gcc/testsuite/gcc.target/arm/builtin-trap.c
===================================================================
--- gcc/testsuite/gcc.target/arm/builtin-trap.c	(revision 0)
+++ gcc/testsuite/gcc.target/arm/builtin-trap.c	(revision 0)
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target arm32 } */
+
+void trap ()
+{
+  __builtin_trap ();
+}
+
+/* { dg-final { scan-assembler "0xe7ffffff" } } */
Index: gcc/config/arm/arm.md
===================================================================
--- gcc/config/arm/arm.md	(revision 163924)
+++ gcc/config/arm/arm.md	(working copy)
@@ -8496,6 +8496,26 @@
 		      (const_int 4)))]
 )
 
+;; Generate an invalid instruction.  The instructions chosen are
+;; documented as permanently UNDEFINED, so we can rely on the fact
+;; that no future version of the architecture will use them.  The
+;; instructions used are chosen so as to be distinct from he
+;; instructions that the Linux kernel interprets as software
+;; breakpoints.
+(define_insn "trap"
+  [(trap_if (const_int 1) (const_int 0))]
+  ""
+  "*
+  if (TARGET_ARM)
+    return \".inst\\t0xe7ffffff\";
+  else
+    return \".inst\\t0xdeff\";
+  "
+  [(set (attr "length")
+	(if_then_else (eq_attr "is_thumb" "yes")
+		      (const_int 2)
+		      (const_int 4)))]
+)
 \f
 ;; Patterns to allow combination of arithmetic, cond code and shifts
 
popd

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

end of thread, other threads:[~2010-09-28 14:59 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-09-08  6:10 RFA: ARM: Implement __builtin_trap Mark Mitchell
2010-09-08 23:05 ` Mike Stump
2010-09-08 23:18   ` Mark Mitchell
2010-09-09 18:34     ` David Daney
2010-09-09 18:46       ` Mark Mitchell
2010-09-09 18:49         ` Chris Lattner
2010-09-09 19:23           ` Mark Mitchell
2010-09-09 21:59             ` Chris Lattner
2010-09-09 22:27               ` Anton Korobeynikov
2010-09-10 10:13               ` Richard Earnshaw
2010-09-10 13:12                 ` Mikael Pettersson
2010-09-10 14:34                 ` Mark Mitchell
2010-09-28 18:07                   ` Mark Mitchell
2010-09-09 19:30     ` Daniel Jacobowitz
2010-09-09 21:25       ` Mark Mitchell
2010-09-09 21:49         ` Daniel Jacobowitz

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).