From patchwork Wed Sep 8 04:12:51 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: RFA: ARM: Implement __builtin_trap Date: Tue, 07 Sep 2010 18:12:51 -0000 From: Mark Mitchell X-Patchwork-Id: 64089 Message-Id: <20100908041251.3586C5664F5@henry1.codesourcery.com> To: gcc-patches@gcc.gnu.org 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 * config/arm/arm.md (trap): New pattern. 2010-09-07 Mark Mitchell * 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 popd 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)))] +) ;; Patterns to allow combination of arithmetic, cond code and shifts