From: Julian Seward Date: Fri, 19 Dec 2008 09:32:25 +0000 (+0000) Subject: genoffsets.c: don't use __builtin_offset since older gcc's don't X-Git-Tag: svn/VALGRIND_3_4_1^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=86b8f559f5ff5a8332fda9628d156624468630a2;p=thirdparty%2Fvalgrind.git genoffsets.c: don't use __builtin_offset since older gcc's don't know about it. Also add some comments. git-svn-id: svn://svn.valgrind.org/vex/trunk@1878 --- diff --git a/VEX/Makefile b/VEX/Makefile index 9283080a36..a140662d5d 100644 --- a/VEX/Makefile +++ b/VEX/Makefile @@ -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" \ diff --git a/VEX/auxprogs/genoffsets.c b/VEX/auxprogs/genoffsets.c index 9602812773..f4f95be98c 100644 --- a/VEX/auxprogs/genoffsets.c +++ b/VEX/auxprogs/genoffsets.c @@ -48,7 +48,13 @@ /* 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)) \ )