[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <063D6719AE5E284EB5DD2968C1650D6DB0205C9F@AcuExch.aculab.com>
Date: Wed, 19 Oct 2016 14:43:13 +0000
From: David Laight <David.Laight@...LAB.COM>
To: 'zhuyj' <zyjzyj2000@...il.com>,
David Lebrun <david.lebrun@...ouvain.be>
CC: netdev <netdev@...r.kernel.org>
Subject: RE: [PATCH 4/9] ipv6: sr: add core files for SR HMAC support
From: zhuyj
> Sent: 19 October 2016 14:21
> __attribute__((packed)) is potentially unsafe on some systems. The
> symptom probably won't show up on an x86, which just makes the problem
> more insidious; testing on x86 systems won't reveal the problem. (On
> the x86, misaligned accesses are handled in hardware; if you
> dereference an int* pointer that points to an odd address, it will be
> a little slower than if it were properly aligned, but you'll get the
> correct result.)
>
> On some other systems, such as SPARC, attempting to access a
> misaligned int object causes a bus error, crashing the program.
__attribute__((packed)) causes the compiler to generate byte memory
access and shifts to access the unaligned data.
You don't get a fault, just rather more instructions that you had in mind.
You shouldn't really specify 'packed' unless there are real reasons
why the data structure will appear on misaligned addresses.
David
Powered by blists - more mailing lists