1
0
Fork 0
mirror of https://github.com/tobast/libunwind-eh_elf.git synced 2024-11-28 18:07:37 +01:00

Fix for test suite build in the separate directory.

Avoid manually coding the rule to build crasher, instead fuddle
the compiler so that even -O2 optimization does not eliminate call
to b().

First, put calls to both a() and b() in the b() into non-tail-recursive
position. Second, as recommended in gcc manual, use asm volatile("");
to prevent further prevent inlining, besides attribute((noinline).
And third, call b() by alias, which current gcc optimizer cannot see
through.

Also, do not dereference NULL in a, and mark the memory access as volatile.
[ Minor portability improvements: asharma@fb.com ]
This commit is contained in:
Konstantin Belousov 2012-08-10 17:20:21 +03:00 committed by Arun Sharma
parent 538f63d796
commit 04c77cced4
2 changed files with 23 additions and 12 deletions

View file

@ -120,10 +120,6 @@ Ltest_nocalloc_SOURCES = Ltest-nocalloc.c
Gtest_trace_SOURCES = Gtest-trace.c ident.c Gtest_trace_SOURCES = Gtest-trace.c ident.c
Ltest_trace_SOURCES = Ltest-trace.c ident.c Ltest_trace_SOURCES = Ltest-trace.c ident.c
# prevent function inlining
crasher: crasher.c
$(CC) -O0 -o crasher crasher.c
LIBUNWIND = $(top_builddir)/src/libunwind-$(arch).la LIBUNWIND = $(top_builddir)/src/libunwind-$(arch).la
LIBUNWIND_ptrace = $(top_builddir)/src/libunwind-ptrace.a LIBUNWIND_ptrace = $(top_builddir)/src/libunwind-ptrace.a
LIBUNWIND_coredump = $(top_builddir)/src/libunwind-coredump.la LIBUNWIND_coredump = $(top_builddir)/src/libunwind-coredump.la

View file

@ -10,9 +10,6 @@
#include <sys/user.h> #include <sys/user.h>
#endif #endif
void a(void) __attribute__((noinline));
void b(int x) __attribute__((noinline));
#if defined(__linux__) #if defined(__linux__)
void write_maps(char *fname) void write_maps(char *fname)
{ {
@ -87,17 +84,35 @@ write_maps(char *fname)
#error Port me #error Port me
#endif #endif
void a(void) #ifdef __GNUC__
int a(void) __attribute__((noinline));
int b(int x) __attribute__((noinline));
int c(int x) __attribute__((noinline, alias("b")));
#define compiler_barrier() asm volatile("");
#else
int a(void);
int b(int x);
int c(int x);
#define compiler_barrier()
#endif
int a(void)
{ {
*(int *)NULL = 42; *(volatile int *)32 = 1;
return 1;
} }
void b(int x) int b(int x)
{ {
int r;
compiler_barrier();
if (x) if (x)
a(); r = a();
else else
b(1); r = c(1);
return r + 1;
} }
int int