]> git.unchartedbackwaters.co.uk Git - francis/libjit.git/commitdiff
resolve stack-walking problem with gcc 4.1 and introduce jit-arch-*.h
authorAleksey Demakov <ademakov@gmail.com>
Sun, 24 Sep 2006 20:36:51 +0000 (20:36 +0000)
committerAleksey Demakov <ademakov@gmail.com>
Sun, 24 Sep 2006 20:36:51 +0000 (20:36 +0000)
headers that may contain architecture dependent code.

ChangeLog
configure.in
include/jit/Makefile.am
include/jit/jit-walk.h
jit/jit-walk.c
tools/gen-apply.c

index c670ed39f1af856a5655a0caf7b9b241e6230bd8..9da24fe0ff1ae7d01b1c46d16d04925a90c083b9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+2006-09-25  Aleksey Demakov  <ademakov@gmail.com>
+
+       * include/jit/jit-arch-x86.h, include/jit/jit-arch-generic.h: add
+       headers for architecture-specific definitions.
+       (_JIT_ARCH_GET_CURRENT_FRAME): add macro to find the stack frame
+       pointer.
+
+       * include/jit/Makefile.am: create jit-arch.h as a symlink to one of
+       the jit-arch-*.h files depending on the JIT_ARCH value.
+       * configure.in: set JIT_ARCH according to the system architecture.
+
+       * include/jit/jit-walk.h (jit_get_current_frame):
+       * jit/jit-walk.c (jit_get_starting_frame):
+       * tools/gen-apply.c (find_return_offset, detect_frame_offsets): use
+       _JIT_ARCH_GET_CURRENT_FRAME macro if available. This resolves the
+       problem with gcc 4.1.* where __builtin_frame_address() function is
+       broken (thanks Klaus for identifing the problem).
+
 2006-09-15  Radek Polak <psonek2@seznam.cz>
 
         * include/jit/jit-insn.h, jit/jit-insn.c, jit/jit-debugger.c: new
index 7caac8769d3c2db2108d12060c83b0cdb0a1aba5..0f4a2cdfe6f5944fe3ef80e7d06a4c7a8dbfebad 100644 (file)
@@ -12,6 +12,19 @@ dnl Set the version number for the shared libraries.
 AC_SUBST(LIBJIT_VERSION)
 LIBJIT_VERSION=0:0:0
 
+dnl Determine the architecture.
+AC_MSG_CHECKING([architecture])
+AC_SUBST(JIT_ARCH)
+case "$host" in
+       i[[3456789]]86-*-*)
+               JIT_ARCH=x86
+               ;;
+       *)
+               JIT_ARCH=generic
+               ;;
+esac
+AC_MSG_RESULT($JIT_ARCH)
+
 dnl Turn off the cygwin library if building for Win32.
 dnl Note: We have to include <stdlib.h> if we will be using "__int64"
 dnl because otherwise the mingw32 compiler won't define it correctly.
index 8ed359b4cb8cb01ea45ce4312d8ca141316a71fe..b281798a9c0fb42c6a90e885df9d66f4672ebb94 100644 (file)
@@ -1,6 +1,8 @@
+ARCH_HEADER = jit-arch-@JIT_ARCH@.h
 
 libjitincludedir = $(includedir)/jit
 libjitinclude_HEADERS = jit.h \
+                                               jit-arch.h \
                                                jit-apply.h \
                                                jit-block.h \
                                                jit-common.h \
@@ -25,4 +27,10 @@ libjitinclude_HEADERS = jit.h \
                                                jit-value.h \
                                                jit-walk.h
 
-DISTCLEANFILES = jit-defs.h
+noinst_HEADERS = jit-arch-generic.h jit-arch-x86.h
+
+DISTCLEANFILES = jit-arch.h jit-defs.h
+
+jit-arch.h: $(ARCH_HEADER)
+       rm -f $@
+       $(LN_S) $(srcdir)/$(ARCH_HEADER) $@
index 0c2df9ce1bea57f8f4b510813204d5cc9e6f75a6..ff936fd7c2d04e6743cd4126708108d104e36608 100644 (file)
@@ -21,6 +21,8 @@
 #ifndef        _JIT_WALK_H
 #define        _JIT_WALK_H
 
