Some distributions enable by default a link-time optimizer that
mangles stack_fcall sample executables in a way that renders them
unusable for test purposes.
Robustify tests to defeat link-time optimizer.
* tests/stack-fcall.h (f0, f1, f2, f3): Add second parameter.
* tests/stack-fcall.c (main): Pass main as the second parameter to f0.
* tests/stack-fcall-0.c (f0): Add second parameter f, pass the xor of it
and f0 to f1.
* tests/stack-fcall-1.c (f1): Add second parameter f, pass the xor of it
and f1 to f2.
* tests/stack-fcall-2.c (f2): Add second parameter f, pass the xor of it
and f2 to f3.
* tests/stack-fcall-3.c: Include <asm/unistd.h>.
(f3): Add second parameter f, invoke __NR_gettid syscall with the xor
of f and f3 as its argument.
#include "stack-fcall.h"
-int f0(int i)
+int f0(int i, unsigned long f)
{
- return f1(i) - i;
+ return f1(i, f ^ (unsigned long) (void *) f0) - i;
}
#include "stack-fcall.h"
-int f1(int i)
+int f1(int i, unsigned long f)
{
- return f2(i) + i;
+ return f2(i, f ^ (unsigned long) (void *) f1) + i;
}
#include "stack-fcall.h"
-int f2(int i)
+int f2(int i, unsigned long f)
{
- return f3(i) - i;
+ return f3(i, f ^ (unsigned long) (void *) f2) - i;
}
#include <signal.h>
#include <unistd.h>
+#include <asm/unistd.h>
#include "stack-fcall.h"
-int f3(int i)
+int f3(int i, unsigned long f)
{
+ syscall(__NR_gettid, f ^ (unsigned long) (void *) f3);
switch (i) {
case 1:
return kill(getpid(), SIGURG);
int main(void)
{
- f0(0);
- f0(1);
+ f0(0, (unsigned long) (void *) main);
+ f0(1, (unsigned long) (void *) main);
return 0;
}
#endif
-int f0(int i);
-int f1(int i);
-int f2(int i);
-int f3(int i);
+int f0(int i, unsigned long);
+int f1(int i, unsigned long);
+int f2(int i, unsigned long);
+int f3(int i, unsigned long);