Description: <short summary of the patch>
 TODO: Put a short summary on the line above and replace this paragraph
 with a longer explanation of this change. Complete the meta-information
 with other relevant fields (see below for details). To make it easier, the
 information below has been extracted from the changelog. Adjust it or drop
 it.
 .
 gcl (2.6.7-94) unstable; urgency=low
 .
   * optimize unwind at O0 to workaround gcc bug; centralize on
     __builtin__clear_cache when available;arm_thm_call reloc support
Author: Camm Maguire <camm@debian.org>

---
The information above should follow the Patch Tagging Guidelines, please
checkout http://dep.debian.net/deps/dep3/ to learn about the format. Here
are templates for supplementary fields that you might want to add:

Origin: <vendor|upstream|other>, <url of original patch>
Bug: <url in upstream bugtracker>
Bug-Debian: http://bugs.debian.org/<bugnumber>
Bug-Ubuntu: https://launchpad.net/bugs/<bugnumber>
Forwarded: <no|not-needed|url proving that it has been forwarded>
Reviewed-By: <name and email of someone who approved the patch>
Last-Update: <YYYY-MM-DD>

--- gcl-2.6.7.orig/configure
+++ gcl-2.6.7/configure
@@ -5740,6 +5740,31 @@ fi
 fi
 
 
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking __builtin___clear_cache" >&5
+$as_echo_n "checking __builtin___clear_cache... " >&6; }
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+void *v,*ve;
+ __builtin___clear_cache(v,ve);
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  $as_echo "#define HAVE_CLEAR_CACHE 1" >>confdefs.h
+
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 
 #AC_CONFIG_SUBDIRS($MY_SUBDIRS)
 
--- gcl-2.6.7.orig/acconfig.h
+++ gcl-2.6.7/acconfig.h
@@ -258,3 +258,4 @@ SGC is enabled.  */
 #undef HAVE_MALLOC_MALLOC_H
 #undef HAVE_OBJC_MALLOC_H
 #undef HAVE_OUTPUT_BFD
+#undef HAVE_BUILTIN_CLEAR_CACHE
--- gcl-2.6.7.orig/configure.in
+++ gcl-2.6.7/configure.in
@@ -558,9 +558,6 @@ case $use in
 		ia64*)
 			if test "$enable_debug" != "yes" ; then TO3FLAGS="-O" ; fi #FIXME needed asof gcc 4.6.2
 			;;
-		sparc64*)
-			if test "$enable_debug" != "yes" ; then TO3FLAGS="-O0" ; fi #FIXME needed asof gcc 4.6.1 frame.c/longjmp, possible make/fork
-			;;
 		arm*)
 			TCFLAGS="$TCFLAGS -mlong-calls -fdollars-in-identifiers -g "
 			if test "$enable_debug" != "yes" ; then TO3FLAGS="-O" ; fi #FIXME needed asof gcc 4.6.2
@@ -1052,6 +1049,14 @@ fi
 AC_CHECK_FUNC(xdr_double,,
 	   AC_CHECK_LIB(tirpc,xdr_double,TLIBS="$TLIBS -ltirpc",AC_MSG_ERROR([Need xdr_double])))
 
+AC_MSG_CHECKING(__builtin___clear_cache)
+AC_TRY_COMPILE([],
+[void *v,*ve;
+ __builtin___clear_cache(v,ve);
+],
+[AC_DEFINE(HAVE_BUILTIN_CLEAR_CACHE)
+ AC_MSG_RESULT(yes)],
+AC_MSG_RESULT(no))
 
 #AC_CONFIG_SUBDIRS($MY_SUBDIRS)
 
--- gcl-2.6.7.orig/o/sfaslelf.c
+++ gcl-2.6.7/o/sfaslelf.c
@@ -514,6 +514,22 @@ seek_to_end_ofile(FILE *fp) {
 
 }
 
