[Crash-utility] [PATCH V3 2/3] Implement byte-by-byte memory access facilitators

David Miller davem at davemloft.net
Tue Apr 26 02:46:28 UTC 2016


From: Sam Ravnborg <sam at ravnborg.org>
Date: Mon, 25 Apr 2016 22:48:45 +0200

> A simpler model would be
> #define LOADER(TYPE, addr)                         \
> ({                                                 \
> 	TYPE ret;                                  \
> 	memcpy(&ret, (void *)addr, sizeof(TYPE));  \
> 	ret;                                       \
> })
> 
> I would expect the compiler to optimize this away for archs
> that do not require aligned access.

The compiler is allowed to "look through" void pointer casts and
use the alignment guaranteed by the original types.

That is why memcpy()'s aren't used for unaligned access handling.

Take a look at include/linux/unaligned/packed_struct.h in the kernel
sources, which is in my opinion the most portable and efficient way to
deal with this problem.

That code does the right thing on both architectures where alignment
matters, and where it does not.




More information about the Crash-utility mailing list