Clozure CL on musl systems

Back when I wrote this admittedly shoddy monkey patch, it was probably the simplest way to get a Lisp system running under musl. Nowadays ECL should be able to do the job. I would have upstreamed this, but see below. This page mostly exists for historical reasons but maybe somebody will find it useful.

The compatibility issues are:

--- ccl/lisp-kernel/lisp-debug.c	2017-11-29 00:25:49.000000000 +0100
+++ ccl_patched/lisp-kernel/lisp-debug.c	2018-04-07 00:23:43.000000000 +0200
@@ -22,6 +22,7 @@
 #include <ctype.h>
 #include <stdio.h>
 #include <stddef.h>
+#include <stdint.h>
 #include <string.h>
 #include <stdarg.h>
 #include <errno.h>
@@ -1134,6 +1135,11 @@
   return debug_continue;
 }

+#if X8664 && defined(LINUX)
+struct x8664_xmmreg {
+  uint32_t element[4];
+};
+#endif

 debug_command_return
 debug_show_fpu(ExceptionInformation *xp, siginfo_t *info, int arg)
@@ -1151,7 +1158,7 @@
 #endif
 #ifdef X8664
 #ifdef LINUX
-  struct _libc_xmmreg * xmmp = NULL;
+  struct x8664_xmmreg * xmmp = NULL;
 #endif
 #ifdef DARWIN
   struct xmm {
@@ -1175,7 +1182,7 @@

 #ifdef LINUX
   if (xp->uc_mcontext.fpregs)
-    xmmp = &(xp->uc_mcontext.fpregs->_xmm[0]);
+    xmmp = (struct x8664_xmmreg*)&(xp->uc_mcontext.fpregs->_xmm[0]);
   else
     /* no fp state, apparently */
     return debug_continue;
--- ccl/lisp-kernel/pmcl-kernel.c	2017-11-29 00:25:49.000000000 +0100
+++ ccl_patched/lisp-kernel/pmcl-kernel.c	2018-04-07 19:14:15.000000000 +0200
@@ -35,7 +35,7 @@
 #endif

 #ifdef LINUX
-#ifndef ANDROID
+#if !defined(ANDROID) && defined(__GLIBC__)
 #include <mcheck.h>
 #endif
 #include <dirent.h>
@@ -1711,6 +1711,16 @@
 #include <asm/prctl.h>
 #include <sys/prctl.h>

+#ifndef __GLIBC__
+static char *
+gnu_get_libc_version(void)
+{
+	static char ver[] = "(not glibc)";
+
+	return ver;
+}
+#endif
+
 void
 ensure_gs_available(char *progname)
 {
--- ccl/lisp-kernel/x86-exceptions.c	2017-11-29 00:25:49.000000000 +0100
+++ ccl_patched/lisp-kernel/x86-exceptions.c	2018-04-02 21:22:36.000000000 +0200
@@ -29,7 +29,6 @@
 #ifdef LINUX
 #include <strings.h>
 #include <sys/mman.h>
-#include <fpu_control.h>
 #include <linux/prctl.h>
 #endif
 #ifdef DARWIN
--- ccl/lisp-kernel/linuxx8664/Makefile	2017-11-29 00:25:49.000000000 +0100
+++ ccl_patched/lisp-kernel/linuxx8664/Makefile	2018-04-03 05:31:45.000000000 +0200
@@ -22,7 +22,7 @@
 ASFLAGS = --64
 M4FLAGS = -DLINUX -DX86 -DX8664 -DHAVE_TLS
 CDEFINES = -DLINUX -D_REENTRANT -DX86 -DX8664 -D_GNU_SOURCE -DHAVE_TLS  -DVC_REVISION=$(VC_REVISION) #-DDISABLE_EGC -DUSE_FUTEX
 CDEBUG = -g
-COPT = -O2
+COPT = -O2 -fno-pie
 # Once in a while, -Wformat says something useful.  The odds are against that,
 # however.
@@ -75,4 +75,4 @@

 ../../lx86cl64: $(KSPOBJ) $(KERNELOBJ) $(DEBUGOBJ) Makefile  $(LINK_MAP)
-	$(CC)  -m64 $(CDEBUG)  -Wl,--export-dynamic $(HASH_STYLE) -o $@ $(USE_LINK_MAP) $(KSPOBJ) $(KERNELOBJ) $(DEBUGOBJ) -Wl,--no-as-needed $(OSLIBS)
+	$(CC) -no-pie -m64 $(CDEBUG)  -Wl,--export-dynamic $(HASH_STYLE) -o $@ $(USE_LINK_MAP) $(KSPOBJ) $(KERNELOBJ) $(DEBUGOBJ) -Wl,--no-as-needed $(OSLIBS)

--- ccl/level-0/l0-cfm-support.lisp	2017-11-29 00:25:49.000000000 +0100
+++ ccl_patched/level-0/l0-cfm-support.lisp	2018-04-07 19:53:25.000000000 +0200
@@ -233,10 +233,8 @@
					     (if (and (> udisp (pref map :link_map.l_addr))
						      (< udisp (%ptr-to-int dynamic-entries)))
					       (%int-to-ptr udisp)
					       (%int-to-ptr 
-                                               (if (< disp 0) 
-                                                 (+ disp (pref map :link_map.l_addr))
-                                                 disp))))))))
+                                               (+ disp (pref map :link_map.l_addr)))))))))
		 (%setf-macptr dynamic-entries
			       (%inc-ptr dynamic-entries
					 #+32-bit-target

Date: 2022-01-31 23:41:45