public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/98627] New: GCC emits unaligned memory access instructions causing address error exceptions with the 68000 architecture
@ 2021-01-11 17:22 noring at nocrew dot org
  2021-01-11 18:04 ` [Bug c/98627] " schwab@linux-m68k.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: noring at nocrew dot org @ 2021-01-11 17:22 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98627

            Bug ID: 98627
           Summary: GCC emits unaligned memory access instructions causing
                    address error exceptions with the 68000 architecture
           Product: gcc
           Version: 9.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: noring at nocrew dot org
  Target Milestone: ---

The 68000 architecture requires that (16-bit) word and (32-bit) long memory
accesses are aligned with even addresses, but GCC frequently emits code that
breaks this when compiling with optimisations (O1 or higher). This causes
address error exceptions, which are fatal errors that crash programs.

For example, consider

struct s { char a, b, c, d, e; };
struct s f(char a)
{
        return (struct s) { .a = a, .d = 'd' };
}

that GCC with O1 will compile into

00000000 <f>:
   0:   2049            moveal %a1,%a0
   2:   202f 0004       movel %sp@(4),%d0
   6:   42a9 0001       clrl %a1@(1)        /* <<<--- unaligned long clear */
   a:   1280            moveb %d0,%a1@
   c:   137c 0064 0003  moveb #100,%a1@(3)
  12:   4e75            rts

where offset 6 has "clrl %a1@(1)", which is an unaligned 32-bit long clear. GCC
can emit several similar variants of this, for example unaligned 16-bit word
clears, and possibly others.

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2021-01-12 19:20 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-11 17:22 [Bug c/98627] New: GCC emits unaligned memory access instructions causing address error exceptions with the 68000 architecture noring at nocrew dot org
2021-01-11 18:04 ` [Bug c/98627] " schwab@linux-m68k.org
2021-01-11 19:12 ` noring at nocrew dot org
2021-01-11 19:24 ` schwab@linux-m68k.org
2021-01-11 20:02 ` noring at nocrew dot org
2021-01-11 20:13 ` schwab@linux-m68k.org
2021-01-11 20:36 ` noring at nocrew dot org
2021-01-11 20:41 ` schwab@linux-m68k.org
2021-01-12 16:26 ` mikpelinux at gmail dot com
2021-01-12 19:20 ` noring at nocrew dot org

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).