Blob Blame Raw
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.12-26) unstable; urgency=medium
 .
   * Version_2_6_13pre32
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: https://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.12.orig/cmpnew/gcl_cmpmain.lsp
+++ gcl-2.6.12/cmpnew/gcl_cmpmain.lsp
@@ -161,7 +161,7 @@
 
 
 (defun compile-file1 (input-pathname
-                      &key (output-file input-pathname)
+                      &key (output-file (truename input-pathname))
                            (o-file t)
                            (c-file *default-c-file*)
                            (h-file *default-h-file*)
--- gcl-2.6.12.orig/h/elf64_mips_reloc.h
+++ gcl-2.6.12/h/elf64_mips_reloc.h
@@ -1,18 +1,28 @@
     case R_MIPS_JALR:
       break;
-    case R_MIPS_64:
-      if (ELF_R_FTYPE(r->r_info)==R_MIPS_GPREL32) s-=(ul)got;
-      add_val(where,~0L,s+a);
-      break;
     case R_MIPS_GPREL32:
+      recurse(s+a-(ul)got);
       add_val(where,MASK(32),s+a-(ul)got);
       break;
+    case R_MIPS_GPREL16:
+      recurse(s+a-(ul)got);
+      add_val(where,MASK(16),s+a-(ul)got);
+      break;
+    case R_MIPS_SUB:
+      recurse(-(s+a));
+      break;/*???*/
+    case R_MIPS_64:
+      recurse(s+a);
+      add_val(where,~0L,s+a);
+      break;
     case R_MIPS_32:
+      recurse(s+a);
       add_val(where,MASK(32),s+a);
       break;
     case R_MIPS_GOT_DISP:
     case R_MIPS_CALL16:
     case R_MIPS_GOT_PAGE:
+      recurse(s+a);
       gote=got+(a>>32)-1;
       a&=MASK(32);
       store_val(where,MASK(16),((void *)gote-(void *)got));
@@ -22,28 +32,27 @@
         *gote=s+(a&~MASK(16))+((a&0x8000)<<1);
       break;
     case R_MIPS_GOT_OFST:
+      recurse(s+a);
       store_val(where,MASK(16),a);
       break;
     case R_MIPS_HI16:
-      s+=a&MASK(32);
-      if (ELF_R_FTYPE(r->r_info)==R_MIPS_GPREL16) s=(ul)got-s;
+      recurse(s+a);
       if (!hr) hr=(void *)r;
-      if (a&(1L<<32)) add_vals(where,MASK(16),(s+(a>>32))>>16);
+      if (lr)/*==(Rela *)r*/
+	add_vals(where,MASK(16),(s+a+la)>>16);
       break;
     case R_MIPS_LO16:
+      recurse(s+a);
       s+=a;
-      if (ELF_R_FTYPE(r->r_info)==R_MIPS_GPREL16) s=(ul)got-s;
       a=*where&MASK(16);
       if (a&0x8000) a|=0xffffffffffff0000; 
       a+=s&MASK(16);
       a+=(a&0x8000)<<1; 
       store_val(where,MASK(16),a);
-      a&=~MASK(16);
-      {
-        Rela *ra=(void *)r;				
-        for (hr=hr ? hr : (void *)ra;--ra>=hr;)
-	  if (ELF_R_TYPE(ra->r_info)==R_MIPS_HI16)
-	    relocate(sym1,ra,ra->r_addend|(1L<<32)|(a<<32),start,got,gote);
-      }
-      hr=NULL;
+      for (la=a&~MASK(16),lr=(Rela *)r,hr=hr ? hr : lr;--lr>=hr;)
+        if (ELF_R_TYPE1(lr->r_info)==R_MIPS_HI16||
+            ELF_R_TYPE2(lr->r_info)==R_MIPS_HI16||
+            ELF_R_TYPE3(lr->r_info)==R_MIPS_HI16)
+          relocate(sym1,lr,lr->r_addend,start,got,gote);
+      hr=lr=NULL;
       break;
--- gcl-2.6.12.orig/h/elf64_mips_reloc_special.h
+++ gcl-2.6.12/h/elf64_mips_reloc_special.h
@@ -1,10 +1,21 @@
-static ul ggot,ggote; static Rela *hr;
+static ul ggot,ggote,la; static Rela *hr,*lr;
 
 #undef ELF_R_SYM 
 #define ELF_R_SYM(a_) (a_&0xffffffff) 
+#define ELF_R_TYPE1(a_) ((a_>>56)&0xff)
+#define ELF_R_TYPE2(a_) ((a_>>48)&0xff)
+#define ELF_R_TYPE3(a_) ((a_>>40)&0xff)
+#define recurse(val) ({							\
+      if (ELF_R_TYPE2(r->r_info)) {					\
+	ul i=r->r_info;							\
+	r->r_info=(((r->r_info>>32)&MASK(24))<<40)|(r->r_info&MASK(32)); \
+	relocate(sym1,r,(val)-s,start,got,gote);			\
+	r->r_info=i;							\
+	break;								\
+      }})
+
 #undef ELF_R_TYPE 
