|
From: Florian K. <br...@ac...> - 2008-05-14 15:52:57
|
On Wednesday 14 May 2008 10:39:48 am Bart Van Assche wrote:
>
> Are you aware that the file libvex_guest_offsets.h is also included
> from assembler files (.S) ?
>
Hello Bart,
no, I missed that. Bummer. Thanks for pointing it out.
I think it's safe to assume that converting the assembler files into
.c files with inline assembly is not an option.
In that case we need these OFFSET.. macros to expand to integer
constants.
Here is one way I can think of. It's not ideal but perhaps acceptable.
Taking libvex_guest_ppc64.h as an example, we could add this at the
end of that header file:
#define OFFSET_ppc64_GPR0 0
#define OFFSET_ppc64_GPR2 16
#define OFFSET_ppc64_GPR3 24
... and so on ...
#if defined(VPA_ppc64)
#define check_guest_offsets() \
do { \
vassert(OFFSET_ppc64_GPR0 == offsetof(VexGuestPPC64State,guest_GPR0)); \
vassert(OFFSET_ppc64_GPR2 == offsetof(VexGuestPPC64State,guest_GPR2)); \
vassert(OFFSET_ppc64_GPR3 == offsetof(VexGuestPPC64State,guest_GPR3)); \
... and so on ...
} while (0)
#endif
When VEX is initialised in LibVEX_Init we could simply call this
"function" to make sure the offsets are properly defined.
I used a macro here, because using a proper function has two issues:
(1) GCC warnings about function being defined but not used
(2) vassert is private, but libvex_guest... is public, so it's not
accessible from that context
Another alternative would be to give LibVEX_Init an additional
parameter which is a function pointer to the checking function. But
I've not explored this further.
It is true, that check_guest_offsets has to be updated whenever the
guest state changes. But that doesn't really happen all that often
once the port to a given platform has been finished.
Cheers,
Florian
|