+#include <jit/jit-arch.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -32,7 +34,7 @@ extern        "C" {
 void *_jit_get_frame_address(void *start, unsigned int n);
 #if defined(__GNUC__)
 #define        jit_get_frame_address(n)        \
-               (_jit_get_frame_address(__builtin_frame_address(0), (n)))
+       (_jit_get_frame_address(jit_get_current_frame(), (n)))
 #else
 #define        jit_get_frame_address(n)        (_jit_get_frame_address(0, (n)))
 #endif
@@ -40,9 +42,21 @@ void *_jit_get_frame_address(void *start, unsigned int n);
 /*
  * Get the frame address for the current frame.  May be more efficient
  * than using "jit_get_frame_address(0)".
+ *
+ * Note: some gcc vestions have broken __builtin_frame_address() so use
+ * _JIT_ARCH_GET_CURRENT_FRAME() if available. 
  */
 #if defined(__GNUC__)
+#if defined(_JIT_ARCH_GET_CURRENT_FRAME)
+#define        jit_get_current_frame()                         \
+       ({                                              \
+               void *address;                          \
+               _JIT_ARCH_GET_CURRENT_FRAME(address);   \
+               address;                                \
+       })
+#else
 #define        jit_get_current_frame()         (__builtin_frame_address(0))
+#endif
 #else
 #define        jit_get_current_frame()         (jit_get_frame_address(0))
 #endif
index a55aacb3cb0a80f465dd4a00cce6455937a4c981..ae2ef7fce9eb4ec3c272d6ac7f618a68e3c3729b 100644 (file)
  * Fetch the starting frame address if the caller did not supply it
  * (probably because the caller wasn't compiled with gcc).  The address
  * that we want is actually one frame out from where we are at the moment.
+ *
+ * Note: some gcc vestions have broken __builtin_frame_address() so use
+ * _JIT_ARCH_GET_CURRENT_FRAME() if available. 
  */
 #if defined(__GNUC__)
+#if defined(_JIT_ARCH_GET_CURRENT_FRAME)
+#define        jit_get_starting_frame()        \
+       do { \
+               _JIT_ARCH_GET_CURRENT_FRAME(start); \
+               if(start) \
+               { \
+                       start = jit_next_frame_pointer(start); \
+               } \
+       } while (0)
+#else
 #define        jit_get_starting_frame()        \
        do { \
                start = __builtin_frame_address(0); \
@@ -82,6 +95,7 @@
                        start = jit_next_frame_pointer(start); \
                } \
        } while (0)
+#endif
 #elif defined(_MSC_VER) && defined(_M_IX86)
 #define        jit_get_starting_frame()        \
        __asm \
index 3de45e90cb734c8c94848cdc774599b5ace35cd0..47e4b925017bbe6d882ef7170ea243af1e310d9f 100644 (file)
@@ -18,6 +18,7 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
+#include <jit/jit-arch.h>
 #include <jit/jit-defs.h>
 #define        JIT_MEMCPY              "mem_copy"
 #include "jit-apply-func.h"
@@ -1329,7 +1330,13 @@ void find_frame_offset_inner(void *looking_for, void **frame)
 }
 void find_frame_offset_outer(void *looking_for)
 {
-       find_frame_offset_inner(looking_for, (void **)__builtin_frame_address(0));
+       void *frame_address;
+#if defined(_JIT_ARCH_GET_CURRENT_FRAME)
+       _JIT_ARCH_GET_CURRENT_FRAME(frame_address);
+#else
+       frame_address = __builtin_frame_address(0);
+#endif
+       find_frame_offset_inner(looking_for, (void **)frame_address);
 }
 void find_return_offset(void *looking_for, void **frame)
 {
@@ -1357,8 +1364,13 @@ void find_return_offset(void *looking_for, void **frame)
 }
 void detect_frame_offsets(void)
 {
-       void *frame_address = __builtin_frame_address(0);
-       void *return_address = __builtin_return_address(0);
+       void *frame_address, *return_address;
+#if defined(_JIT_ARCH_GET_CURRENT_FRAME)
+       _JIT_ARCH_GET_CURRENT_FRAME(frame_address);
+#else
+       frame_address = __builtin_frame_address(0);
+#endif
+       return_address = __builtin_return_address(0);
        find_frame_offset_outer(frame_address);
        find_return_offset(return_address, frame_address);
        if(parent_frame_offset == 0 && return_address_offset == 0)