gcc builtin memcpy is bogus?

From: Matthew Wilcox <willy_at_debian.org>
Date: 2003-12-09 03:01:24
This is a fun one ... I don't know what to blame for this.

struct rfd {
        u16 status;
        u16 command;
        u32 link;
        u32 rbd;
        u16 actual_size;
        u16 size;

static void e100_rx_rfa_add_tail(struct nic *nic, struct rx_list *curr)
        struct rfd *rfd = (struct rfd *)curr->skb->data;
        memcpy(rfd, &nic->blank_rfd, sizeof(struct rfd));

I'm using gcc (GCC) 3.3.2 (Debian) for this.

The kernel doesn't use -fno-builtin or -fno-builtin-memcpy so it attempts
to optimise this by doing 4-byte loads and stores.  Problem is, the
destination is misaligned (deliberately), so the kernel emits unaligned
messages.  Adding -fno-builtin to the command line turns this back into
a call to memcpy.

So how should this be fixed?

 - Improve gcc's builtin memcpy to work on non-aligned structs (unlikely)?
 - Somehow tag the pointer or the struct that it's unaligned?
 - Compile with -fno-builtin-memcpy (and probably a few others too)?

Other suggestions?

"Next the statesmen will invent cheap lies, putting the blame upon 
the nation that is attacked, and every man will be glad of those
conscience-soothing falsities, and will diligently study them, and refuse
to examine any refutations of them; and thus he will by and by convince 
himself that the war is just, and will thank God for the better sleep 
he enjoys after this process of grotesque self-deception." -- Mark Twain
To unsubscribe from this list: send the line "unsubscribe linux-ia64" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Received on Mon Dec 8 11:13:51 2003

This archive was generated by hypermail 2.1.8 : 2005-08-02 09:20:20 EST