From patchwork Fri Jul 20 10:15:27 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julian Brown X-Patchwork-Id: 172194 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]) by ozlabs.org (Postfix) with SMTP id 3228E2C0267 for ; Fri, 20 Jul 2012 20:15:56 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1343384158; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Date:From:To:CC:Subject:Message-ID:MIME-Version: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=IBvGj7m ALe7Z/88fYUC7896O5is=; b=TEheX5wBM/OPct5mj4WWyykWNmhydXaiaxFBsUP WZfnLsCDyd6o2fMgrgy++PDWxGqLDOWdTSJ9cMwcQqFJfhdkAnUog/qxju1BDRO7 RwNODChKSyMXKJ9DkZm5Mj7Pjg2ZK6jNaS2TxA5V2wr+3jQ6IcyUlF/u5pb5CAIc EUpc= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Received:Date:From:To:CC:Subject:Message-ID:MIME-Version:Content-Type:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=ba54RTbAS9FCVfv5smsm7J8JJN4DdNaMuc9pnW57s5VVWhH4MNw26FkZJNip2f Zt1VVfr5CSWq5kJ/SFnlX+w/mWUIytSfDS3c39vc9JdeMPn/cuSr5u9i9frG+DfG Zl/HMxvah4Vaeb2KwUHeHWkR6GtTNAgig822bxNepurQo=; Received: (qmail 27787 invoked by alias); 20 Jul 2012 10:15:53 -0000 Received: (qmail 27776 invoked by uid 22791); 20 Jul 2012 10:15:51 -0000 X-SWARE-Spam-Status: No, hits=-1.7 required=5.0 tests=AWL, BAYES_00, FROM_12LTRDOM, KHOP_RCVD_UNTRUST, RCVD_IN_HOSTKARMA_W, RCVD_IN_HOSTKARMA_WL, TW_IV X-Spam-Check-By: sourceware.org Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 20 Jul 2012 10:15:37 +0000 Received: from svr-orw-fem-01.mgc.mentorg.com ([147.34.98.93]) by relay1.mentorg.com with esmtp id 1SsAFE-00047c-2P from Julian_Brown@mentor.com ; Fri, 20 Jul 2012 03:15:36 -0700 Received: from SVR-IES-FEM-02.mgc.mentorg.com ([137.202.0.106]) by svr-orw-fem-01.mgc.mentorg.com over TLS secured channel with Microsoft SMTPSVC(6.0.3790.4675); Fri, 20 Jul 2012 03:15:35 -0700 Received: from octopus (137.202.0.76) by SVR-IES-FEM-02.mgc.mentorg.com (137.202.0.106) with Microsoft SMTP Server id 14.1.289.1; Fri, 20 Jul 2012 11:15:33 +0100 Date: Fri, 20 Jul 2012 11:15:27 +0100 From: Julian Brown To: CC: , Subject: [PATCH, ARM] Don't pull in unwinder for 64-bit division routines Message-ID: <20120720111527.16dea84e@octopus> MIME-Version: 1.0 X-IsSubscribed: yes 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 Hi, This (old!) patch avoids uselessly pulling in the unwinder for 64-bit division routines. I last posted it here: http://gcc.gnu.org/ml/gcc-patches/2009-10/msg01618.html Other people have noticed the same issue, e.g.: http://gcc.gnu.org/ml/gcc-help/2011-03/msg00187.html Note that we take special care already for the case where division-by-zero throws an exception: we tailcall the division-by-zero handler at the head of the 64-bit division helper routines, so never create a stack frame which needs to be unwound. On ARM, division by zero can trapped by defining magic __aeabi_[il]div0 functions. See here: http://gcc.gnu.org/ml/gcc-patches/2009-10/msg01661.html Unfortunately, despite that, throwing an exception from the division-by-zero handler functions doesn't appear to work at present -- either with or without the current patch. I'm not intending to tackle that now (see attached program -- which exits with "terminate called after throwing an instance of 'int'" for me). I'm no C++ expert, so I might have done something dumb :-). Anyway: this revised version of the patch removes the strange libgcc Makefile-fragment changes, the equivalent of which have since been incorporated into mainline GCC now anyway, so the patch is somewhat more straightforward than it was previously. The patch allows a trivial program using 64-bit division (on bare metal) to shrink quite considerably: $ arm-none-eabi-size div64 text data bss dec hex filename 13120 2404 276 15800 3db8 div64 $ arm-none-eabi-size div64-unpatched text data bss dec hex filename 20064 2404 276 22744 58d8 div64-unpatched OK to apply? Thanks, Julian ChangeLog libgcc/ * config.host (arm*-*-linux-*eabi, arm*-*-uclinux*eabi) (arm*-*-eabi*, arm*-*-symbianelf*, arm*-*-rtemseabi*): Add arm/t-divmod-ef to tmake_file. * Makefile.in (LIB2_DIVMOD_EXCEPTION_FLAGS): Default to -fexceptions -fnon-call-exceptions if not defined. ($(lib2-divmod-o), $(lib2-divmod-s-o)): Use above. * config/arm/t-divmod-ef: New file. gcc/testsuite/ * gcc.target/arm/div64-unwinding.c: New test. Index: libgcc/config.host =================================================================== --- libgcc/config.host (revision 189656) +++ libgcc/config.host (working copy) @@ -317,7 +317,7 @@ arm*-*-linux*) # ARM GNU/Linux with EL tmake_file="${tmake_file} arm/t-arm t-fixedpoint-gnu-prefix" case ${host} in arm*-*-linux-*eabi) - tmake_file="${tmake_file} arm/t-elf arm/t-bpabi arm/t-linux-eabi t-slibgcc-libgcc" + tmake_file="${tmake_file} arm/t-elf arm/t-bpabi arm/t-linux-eabi arm/t-divmod-ef t-slibgcc-libgcc" tm_file="$tm_file arm/bpabi-lib.h" unwind_header=config/arm/unwind-arm.h ;; @@ -331,7 +331,7 @@ arm*-*-uclinux*) # ARM ucLinux tmake_file="${tmake_file} t-fixedpoint-gnu-prefix" case ${host} in arm*-*-uclinux*eabi) - tmake_file="${tmake_file} arm/t-bpabi" + tmake_file="${tmake_file} arm/t-bpabi arm/t-divmod-ef" tm_file="$tm_file arm/bpabi-lib.h" unwind_header=config/arm/unwind-arm.h ;; @@ -344,7 +344,7 @@ arm*-*-ecos-elf) extra_parts="$extra_parts crti.o crtn.o" ;; arm*-*-eabi* | arm*-*-symbianelf* | arm*-*-rtemseabi*) - tmake_file="${tmake_file} arm/t-arm arm/t-elf t-fixedpoint-gnu-prefix" + tmake_file="${tmake_file} arm/t-arm arm/t-elf arm/t-divmod-ef t-fixedpoint-gnu-prefix" tm_file="$tm_file arm/bpabi-lib.h" case ${host} in arm*-*-eabi* | arm*-*-rtemseabi*) Index: libgcc/Makefile.in =================================================================== --- libgcc/Makefile.in (revision 189656) +++ libgcc/Makefile.in (working copy) @@ -497,18 +497,24 @@ libgcc-s-objects += $(patsubst %,%_s$(ob endif endif +ifeq ($(LIB2_DIVMOD_EXCEPTION_FLAGS),) +# Provide default flags for compiling divmod functions, if they haven't been +# set already by a target-specific Makefile fragment. +LIB2_DIVMOD_EXCEPTION_FLAGS := -fexceptions -fnon-call-exceptions +endif + # Build LIB2_DIVMOD_FUNCS. lib2-divmod-o = $(patsubst %,%$(objext),$(LIB2_DIVMOD_FUNCS)) $(lib2-divmod-o): %$(objext): $(srcdir)/libgcc2.c $(gcc_compile) -DL$* -c $< \ - -fexceptions -fnon-call-exceptions $(vis_hide) + $(LIB2_DIVMOD_EXCEPTION_FLAGS) $(vis_hide) libgcc-objects += $(lib2-divmod-o) ifeq ($(enable_shared),yes) lib2-divmod-s-o = $(patsubst %,%_s$(objext),$(LIB2_DIVMOD_FUNCS)) $(lib2-divmod-s-o): %_s$(objext): $(srcdir)/libgcc2.c $(gcc_s_compile) -DL$* -c $< \ - -fexceptions -fnon-call-exceptions + $(LIB2_DIVMOD_EXCEPTION_FLAGS) libgcc-s-objects += $(lib2-divmod-s-o) endif Index: libgcc/config/arm/t-divmod-ef =================================================================== --- libgcc/config/arm/t-divmod-ef (revision 0) +++ libgcc/config/arm/t-divmod-ef (revision 0) @@ -0,0 +1,4 @@ +# On ARM, specifying -fnon-call-exceptions will needlessly pull in +# the unwinder in simple programs which use 64-bit division. Omitting +# the option is safe. +LIB2_DIVMOD_EXCEPTION_FLAGS := -fexceptions Index: gcc/testsuite/gcc.target/arm/div64-unwinding.c =================================================================== --- gcc/testsuite/gcc.target/arm/div64-unwinding.c (revision 0) +++ gcc/testsuite/gcc.target/arm/div64-unwinding.c (revision 0) @@ -0,0 +1,24 @@ +/* Performing a 64-bit division should not pull in the unwinder. */ + +/* { dg-do run } */ +/* { dg-options "-O0" } */ + +#include + +long long +foo (long long c, long long d) +{ + return c/d; +} + +long long x = 0; +long long y = 1; + +extern int (*_Unwind_RaiseException) (void *) __attribute__((weak)); + +int main(void) +{ + if (&_Unwind_RaiseException != NULL) + abort ();; + return foo (x, y); +}