libunwind-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Libunwind-devel] crasher.c port for FreeBSD


From: Konstantin Belousov
Subject: Re: [Libunwind-devel] crasher.c port for FreeBSD
Date: Fri, 10 Aug 2012 17:20:21 +0300
User-agent: Mutt/1.4.2.3i

On Sat, Jun 23, 2012 at 11:43:10AM -0700, Arun Sharma wrote:
> On Mon, Jun 18, 2012 at 5:30 AM, Konstantin Belousov
> <address@hidden> wrote:
> >  # prevent function inlining
> > -crasher: crasher.c
> > -       $(CC) -O0 -o crasher crasher.c
> > +crasher_CFLAGS=-O0
> 
> This still causes crasher to be built with -O0 -O2 and the test fails
> for me with:
> 
> Segmentation fault (core dumped)
> FAILURE: start IPs incorrect
> FAIL: run-coredump-unwind
> 
> You might want to try something along the lines of:
> 
> http://lists.gnu.org/archive/html/automake/2005-09/msg00108.html

This seems to be quite broken on its own. Looks like it would prevent
use of any user-supplied flags, not only optimization flags. E.g., -m32
is erased by this approach.

Instead, I fooled gcc optimizer to not understand the code to not
eliminate the function call. Patch is below, also available for pull
from branch for-arun.

I only looked at the disassembly for verification.

commit 27c3d08c980931142b27a8da48d2b8e26ea50e97
Author: Konstantin Belousov <address@hidden>
Date:   Fri Aug 10 17:12:18 2012 +0300

    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.

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 9dd9a76..9e6fd2f 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -115,10 +115,6 @@ Ltest_nocalloc_SOURCES = Ltest-nocalloc.c
 Gtest_trace_SOURCES = Gtest-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_ptrace = $(top_builddir)/src/libunwind-ptrace.a
 LIBUNWIND_coredump = $(top_builddir)/src/libunwind-coredump.la
diff --git a/tests/crasher.c b/tests/crasher.c
index 72cd54d..4c84e5f 100644
--- a/tests/crasher.c
+++ b/tests/crasher.c
@@ -10,9 +10,6 @@
 #include <sys/user.h>
 #endif
 
-void a(void) __attribute__((noinline));
-void b(int x) __attribute__((noinline));
-
 #if defined(__linux__)
 void write_maps(char *fname)
 {
@@ -87,17 +84,26 @@ write_maps(char *fname)
 #error Port me
 #endif
 
-void a(void)
+int a(void) __attribute__((noinline));
+int b(int x) __attribute__((noinline));
+int c(int x) __attribute__((noinline, alias("b")));
+
+int a(void)
 {
-  *(int *)NULL = 42;
+  *(volatile int *)32 = 1;
+  return 1;
 }
 
-void b(int x)
+int b(int x)
 {
+  int r;
+
+  asm volatile("");
   if (x)
-    a();
+    r = a();
   else
-    b(1);
+    r = c(1);
+  return r + 1;
 }
 
 int

Attachment: pgptdWIRdC5pU.pgp
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]