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

* [Bug c/98627] GCC emits unaligned memory access instructions causing address error exceptions with the 68000 architecture
  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 ` schwab@linux-m68k.org
  2021-01-11 19:12 ` noring at nocrew dot org
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: schwab@linux-m68k.org @ 2021-01-11 18:04 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andreas Schwab <schwab@linux-m68k.org> ---
How did you configure the compiler?

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

* [Bug c/98627] GCC emits unaligned memory access instructions causing address error exceptions with the 68000 architecture
  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
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: noring at nocrew dot org @ 2021-01-11 19:12 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Fredrik Noring <noring at nocrew dot org> ---
To obtain the object file I can run the command

m68k-unknown-linux-gnu-gcc -O1 -march=68000 -c -o address-error.o
address-error.c

with a cross-compiler made using the Gentoo package sys-devel/crossdev having
the target m68k-unknown-linux-gnu.

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

* [Bug c/98627] GCC emits unaligned memory access instructions causing address error exceptions with the 68000 architecture
  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
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: schwab@linux-m68k.org @ 2021-01-11 19:24 UTC (permalink / raw)
  To: gcc-bugs

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

Andreas Schwab <schwab@linux-m68k.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #3 from Andreas Schwab <schwab@linux-m68k.org> ---
m68k-linux requires m68020+, you cannot combine that with -march=68000.

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

* [Bug c/98627] GCC emits unaligned memory access instructions causing address error exceptions with the 68000 architecture
  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
                   ` (2 preceding siblings ...)
  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
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: noring at nocrew dot org @ 2021-01-11 20:02 UTC (permalink / raw)
  To: gcc-bugs

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

Fredrik Noring <noring at nocrew dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|INVALID                     |FIXED

--- Comment #4 from Fredrik Noring <noring at nocrew dot org> ---
Well, GCC accepts -march=68000 as a valid option and so it doesn't seem to make
sense that it then proceeds to generate code for something incompatible like
the 68020. As far as I understand, other targets such as MIPS don't behave like
that: a MIPS III compiler can generate code for MIPS I without problems, for
instance.

What target(s) would you recommend for the compiler to (completely and without
exceptions) honour the given -march=68000 option?

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

* [Bug c/98627] GCC emits unaligned memory access instructions causing address error exceptions with the 68000 architecture
  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
                   ` (3 preceding siblings ...)
  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
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: schwab@linux-m68k.org @ 2021-01-11 20:13 UTC (permalink / raw)
  To: gcc-bugs

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

Andreas Schwab <schwab@linux-m68k.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|FIXED                       |INVALID

--- Comment #5 from Andreas Schwab <schwab@linux-m68k.org> ---
Anything but linux.

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

* [Bug c/98627] GCC emits unaligned memory access instructions causing address error exceptions with the 68000 architecture
  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
                   ` (4 preceding siblings ...)
  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
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: noring at nocrew dot org @ 2021-01-11 20:36 UTC (permalink / raw)
  To: gcc-bugs

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

Fredrik Noring <noring at nocrew dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|INVALID                     |FIXED

--- Comment #6 from Fredrik Noring <noring at nocrew dot org> ---
Then I would suggest it's a bug that GCC doesn't reject -march=68000
in combination with linux. Unsuspecting projects use this, and in fact
it almost works except for random crashes every now and then, which is
a grave quality problem to be sure.

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

* [Bug c/98627] GCC emits unaligned memory access instructions causing address error exceptions with the 68000 architecture
  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
                   ` (5 preceding siblings ...)
  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
  8 siblings, 0 replies; 10+ messages in thread
From: schwab@linux-m68k.org @ 2021-01-11 20:41 UTC (permalink / raw)
  To: gcc-bugs

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

Andreas Schwab <schwab@linux-m68k.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|FIXED                       |INVALID

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

* [Bug c/98627] GCC emits unaligned memory access instructions causing address error exceptions with the 68000 architecture
  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
                   ` (6 preceding siblings ...)
  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
  8 siblings, 0 replies; 10+ messages in thread
From: mikpelinux at gmail dot com @ 2021-01-12 16:26 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Mikael Pettersson <mikpelinux at gmail dot com> ---
The correct target to use in this case is m68k-elf.

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

* [Bug c/98627] GCC emits unaligned memory access instructions causing address error exceptions with the 68000 architecture
  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
                   ` (7 preceding siblings ...)
  2021-01-12 16:26 ` mikpelinux at gmail dot com
@ 2021-01-12 19:20 ` noring at nocrew dot org
  8 siblings, 0 replies; 10+ messages in thread
From: noring at nocrew dot org @ 2021-01-12 19:20 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Fredrik Noring <noring at nocrew dot org> ---
Thanks, Mikael. Users evidently take whatever m68k-* GCC they have at hand and
so 68000-projects therefore must have a special configure test to verify that
-march=68000 isn't broken with the user's choice of GCC. I must say I do think
it's quite wrong to blame the user for this problem.

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