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-103) unstable; urgency=medium
 .
   * Bug fix: "Fails to install in unstable", thanks to Samuel Thibault
     (Closes: #993480).
Author: Camm Maguire <camm@debian.org>
Bug-Debian: https://bugs.debian.org/993480

---
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: 2021-10-10

--- gcl-2.6.12.orig/configure
+++ gcl-2.6.12/configure
@@ -761,6 +761,7 @@ enable_gprof
 enable_dynsysgmp
 with_x
 enable_xdr
+enable_cstackmax
 enable_immfix
 enable_fastimmfix
 enable_ansi
@@ -1429,6 +1430,7 @@ Optional Features:
   --enable-gprof builds gcl with -pg in CFLAGS to enable profiling with gprof
   --enable-dynsysgmp will link against the system libgmp3 overriding certain functions with patched versions from the local source
   --enable-xdr=yes will compile in support for XDR
+  --enable-cstackmax=xxxx will ensure that the cstack begins below xxxx or fail
   --enable-immfix will enable an immediate fixnum table above the C stack
   --enable-fastimmfix=XXXX will reject low immediate fixnums unless 2^XXX can be attained
   --enable-ansi builds a large gcl aiming for ansi compliance
@@ -4186,11 +4188,14 @@ case $use in
 	    ia64*)
 		if test "$enable_debug" != "yes" ; then TO3FLAGS="-O" ; fi #FIXME needed asof gcc 4.8.1
 		;;
-	    armhf*)
-		assert_arg_to_cflags -fdollars-in-identifiers
-		assert_arg_to_cflags -g #?
-		;;
 	    arm*)
+
+$as_echo "#define SET_STACK_POINTER \"mov %%sp,%0\\n\\t\"" >>confdefs.h
+
+		{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to set stack pointer" >&5
+$as_echo_n "checking how to set stack pointer... " >&6; }
+		{ $as_echo "$as_me:${as_lineno-$LINENO}: result: done" >&5
+$as_echo "done" >&6; }
 		assert_arg_to_cflags -fdollars-in-identifiers
 		assert_arg_to_cflags -g #?
 		;;
@@ -6673,24 +6678,12 @@ else
 
 		#include <stdio.h>
 		#include <stdlib.h>
