|
From: <sv...@va...> - 2005-07-07 11:24:19
|
Author: sewardj
Date: 2005-07-07 12:24:14 +0100 (Thu, 07 Jul 2005)
New Revision: 4123
Log:
Modify this test so it no longer uses client requests, but instead
relies on --smc-support=3Dall to work correctly. Hence it tests the
s-m-c support at least on x86. Jump through various hoops to defeat
vex's basic-block-chasing optimisation, which has an annoying habit of
making this test work correctly even without --smc-support=3Dall.
Modified:
trunk/none/tests/x86/smc1.c
trunk/none/tests/x86/smc1.vgtest
Modified: trunk/none/tests/x86/smc1.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/none/tests/x86/smc1.c 2005-07-07 10:05:05 UTC (rev 4122)
+++ trunk/none/tests/x86/smc1.c 2005-07-07 11:24:14 UTC (rev 4123)
@@ -1,5 +1,5 @@
=20
-/* Test Heimdall's ability to spot writes to code which has been
+/* Test Valgrind's ability to spot writes to code which has been
translated, and discard the out-of-date translations.
=20
CORRECT output is
@@ -30,7 +30,6 @@
*/
=20
#include <stdio.h>
-#include "valgrind.h"
=20
typedef unsigned int Addr;
typedef unsigned char UChar;
@@ -45,33 +44,52 @@
printf("in p %d\n", n);
}
=20
-UChar code[10];
+static UChar code[10];
=20
-/* Make `code' be JMP-32 dest */
+/* Make `code' be PUSHL $dest ; ret */
+// This forces the branch onwards to be indirect, so vex can't chase it
void set_dest ( Addr dest )
{
- unsigned int delta;
- delta =3D dest - ((Addr)(&code[0]));
- delta -=3D 5;
- =20
- code[0] =3D 0xE9; /* JMP d32 */
- code[1] =3D (delta & 0xFF);
- code[2] =3D ((delta >> 8) & 0xFF);
- code[3] =3D ((delta >> 16) & 0xFF);
- code[4] =3D ((delta >> 24) & 0xFF);
-
- /* XXX this should be automatic */
- VALGRIND_DISCARD_TRANSLATIONS(code, sizeof(code));
+ code[0] =3D 0x68; /* PUSH imm32 */
+ code[1] =3D (dest & 0xFF);
+ code[2] =3D ((dest >> 8) & 0xFF);
+ code[3] =3D ((dest >> 16) & 0xFF);
+ code[4] =3D ((dest >> 24) & 0xFF);
+ code[5] =3D 0xC3;
}
=20
+/* Calling aa gets eventually to the function residing in code[0..].
+ This indirection is necessary to defeat Vex's basic-block chasing
+ optimisation. That will merge up to three basic blocks into the
+ same IR superblock, which causes the test to succeed when it
+ shouldn't if main calls code[] directly. */
+
+// force an indirect branch to code[0], so vex can't chase it
+__attribute__((noinline))
+void dd ( int x, void (*f)(int) ) { f(x); }
+
+__attribute__((noinline))
+void cc ( int x ) { dd(x, (void(*)(int)) &code[0]); }
+
+__attribute__((noinline))
+void bb ( int x ) { cc(x); }
+
+__attribute__((noinline))
+void aa ( int x ) { bb(x); }
+
+__attribute__((noinline))
+void diversion ( void ) { }
+
int main ( void )
{
int i;
for (i =3D 0; i < 10; i +=3D 2) {
set_dest ( (Addr)&p );
- ( (void (*)(int)) (&code[0]) ) (i);
+ // diversion();
+ aa(i);
set_dest ( (Addr)&q );
- ( (void (*)(int)) (&code[0]) ) (i+1);
+ // diversion();
+ aa(i+1);
}
return 0;
}
Modified: trunk/none/tests/x86/smc1.vgtest
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/none/tests/x86/smc1.vgtest 2005-07-07 10:05:05 UTC (rev 4122)
+++ trunk/none/tests/x86/smc1.vgtest 2005-07-07 11:24:14 UTC (rev 4123)
@@ -1 +1,2 @@
prog: smc1
+vgopts: --smc-support=3Dall
|