public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/67246] New: MIPS: lw (load word) is generated for byte bitfield, leading to unaligned access
@ 2015-08-17  9:33 kugel at rockbox dot org
  2015-08-17  9:37 ` [Bug target/67246] " pinskia at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: kugel at rockbox dot org @ 2015-08-17  9:33 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 67246
           Summary: MIPS: lw (load word) is generated for byte bitfield,
                    leading to unaligned access
           Product: gcc
           Version: 5.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kugel at rockbox dot org
  Target Milestone: ---

Created attachment 36194
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=36194&action=edit
test program

Hello,

I hit a problem with unaligned accesses in the Linux kernel. The kernel defines

struct iphdr {
#if defined(__LITTLE_ENDIAN_BITFIELD)
        __u8    ihl:4,
                version:4;
#elif defined (__BIG_ENDIAN_BITFIELD)
        __u8    version:4,
                ihl:4;
#endif
... more fields ...
};

Then, in a source file it does (net/core/flow_dissector.c)
   nhoff += iph->ihl * 4;


GCC generates a lw for that
 248:   8e220000        lw      v0,0(s1)
 24c:   8fa40044        lw      a0,68(sp)
 250:   7c421e00        ext     v0,v0,0x18,0x4
 254:   00021080        sll     v0,v0,0x2
 258:   00821021        addu    v0,a0,v0

The problem is that iphdr can be 16bit aligned (due to ethernet header being 14
bytes, and iphdr usually follows). If that happens, this code generates a
unaligned access which is really unwanted.

I would expect that GCC uses a lbu to load that value, avoiding the unaligned
access. I think GCCs behavior is buggy in this instance.

I attached a small test program that also shows the problem.


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

end of thread, other threads:[~2015-08-17 10:25 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-17  9:33 [Bug target/67246] New: MIPS: lw (load word) is generated for byte bitfield, leading to unaligned access kugel at rockbox dot org
2015-08-17  9:37 ` [Bug target/67246] " pinskia at gcc dot gnu.org
2015-08-17  9:46 ` kugel at rockbox dot org
2015-08-17  9:51 ` pinskia at gcc dot gnu.org
2015-08-17  9:59 ` pinskia at gcc dot gnu.org
2015-08-17 10:04 ` kugel at rockbox dot org
2015-08-17 10:25 ` schwab@linux-m68k.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).