-#define ELF_R_TYPE(a_) (((a_>>40)&0xff) ? ((a_>>40)&0xff) : (((a_>>48)&0xff) ? ((a_>>48)&0xff) : ((a_>>56)&0xff)))
-#define ELF_R_FTYPE(a_) ((a_>>56)&0xff)
+#define ELF_R_TYPE(a_) ELF_R_TYPE1(a_)
 
 typedef struct {
   ul entry,gotoff;
--- gcl-2.6.12.orig/h/object.h
+++ gcl-2.6.12/h/object.h
@@ -568,6 +568,12 @@ EXTER unsigned plong signals_allowed, si
 
 #define IMMNIL(x) (is_imm_fixnum(x)||x==Cnil)
 
-#define eql(a_,b_)    ({register object _a=(a_);register object _b=(b_);_a==_b || (!IMMNIL(_a)&&!IMMNIL(_b)&&eql1(_a,_b));})
-#define equal(a_,b_)  ({register object _a=(a_);register object _b=(b_);_a==_b || (!IMMNIL(_a)&&!IMMNIL(_b)&&equal1(_a,_b));})
-#define equalp(a_,b_) ({register object _a=(a_);register object _b=(b_);_a==_b || (_a!=Cnil&&_b!=Cnil&&equalp1(_a,_b));})
+/*gcc boolean expression tail position bug*/
+
+/* #define eql(a_,b_)    ({register object _a=(a_);register object _b=(b_);_a==_b || (!IMMNIL(_a)&&!IMMNIL(_b)&&eql1(_a,_b));}) */
+/* #define equal(a_,b_)  ({register object _a=(a_);register object _b=(b_);_a==_b || (!IMMNIL(_a)&&!IMMNIL(_b)&&equal1(_a,_b));}) */
+/* #define equalp(a_,b_) ({register object _a=(a_);register object _b=(b_);_a==_b || (_a!=Cnil&&_b!=Cnil&&equalp1(_a,_b));}) */
+
+#define eql(a_,b_)    ({register object _a=(a_);register object _b=(b_);_a==_b ? TRUE : (IMMNIL(_a)||IMMNIL(_b) ? FALSE : eql1(_a,_b));})
+#define equal(a_,b_)  ({register object _a=(a_);register object _b=(b_);_a==_b ? TRUE : (IMMNIL(_a)||IMMNIL(_b) ? FALSE : equal1(_a,_b));})
+#define equalp(a_,b_) ({register object _a=(a_);register object _b=(b_);_a==_b ? TRUE : (_a==Cnil||_b==Cnil ? FALSE : equalp1(_a,_b));})
--- gcl-2.6.12.orig/o/main.c
+++ gcl-2.6.12/o/main.c
@@ -443,6 +443,23 @@ gcl_cleanup(int gc) {
 
 }
 
+/*gcc boolean expression tail position bug*/
+
+void *
+cclear_stack(unsigned long size) {
+  void *v=alloca(size);
+  memset(v,0,size);
+  return v;
+}
+
+DEFUN_NEW("EQUAL-TAIL-RECURSION-CHECK",object,fSequal_tail_recursion_check,SI,1,1,NONE,II,OO,OO,OO,(fixnum s),"") {
+  object x0=make_list(s/sizeof(object)),x1=make_list(s/sizeof(object));
+  char *u=cclear_stack(s),*w;
+  fLequal(x0,x1);
+  for (w=u;w<u+s && !*w;w++);
+  RETURN1((object)(w-u));
+}
+
 
 int
 main(int argc, char **argv, char **envp) {
--- gcl-2.6.12.orig/o/predicate.c
+++ gcl-2.6.12/o/predicate.c
@@ -446,23 +446,9 @@ equal1(register object x, register objec
 
   /*x and y are not == and not Cnil and not immfix*/
 
-#ifdef __MINGW32__ /*FIXME mingw compiler cannot do tail recursion and blows out stack*/
- BEGIN:
-  if (valid_cdr(x)) {
-    if (valid_cdr(y)&&equal(x->c.c_car,y->c.c_car)) {
-      x=x->c.c_cdr;
-      y=y->c.c_cdr;
-      if (x==y) return TRUE;
-      if (IMMNIL(x)||IMMNIL(y)) return FALSE;
-      goto BEGIN;
-    } else
-      return FALSE;
-  }
-#else
-  
-  if (valid_cdr(x)) return valid_cdr(y)&&equal(x->c.c_car,y->c.c_car)&&equal(x->c.c_cdr,y->c.c_cdr);
-
-#endif
+  /*gcc boolean expression tail position bug*/
+  /* if (valid_cdr(x)) return valid_cdr(y)&&equal(x->c.c_car,y->c.c_car)&&equal(x->c.c_cdr,y->c.c_cdr); */
+  if (valid_cdr(x)) return !valid_cdr(y)||!equal(x->c.c_car,y->c.c_car) ? FALSE : equal(x->c.c_cdr,y->c.c_cdr);
 
   if (valid_cdr(y)) return FALSE;
   
@@ -524,7 +510,9 @@ equalp1(register object x, register obje
   
   /*x and y are not == and not Cnil*/
 
-  if (listp(x)) return listp(y)&&equalp(x->c.c_car,y->c.c_car)&&equalp(x->c.c_cdr,y->c.c_cdr);
+  /*gcc boolean expression tail position bug*/
+  /* if (listp(x)) return listp(y)&&equalp(x->c.c_car,y->c.c_car)&&equalp(x->c.c_cdr,y->c.c_cdr); */
+  if (listp(x)) return !listp(y)||!equalp(x->c.c_car,y->c.c_car) ? FALSE : equalp(x->c.c_cdr,y->c.c_cdr);
     
   if (listp(y)) return FALSE;
 
--- gcl-2.6.12.orig/unixport/sys_init.lsp.in
+++ gcl-2.6.12/unixport/sys_init.lsp.in
@@ -79,3 +79,7 @@
 
 #+ansi-cl (use-package :pcl :user)
 #+ansi-cl (import 'si::(clines defentry defcfun object void int double quit bye gbc system) :user)
+
+(let* ((i 4096)(j (si::equal-tail-recursion-check i)))
+  (unless (eql i j)
+    (warn "equal is not tail recursive ~s ~s" i j)))