|
From: <sv...@va...> - 2008-12-19 09:32:31
|
Author: sewardj
Date: 2008-12-19 09:32:25 +0000 (Fri, 19 Dec 2008)
New Revision: 1878
Log:
genoffsets.c: don't use __builtin_offset since older gcc's don't
know about it. Also add some comments.
Modified:
trunk/Makefile
trunk/auxprogs/genoffsets.c
Modified: trunk/Makefile
===================================================================
--- trunk/Makefile 2008-12-17 22:37:49 UTC (rev 1877)
+++ trunk/Makefile 2008-12-19 09:32:25 UTC (rev 1878)
@@ -196,7 +196,7 @@
# differently -- with a leading $ on x86/amd64 but none on ppc32/64.
pub/libvex_guest_offsets.h:
rm -f auxprogs/genoffsets.s
- $(CC) $(CCFLAGS) -O0 -S -o auxprogs/genoffsets.s \
+ $(CC) $(CCFLAGS) -O -S -o auxprogs/genoffsets.s \
auxprogs/genoffsets.c
grep xyzzy auxprogs/genoffsets.s | grep define \
| sed "s/xyzzy\\$$//g" | sed "s/xyzzy//g" \
Modified: trunk/auxprogs/genoffsets.c
===================================================================
--- trunk/auxprogs/genoffsets.c 2008-12-17 22:37:49 UTC (rev 1877)
+++ trunk/auxprogs/genoffsets.c 2008-12-19 09:32:25 UTC (rev 1878)
@@ -48,8 +48,14 @@
/* A program which, when compiled to assembly, exposes various guest
state offsets. The program isn't executed, since that breaks
- cross-compilation. */
+ cross-compilation.
+ It does rely on the assumption that 'my_offsetof(Ty,Field)' is
+ folded to a constant at a compile time, which seems a bit dodgy
+ to me. On gcc4 it is possible to use __builtin_offsetof, which
+ sounds safer, but that doesn't exist on older gccs. Oh Well.
+*/
+
#include "../pub/libvex_basictypes.h"
#include "../pub/libvex_guest_x86.h"
#include "../pub/libvex_guest_amd64.h"
@@ -59,7 +65,9 @@
#define VG_STRINGIFZ(__str) #__str
#define VG_STRINGIFY(__str) VG_STRINGIFZ(__str)
-/* This forces gcc to evaluate the __builtin_offset at compile time,
+#define my_offsetof(__type,__field) (&((__type*)0)->__field)
+
+/* This forces gcc to evaluate the my_offsetof call at compile time,
and then emits it in the assembly, along with the nonsense string
"xyzzy", for easy greppability. Once this file is compiled to
assembly, the lines containing "xyzzy" are grepped out and sed-ed
@@ -72,7 +80,7 @@
VG_STRINGIFY(_fieldname) \
" xyzzy%0\n" : /*out*/ \
: /*in*/ "n" \
- (__builtin_offsetof(VexGuest##_structUppercase##State, \
+ (my_offsetof(VexGuest##_structUppercase##State, \
guest_##_fieldname)) \
)
|