From patchwork Fri Dec 6 15:54:05 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Bolton X-Patchwork-Id: 298066 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 01F552C009F for ; Sat, 7 Dec 2013 02:54:42 +1100 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:references:in-reply-to:subject:date:message-id :mime-version:content-type; q=dns; s=default; b=C9aF3ufh+TIqxE9R tv73ExRk2B9sdnfvjjSZ/EnlGRZQ8RQ2V1agj+hM8946bryq+Z9fbKLZdprJX9rA LMEa8ASrJTPR+NpkEYb5Ua48/BSlyw0qI9xwun1z7G6kWVurg4rWDXmF4wzBftKh 93ruAVuwCF2ApzQOB8eXHMUqAWA= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:references:in-reply-to:subject:date:message-id :mime-version:content-type; s=default; bh=CDgyHZolxzHfcFF24mEnNE PLNQk=; b=Cq1p+giZGzAys9xa/E68Em4qRunROqLmCMZC2y68lE1EMCfD8CGaX3 fp3P/Rel+COrIBMAr9JB8qYhJCBCTd0fJ1f/qMuMS2i06Vk6iOKFqqajOIgOiFbu XTUk8vqJlBnbnBZ3bNlaYZIHksUQFeXnFLamunOAS+oPJkHKELEzY= Received: (qmail 25020 invoked by alias); 6 Dec 2013 15:54:35 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 24906 invoked by uid 89); 6 Dec 2013 15:54:34 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.6 required=5.0 tests=AWL, BAYES_00, MSGID_MULTIPLE_AT, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=no version=3.3.2 X-HELO: service87.mimecast.com Received: from Unknown (HELO service87.mimecast.com) (91.220.42.44) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 06 Dec 2013 15:54:33 +0000 Received: from cam-owa2.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.21]) by service87.mimecast.com; Fri, 06 Dec 2013 15:54:24 +0000 Received: from E102352xp ([10.1.255.212]) by cam-owa2.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Fri, 6 Dec 2013 15:54:22 +0000 From: "Ian Bolton" To: "Richard Earnshaw" Cc: References: <000001cef10a$a35819b0$ea084d10$@bolton@arm.com> In-Reply-To: Subject: RE: [PATCH, ARM] Implement __builtin_trap Date: Fri, 6 Dec 2013 15:54:05 -0000 Message-ID: <000501cef29b$64588aa0$2d099fe0$@bolton@arm.com> MIME-Version: 1.0 X-MC-Unique: 113120615542425901 X-IsSubscribed: yes > > Hi, > > > > Currently, on ARM, you have to either call abort() or raise(SIGTRAP) > > to achieve a handy crash. > > > > This patch allows you to instead call __builtin_trap() which is much > > more efficient at falling over because it becomes just a single > > instruction that will trap for you. > > > > Two testcases have been added (for ARM and Thumb) and both pass. > > > > > > Note: This is a modified version of a patch originally submitted by > Mark > > Mitchell back in 2010, which came in response to PR target/59091. > > > > http://gcc.gnu.org/ml/gcc-patches/2010-09/msg00639.html > > http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59091 > > > > The main update, other than cosmetic differences, is that we've > chosen > > the same ARM encoding as LLVM for practical purposes. (The Thumb > > encoding in Mark's patch already matched LLVM.) > > > > > > OK for trunk? > > > > Cheers, > > Ian > > > > > > 2013-12-04 Ian Bolton > > Mark Mitchell > > > > gcc/ > > * config/arm/arm.md (trap): New pattern. > > * config/arm/types.md: Added a type for trap. > > > > testsuite/ > > * gcc.target/arm/builtin-trap.c: New test. > > * gcc.target/arm/thumb-builtin-trap.c: Likewise. > > > > This needs to set the conds attribute to "unconditional". Otherwise > the ARM backend might try to turn this into a conditional instruction. > > R. Thanks, Richard. I fixed it up, tested it and committed as trivial difference compared to what was approved already. diff --git a/gcc/config/arm/arm.md b/gcc/config/arm/arm.md index dd73366..934b859 100644 --- a/gcc/config/arm/arm.md +++ b/gcc/config/arm/arm.md @@ -9927,6 +9927,23 @@ (set_attr "type" "mov_reg")] ) +(define_insn "trap" + [(trap_if (const_int 1) (const_int 0))] + "" + "* + if (TARGET_ARM) + return \".inst\\t0xe7f000f0\"; + else + return \".inst\\t0xdeff\"; + " + [(set (attr "length") + (if_then_else (eq_attr "is_thumb" "yes") + (const_int 2) + (const_int 4))) + (set_attr "type" "trap") + (set_attr "conds" "unconditional")] +) + ;; Patterns to allow combination of arithmetic, cond code and shifts diff --git a/gcc/config/arm/types.md b/gcc/config/arm/types.md index 1c4b9e3..6351f08 100644 --- a/gcc/config/arm/types.md +++ b/gcc/config/arm/types.md @@ -152,6 +152,7 @@ ; store2 store 2 words to memory from arm registers. ; store3 store 3 words to memory from arm registers. ; store4 store 4 (or more) words to memory from arm registers. +; trap cause a trap in the kernel. ; udiv unsigned division. ; umaal unsigned multiply accumulate accumulate long. ; umlal unsigned multiply accumulate long. @@ -645,6 +646,7 @@ store2,\ store3,\ store4,\ + trap,\ udiv,\ umaal,\ umlal,\ diff --git a/gcc/testsuite/gcc.target/arm/builtin-trap.c b/gcc/testsuite/gcc.target/arm/builtin-trap.c new file mode 100644 index 0000000..4ff8d25 --- /dev/null +++ b/gcc/testsuite/gcc.target/arm/builtin-trap.c @@ -0,0 +1,10 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target arm32 } */ + +void +trap () +{ + __builtin_trap (); +} + +/* { dg-final { scan-assembler "0xe7f000f0" { target { arm_nothumb } } } } */ diff --git a/gcc/testsuite/gcc.target/arm/thumb-builtin-trap.c b/gcc/testsuite/gcc.target/arm/thumb-builtin-trap.c new file mode 100644 index 0000000..22e90e7 --- /dev/null +++ b/gcc/testsuite/gcc.target/arm/thumb-builtin-trap.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-options "-mthumb" } */ +/* { dg-require-effective-target arm_thumb1_ok } */ + +void +trap () +{ + __builtin_trap (); +} + +/* { dg-final { scan-assembler "0xdeff" } } */