]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
genoffsets.c: don't use __builtin_offset since older gcc's don't
authorJulian Seward <jseward@acm.org>
Fri, 19 Dec 2008 09:32:25 +0000 (09:32 +0000)
committerJulian Seward <jseward@acm.org>
Fri, 19 Dec 2008 09:32:25 +0000 (09:32 +0000)
know about it.  Also add some comments.

git-svn-id: svn://svn.valgrind.org/vex/trunk@1878

VEX/Makefile
VEX/auxprogs/genoffsets.c

index 9283080a36ac62b4240d59c757da48ea538417c1..a140662d5df15fa7035cd5cad7f266cb9f8ce11f 100644 (file)
@@ -196,7 +196,7 @@ minidist: version
 # 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" \
index 96028127738cbdd8ace1c840196f70d0c99a22ab..f4f95be98c2389bc7cceeaf0815a218511ad1816 100644 (file)
 
 /* 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"
@@ -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)) \
    )