]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[build] Use __builtin_offsetof() when available
authorMichael Brown <mcb30@ipxe.org>
Sun, 28 Nov 2010 17:26:27 +0000 (17:26 +0000)
committerMichael Brown <mcb30@ipxe.org>
Sun, 28 Nov 2010 17:28:52 +0000 (17:28 +0000)
Some newer versions of gcc (observed with a patched gcc 4.5.1) seem to
treat our offsetof() implementation as not being a compile-time
constant.  Fix by using __builtin_offsetof() when available.  (As with
the original offsetof() macro, this code is copied from the Linux
kernel's stddef.h.)

Reported-by: Arkadiusz Miskiewicz <arekm@maven.pl>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/include/stddef.h

index 2a02a8985169efdeed8c85b067710c769e29cb76..8e69545c292b2c8c42f511b74ede0a1be2f80e33 100644 (file)
@@ -10,7 +10,11 @@ FILE_LICENCE ( GPL2_ONLY );
 #define NULL ((void *)0)
 
 #undef offsetof
+#ifdef __compiler_offsetof
+#define offsetof(TYPE,MEMBER) __compiler_offsetof(TYPE,MEMBER)
+#else
 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
+#endif
 
 #undef container_of
 #define container_of(ptr, type, member) ({                      \