+#ifdef HAVE_BUILTIN_CLEAR_CACHE
+static int
+clear_protect_memory(object memory) {
+
+  void *p,*pe;
+
+  __builtin___clear_cache((void *)memory->cfd.cfd_start,(void *)memory->cfd.cfd_start+memory->cfd.cfd_size);
+
+  p=(void *)((unsigned long)memory->cfd.cfd_start & ~(PAGESIZE-1));
+  pe=(void *)((unsigned long)(memory->cfd.cfd_start+memory->cfd.cfd_size) & ~(PAGESIZE-1)) + PAGESIZE-1;
+
+  return mprotect(p,pe-p,PROT_READ|PROT_WRITE|PROT_EXEC) ? 1 : 0;
+
+}
+#endif
+
 int
 fasload(object faslfile) {
 
@@ -551,10 +567,14 @@ fasload(object faslfile) {
   massert(!un_mmap(v1,ve));
   close_stream(faslfile);
   
+#ifdef HAVE_BUILTIN_CLEAR_CACHE
+  massert(!clear_protect_memory(memory));
+#else
 #ifdef CLEAR_CACHE
   CLEAR_CACHE;
 #endif
-  
+#endif  
+
   init_address-=(ul)memory->cfd.cfd_start;
   call_init(init_address,memory,data,0);
   
--- gcl-2.6.7.orig/h/elf32_arm_reloc.h
+++ gcl-2.6.7/h/elf32_arm_reloc.h
@@ -1,22 +1,17 @@
-/* #define R_ARM_THM_CALL        10 */
+#define R_ARM_THM_CALL        10
 #define R_ARM_CALL 28
 #define R_ARM_V4BX 40
 #define R_ARM_THM_MOVW_ABS_NC 47
 #define R_ARM_THM_MOVW_ABS    48
-    /* case R_ARM_THM_CALL: */
-    /*   s+=a; */
-    /*   if (ELF_ST_TYPE(sym->st_info)==STT_FUNC) s|=1; */
-    /*   s-=p; */
-    /*   s-=4;  */
-    /*   s>>=1; */
-    /*   s&=(~1); */
-    /*   store_val(where,MASK(1)<<28,0); */
-    /*   /\* massert(!(s&0xffc00000)); *\/ */
-    /*   /\* s=((s&0x7ff)<<16)|((s>>11)&0x7ff); *\/ */
-    /*   store_val(where,MASK(12),s>>12); */
-    /*   store_val(where,MASK(12)<<16,(s&0xfff)<<16); */
-    /*   /\* add_vals(where,~0L,s); *\/ */
-    /*   break; */
+    case R_ARM_THM_CALL: 
+      s+=a; 
+      if (ELF_ST_TYPE(sym->st_info)==STT_FUNC) s|=1; 
+      s-=p+4; /*FIXME maybe drop 4 and add_val below*/
+      s=((long)s>>1); 
+      massert(!(abs(s)&0xffc00000));  
+      store_val(where,MASK(11),s>>11); 
+      store_val(where,MASK(11)<<16,(s&0x7ff)<<16); 
+      break; 
     case R_ARM_THM_MOVW_ABS_NC:
       s+=a;
       if (ELF_ST_TYPE(sym->st_info)==STT_FUNC) s|=1;
--- gcl-2.6.7.orig/h/gclincl.h.in
+++ gcl-2.6.7/h/gclincl.h.in
@@ -259,6 +259,7 @@ SGC is enabled.  */
 #undef HAVE_MALLOC_MALLOC_H
 #undef HAVE_OBJC_MALLOC_H
 #undef HAVE_OUTPUT_BFD
+#undef HAVE_BUILTIN_CLEAR_CACHE
 
 /* Define to 1 if you have the <asm/sigcontext.h> header file. */
 #undef HAVE_ASM_SIGCONTEXT_H
--- gcl-2.6.7.orig/h/sparc-linux.h
+++ gcl-2.6.7/h/sparc-linux.h
@@ -23,6 +23,7 @@
 #else
 #define RELOC_H "elf64_sparc_reloc.h"
 #define SPECIAL_RELOC_H "elf64_sparc_reloc_special.h"
+void unwind(frame_ptr fr, object tag) __attribute__((optimize("O0")));/*FIXME*/
 #endif
 
 /* #if SIZEOF_LONG == 8 */
