From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 124963 invoked by alias); 18 Oct 2019 10:26:04 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 124955 invoked by uid 89); 18 Oct 2019 10:26:04 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-5.9 required=5.0 tests=AWL,BAYES_00,SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: foss.arm.com Received: from Unknown (HELO foss.arm.com) (217.140.110.172) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 18 Oct 2019 10:26:03 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 70C8DAB6; Fri, 18 Oct 2019 03:25:55 -0700 (PDT) Received: from e120077-lin.cambridge.arm.com (e120077-lin.cambridge.arm.com [10.2.206.225]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E2C9A3F6C4; Fri, 18 Oct 2019 03:25:54 -0700 (PDT) Subject: Re: Crash when cross compiling for ARM with GCC-8-2-0 and -ftree-loop-distribute-patterns To: Josef Wolf , gcc-help@gcc.gnu.org References: <20191016131759.GA11171@raven.inka.de> <5b75d9aa-9f33-2ec6-ff46-713b113b3539@gmail.com> <20191017113157.GC11171@raven.inka.de> <20191017140423.GD11171@raven.inka.de> <20191018085314.GE11171@raven.inka.de> From: "Richard Earnshaw (lists)" Message-ID: Date: Fri, 18 Oct 2019 10:26:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <20191018085314.GE11171@raven.inka.de> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-SW-Source: 2019-10/txt/msg00076.txt.bz2 On 18/10/2019 09:53, Josef Wolf wrote: > Thanks for your help, Richard! > > On Thu, Oct 17, 2019 at 03:55:31PM +0100, Richard Earnshaw (lists) wrote: >> On 17/10/2019 15:04, Josef Wolf wrote: >>> On Thu, Oct 17, 2019 at 02:37:11PM +0200, Matthias Pfaller wrote: >>>> Why is the stack pointer so low at this point of execution? Using >>>> 0x20018000-0x20017d20 == 0x2e0 bytes of stack seems a little excessive >>>> for just one call. >>> >>> Ah!... Looks like you've spotted the problem! Actually, the SP is decremented >>> on every cycle of the loop: >>> >>> (gdb) disass >>> Dump of assembler code for function memset: >>> 0x08001008 <+0>: push {r4, lr} >>> 0x0800100a <+2>: mov r4, r0 >>> 0x0800100c <+4>: cbz r2, 0x8001014 >>> => 0x0800100e <+6>: uxtb r1, r1 >>> 0x08001010 <+8>: bl 0x8001008 >>> 0x08001014 <+12>: mov r0, r4 >>> 0x08001016 <+14>: pop {r4, pc} >>> End of assembler dump. >>> >>> This looks REALLY suspicous to me. Every cycle of the loop in memset() is >>> pushing something onto the stack?!? >>> >>> Without the -ftree-loop-distribute-patterns option, the memset() function >>> looks entirely different: >>> >>> cbz r2, >>> add r2, r0 >>> subs r2, #1 >>> uxtb r1, r1 >>> subs r3, r0, #1 >>> <+10>: strb.w r1, [r3, #1]! >>> cmp r3, r2 >>> bne.n >>> <+18>: bx lr >> >> The compiler has spotted that you've written something that acts like memset >> and optimized it into a function call to memset. So now you're recursing to >> oblivion. Try adding -fno-builtin-memset to your compile options. > > This sounds reasonable, and I was actually thinking it would solve the > problem. > > Unfortunately, -fno-built-memset doesn't have any effect. The same code is > generated. > Ah, yes. Looking at some libc sources it puts an explicit optimization attribute onto the memset (and similar mem... functions) to disable -ftree-loop-distribute-patterns for such functions. So something like void * __attribute__ ((__optimize__ ("-fno-tree-loop-distribute-patterns"))) memset (void *s, int c, size_t n) { int i; for (i=0; i