-
-		unsigned long w;
-
-		void
-		foo(void) {
-		    int i;
-		    w=(unsigned long)&i;
-		}
-
-		int
-		main(int argc,char **argv,char **envp) {
-		    void *b;
+		int main(int argc,char **argv,char **envp) {
 		    FILE *fp = fopen("conftest1","w");
 		    #ifdef CAN_UNRANDOMIZE_SBRK
 		    #include "h/unrandomize.h"
 		    #endif
-		    foo();
-		    fprintf(fp,"%d",((unsigned long) &b) > w ? -1 : 1);
+		    fprintf(fp,"%d",(alloca(sizeof(void *))>alloca(sizeof(void *))) ? -1 : 1);
 		    fclose(fp);
 		    return 0;
 		}
@@ -6712,6 +6705,62 @@ _ACEOF
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $cstack_direction" >&5
 $as_echo "$cstack_direction" >&6; }
 
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking finding CSTACK_ALIGNMENT" >&5
+$as_echo_n "checking finding CSTACK_ALIGNMENT... " >&6; }
+if test "$cross_compiling" = yes; then :
+  { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "cannot run test program while cross compiling
+See \`config.log' for more details" "$LINENO" 5; }
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+		#include <stdio.h>
+		#include <stdlib.h>
+		int main(int argc,char **argv,char **envp) {
+		    void *b,*c;
+		    FILE *fp = fopen("conftest1","w");
+		    long n;
+		    #ifdef CAN_UNRANDOMIZE_SBRK
+		    #include "h/unrandomize.h"
+		    #endif
+		    b=alloca(sizeof(b));
+		    c=alloca(sizeof(c));
+		    n=b>c ? b-c : c-b;
+		    n=n>sizeof(c) ? n : 1;
+		    fprintf(fp,"%ld",n);
+		    fclose(fp);
+		    return 0;
+		}
+_ACEOF
+if ac_fn_c_try_run "$LINENO"; then :
+  cstack_alignment=`cat conftest1`
+else
+  cstack_alignment=0
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
+  conftest.$ac_objext conftest.beam conftest.$ac_ext
+fi
+
+
+cat >>confdefs.h <<_ACEOF
+#define CSTACK_ALIGNMENT $cstack_alignment
+_ACEOF
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $cstack_alignment" >&5
+$as_echo "$cstack_alignment" >&6; }
+
+# Check whether --enable-cstackmax was given.
+if test "${enable_cstackmax+set}" = set; then :
+  enableval=$enable_cstackmax; if test "$enableval" != "" ; then
+cat >>confdefs.h <<_ACEOF
+#define CSTACKMAX $enableval
+_ACEOF
+ fi
+fi
+
+
 
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking CSTACK_ADDRESS" >&5
 $as_echo_n "checking CSTACK_ADDRESS... " >&6; }
@@ -6728,7 +6777,6 @@ else
 		#include <stdlib.h>
 		int
 		main(int argc,char **argv,char **envp) {
-		    void *v ;
 		    FILE *fp = fopen("conftest1","w");
 		    unsigned long i,j;
 
@@ -6738,7 +6786,7 @@ else
 		    j=1;
 		    j<<=$PAGEWIDTH;
 		    j<<=16;
-		    i=(unsigned long)&v;
+		    i=(unsigned long)alloca(sizeof(void *));
 		    if ($cstack_direction==1) i-=j;
 		    j--;
 		    i+=j;
@@ -6856,52 +6904,6 @@ rm -f core *.core core.conftest.* gmon.o
 fi
 
 
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking finding CSTACK_ALIGNMENT" >&5
-$as_echo_n "checking finding CSTACK_ALIGNMENT... " >&6; }
-if test "$cross_compiling" = yes; then :
-  { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
-$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
-as_fn_error $? "cannot run test program while cross compiling
-See \`config.log' for more details" "$LINENO" 5; }
-else
-  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-
-		#include <stdio.h>
-		#include <stdlib.h>
-		int main(int argc,char **argv,char **envp) {
-		    void *b,*c;
-		    FILE *fp = fopen("conftest1","w");
-		    long n;
-		    #ifdef CAN_UNRANDOMIZE_SBRK
-		    #include "h/unrandomize.h"
-		    #endif
-		    b=alloca(sizeof(b));
-		    c=alloca(sizeof(c));
-		    n=b>c ? b-c : c-b;
-		    n=n>sizeof(c) ? n : 1;
-		    fprintf(fp,"%ld",n);
-		    fclose(fp);
-		    return 0;
-		}
-_ACEOF
-if ac_fn_c_try_run "$LINENO"; then :
-  cstack_alignment=`cat conftest1`
-else
-  cstack_alignment=0
-fi
-rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
-  conftest.$ac_objext conftest.beam conftest.$ac_ext
-fi
-
-
-cat >>confdefs.h <<_ACEOF
-#define CSTACK_ALIGNMENT $cstack_alignment
-_ACEOF
-
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $cstack_alignment" >&5
-$as_echo "$cstack_alignment" >&6; }
-
 # Check whether --enable-immfix was given.
 if test "${enable_immfix+set}" = set; then :
   enableval=$enable_immfix;
--- gcl-2.6.12.orig/configure.in
+++ gcl-2.6.12/configure.in
@@ -393,11 +393,10 @@ case $use in
 	    ia64*)
 		if test "$enable_debug" != "yes" ; then TO3FLAGS="-O" ; fi #FIXME needed asof gcc 4.8.1
 		;;
-	    armhf*)
-		assert_arg_to_cflags -fdollars-in-identifiers
-		assert_arg_to_cflags -g #?
-		;;
 	    arm*)
+		AC_DEFINE([SET_STACK_POINTER],["mov %%sp,%0\n\t"],[asm string to set the stack pointer])
+		AC_MSG_CHECKING([how to set stack pointer])
+		AC_MSG_RESULT([done])
 		assert_arg_to_cflags -fdollars-in-identifiers
 		assert_arg_to_cflags -g #?
 		;;
@@ -1196,24 +1195,12 @@ AC_RUN_IFELSE(
 	    [[
 		#include <stdio.h>
 		#include <stdlib.h>
-
-		unsigned long w;
-
-		void
-		foo(void) {
-		    int i;
-		    w=(unsigned long)&i;
-		}
-		
-		int
-		main(int argc,char **argv,char **envp) {
-		    void *b;
+		int main(int argc,char **argv,char **envp) {
 		    FILE *fp = fopen("conftest1","w");
 		    #ifdef CAN_UNRANDOMIZE_SBRK
 		    #include "h/unrandomize.h"
 		    #endif
-		    foo();
-		    fprintf(fp,"%d",((unsigned long) &b) > w ? -1 : 1);
+		    fprintf(fp,"%d",(alloca(sizeof(void *))>alloca(sizeof(void *))) ? -1 : 1);
 		    fclose(fp);
 		    return 0;
 		}]])],
@@ -1221,6 +1208,34 @@ AC_RUN_IFELSE(
 AC_DEFINE_UNQUOTED(CSTACK_DIRECTION,$cstack_direction,[whether C stack grows up or down])
 AC_MSG_RESULT($cstack_direction)
 
+AC_MSG_CHECKING([finding CSTACK_ALIGNMENT])
+AC_RUN_IFELSE(
+    [AC_LANG_SOURCE(
+	    [[
+		#include <stdio.h>
+		#include <stdlib.h>
+		int main(int argc,char **argv,char **envp) {
+		    void *b,*c;
+		    FILE *fp = fopen("conftest1","w");
+		    long n;
+		    #ifdef CAN_UNRANDOMIZE_SBRK
+		    #include "h/unrandomize.h"
+		    #endif
+		    b=alloca(sizeof(b));
+		    c=alloca(sizeof(c));
+		    n=b>c ? b-c : c-b;
+		    n=n>sizeof(c) ? n : 1;
+		    fprintf(fp,"%ld",n);
+		    fclose(fp);
+		    return 0;
+		}]])],
+    [cstack_alignment=`cat conftest1`],[cstack_alignment=0])
+AC_DEFINE_UNQUOTED(CSTACK_ALIGNMENT,$cstack_alignment,[C stack alignment])
+AC_MSG_RESULT($cstack_alignment)
+
+AC_ARG_ENABLE([cstackmax],[  --enable-cstackmax=xxxx will ensure that the cstack begins below xxxx or fail],
+	      [if test "$enableval" != "" ; then AC_DEFINE_UNQUOTED([CSTACKMAX],$enableval,[cstack max]) fi])
+
 
 AC_MSG_CHECKING(CSTACK_ADDRESS)
 AC_RUN_IFELSE(
@@ -1230,7 +1245,6 @@ AC_RUN_IFELSE(
 		#include <stdlib.h>
 		int
 		main(int argc,char **argv,char **envp) {
-		    void *v ;
 		    FILE *fp = fopen("conftest1","w");
 		    unsigned long i,j;
 		    
@@ -1240,7 +1254,7 @@ AC_RUN_IFELSE(
 		    j=1;
 		    j<<=$PAGEWIDTH;
 		    j<<=16;
-		    i=(unsigned long)&v;
+		    i=(unsigned long)alloca(sizeof(void *));
 		    if ($cstack_direction==1) i-=j;
 		    j--;
 		    i+=j;
@@ -1304,31 +1318,6 @@ AC_RUN_IFELSE(
     [AC_MSG_RESULT(no)
      neg_cstack_address=0])
 
-AC_MSG_CHECKING([finding CSTACK_ALIGNMENT])
-AC_RUN_IFELSE(
-    [AC_LANG_SOURCE(
-	    [[
-		#include <stdio.h>
-		#include <stdlib.h>
-		int main(int argc,char **argv,char **envp) {
-		    void *b,*c;
-		    FILE *fp = fopen("conftest1","w");
-		    long n;
-		    #ifdef CAN_UNRANDOMIZE_SBRK
-		    #include "h/unrandomize.h"
-		    #endif
-		    b=alloca(sizeof(b));
-		    c=alloca(sizeof(c));
-		    n=b>c ? b-c : c-b;
-		    n=n>sizeof(c) ? n : 1;
-		    fprintf(fp,"%ld",n);
-		    fclose(fp);
-		    return 0;
-		}]])],
-    [cstack_alignment=`cat conftest1`],[cstack_alignment=0])
-AC_DEFINE_UNQUOTED(CSTACK_ALIGNMENT,$cstack_alignment,[C stack alignment])
-AC_MSG_RESULT($cstack_alignment)
-
 AC_ARG_ENABLE([immfix],[  --enable-immfix will enable an immediate fixnum table above the C stack])
 
 AC_ARG_ENABLE([fastimmfix],[  --enable-fastimmfix=XXXX will reject low immediate fixnums unless 2^XXX can be attained],,[enable_fastimmfix=64])
--- gcl-2.6.12.orig/h/att_ext.h
+++ gcl-2.6.12/h/att_ext.h
@@ -272,12 +272,7 @@ object macro_expand();
 
 /*  main.c  */
 EXTER char* system_directory;
-EXTER int ARGC;
-EXTER char **ARGV;
 void error();
-#ifdef UNIX
-EXTER char **ENVP;
-#endif
 object vs_overflow(void);
 
 EXTER object sSAsystem_directoryA;
--- gcl-2.6.12.orig/h/elf32_armhf_reloc.h
+++ gcl-2.6.12/h/elf32_armhf_reloc.h
@@ -4,7 +4,7 @@
      case R_ARM_THM_JUMP24:
       {
     	long x=(long)(s+a-p);
-    	if (abs(x)&(~MASK(22))) {
+    	if (abs(x)&(~MASK(23))) {
 
           got+=(sym->st_size-1)*tz;
     	  memcpy(got,tramp,sizeof(tramp));
--- gcl-2.6.12.orig/h/gclincl.h.in
+++ gcl-2.6.12/h/gclincl.h.in
@@ -26,6 +26,9 @@
    */
 #undef CRAY_STACKSEG_END
 
+/* cstack max */
+#undef CSTACKMAX
+
 /* starting C stack address */
 #undef CSTACK_ADDRESS
 
@@ -336,6 +339,9 @@
 /* system pagewidth */
 #undef PAGEWIDTH
 
+/* asm string to set the stack pointer */
+#undef SET_STACK_POINTER
+
 /* have sigcontext of signal.h */
 #undef SIGNAL_H_HAS_SIGCONTEXT
 
--- gcl-2.6.12.orig/h/unrandomize.h
+++ gcl-2.6.12/h/unrandomize.h
@@ -1,4 +1,5 @@
 #include <sys/personality.h>
+#include <sys/mman.h>
 #include <syscall.h>
 #include <unistd.h>
 #include <string.h>
@@ -61,5 +62,20 @@
 	exit(-1);
       }
     }
+#if defined(CSTACKMAX) && CSTACK_DIRECTION < 0
+    if ((void *)&argc > (void *)CSTACKMAX) {
+      if (mmap((void *)CSTACKMAX-(1L << PAGEWIDTH),(1L << PAGEWIDTH),
+	       PROT_READ|PROT_WRITE|PROT_EXEC,MAP_FIXED|MAP_PRIVATE|MAP_ANON|MAP_STACK|MAP_GROWSDOWN,-1,0)==(void *)-1) {
+	printf("cannot mmap new stack %d\n",errno);
+	exit(-1);
+      }
+#ifdef SET_STACK_POINTER
+      {void *p=(void *)CSTACKMAX-4*CSTACK_ALIGNMENT;asm volatile (SET_STACK_POINTER::"r" (p):"memory");}
+#else
+#error Cannot set stack pointer
+#endif
+    }
+#endif
+
   }
 }
--- gcl-2.6.12.orig/o/main.c
+++ gcl-2.6.12/o/main.c
@@ -503,6 +503,9 @@ which(const char *n,char *o) {
 
 #endif
 
+static int ARGC;
+static char **ARGV;
+
 int
 main(int argc, char **argv, char **envp) {
 
@@ -515,7 +518,7 @@ main(int argc, char **argv, char **envp)
 #include "unrandomize.h"
 #endif
 
-  gcl_init_alloc(&argv);
+  gcl_init_alloc(alloca(1));
 
   setbuf(stdin, stdin_buf); 
   setbuf(stdout, stdout_buf);
@@ -527,7 +530,6 @@ main(int argc, char **argv, char **envp)
 #endif
   ARGC = argc;
   ARGV = argv;
-  ENVP = envp;
   
   vs_top = vs_base = vs_org;
   ihs_top = ihs_org-1;
@@ -539,9 +541,9 @@ main(int argc, char **argv, char **envp)
     printf("GCL (GNU Common Lisp)  %s  %ld pages\n",LISP_IMPLEMENTATION_VERSION,real_maxpage);
     fflush(stdout);
     
-    if (argc>1) {
-      massert(argv[1][strlen(argv[1])-1]=='/');
-      system_directory=argv[1];
+    if (ARGC>1) {
+      massert(ARGV[1][strlen(ARGV[1])-1]=='/');
+      system_directory=ARGV[1];
     }
 
     initlisp();
