public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Josef Wolf <jw@raven.inka.de>
To: gcc-help@gcc.gnu.org
Subject: Re: Crash when cross compiling for ARM with GCC-8-2-0 and -ftree-loop-distribute-patterns
Date: Thu, 17 Oct 2019 14:10:00 -0000	[thread overview]
Message-ID: <20191017140423.GD11171@raven.inka.de> (raw)
In-Reply-To: <b0d6f7dd-cca3-c605-b205-43ba59119183@marco.de>

Tahnks for your help, Matthias!

On Thu, Oct 17, 2019 at 02:37:11PM +0200, Matthias Pfaller wrote:

> Have a look at "arm-eabi-objdump -S -d main.elf". Sometimes this is
> quite revealing.

Yeah.

> Are you using openocd or something similar for debugging?

Yes. Openocd with gdb.

> You are compiling for a cortex-m0/3/4?

Cortex-m3

> Are you single stepping through the complete startup sequence or do set a
> break point ath the top of memset (i.e. are break points working at all)?

Breakpoints are working. But there is only a limited set of hardware
breakpoints (four, AFAIR).

> Interrupts are still disabled?

There are no interrupt sources enabled yet. But I wonder why the CPU is not
starting up with disabled IRQs? I am new to the ARM architecture, but every
other architecture I know of would come out from reset with disabled
interrupts... I'd expect BASEPRI and PRIMASK to be set to sane values before
the first instruction is executed?

Anyway, explicitly calling __set_PRIMASK(1) did also not help, although
primask ist still set when the processor crashes.

> 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 <memset+12>
  => 0x0800100e <+6>:    uxtb r1, r1
     0x08001010 <+8>:    bl   0x8001008 <memset>
     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, <memset+18>
         add    r2, r0
         subs   r2, #1
         uxtb   r1, r1
         subs   r3, r0, #1
  <+10>: strb.w r1, [r3, #1]!
         cmp    r3, r2
         bne.n  <memset+10>
  <+18>: bx     lr

> I usually start toggling output lines when I'm stuck like this...

?


-- 
Josef Wolf
jw@raven.inka.de

  reply	other threads:[~2019-10-17 14:10 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-16 13:19 Josef Wolf
2019-10-16 13:30 ` Matthias Pfaller
2019-10-17  8:10   ` Josef Wolf
2019-10-16 18:18 ` Martin Sebor
2019-10-17 11:40   ` Josef Wolf
2019-10-17 12:37     ` Matthias Pfaller
2019-10-17 14:10       ` Josef Wolf [this message]
2019-10-17 14:55         ` Richard Earnshaw (lists)
2019-10-18  9:00           ` Josef Wolf
2019-10-18 10:26             ` Richard Earnshaw (lists)
2019-10-18 12:10               ` Josef Wolf
2019-10-18 13:07                 ` Segher Boessenkool
2019-10-18 13:40                   ` Josef Wolf
2019-10-18 12:50               ` Josef Wolf
2019-10-18 14:04                 ` Richard Earnshaw (lists)
2019-10-18  9:10     ` Propagating addresses from linker to the runtie (was: Re: Crash when cross compiling for ARM with GCC-8-2-0 and) -ftree-loop-distribute-patterns Josef Wolf
2019-10-18  9:15       ` Propagating addresses from linker to the runtie Florian Weimer
2019-10-18  9:50         ` Josef Wolf
2019-10-18 10:47           ` Florian Weimer
2019-10-18 12:51             ` Segher Boessenkool
2019-10-18 12:56               ` Florian Weimer
2019-10-18 14:14                 ` Segher Boessenkool
2019-10-18 14:34                   ` Florian Weimer
2019-10-18 13:30               ` Josef Wolf
2019-10-18 14:20                 ` Segher Boessenkool
2019-10-18 13:10   ` Crash when cross compiling for ARM with GCC-8-2-0 and -ftree-loop-distribute-patterns Josef Wolf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191017140423.GD11171@raven.inka.de \
    --to=jw@raven.inka.de \
    --cc=gcc-help@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).