~ruther/guix-local

158a30fc032dd60fe98590719410c49d16201917 — Guillaume Le Vaillant 7 months ago 70a45f3
gnu: sbcl: Fix build on arm64.

* gnu/packages/patches/sbcl-fix-arm64-shared-lib.patch: New file.
* gnu/local.mk (dist_patch_DATA): Register it.
* gnu/packages/lisp.scm (sbcl)[source]: Use it.

Change-Id: Icb49d76e0e68e02f7e7bb9ef49ce862dcce3969a
3 files changed, 132 insertions(+), 0 deletions(-)

M gnu/local.mk
M gnu/packages/lisp.scm
A gnu/packages/patches/sbcl-fix-arm64-shared-lib.patch
M gnu/local.mk => gnu/local.mk +1 -0
@@ 2273,6 2273,7 @@ dist_patch_DATA =						\
  %D%/packages/patches/sajson-for-gemmi-numbers-as-strings.patch	\
  %D%/packages/patches/sajson-build-with-gcc10.patch		\
  %D%/packages/patches/sbc-fix-build-non-x86.patch		\
  %D%/packages/patches/sbcl-fix-arm64-shared-lib.patch		\
  %D%/packages/patches/sbcl-aserve-add-HTML-5-elements.patch	\
  %D%/packages/patches/sbcl-aserve-fix-rfe12668.patch	\
  %D%/packages/patches/sbcl-burgled-batteries3-fix-signals.patch	\

M gnu/packages/lisp.scm => gnu/packages/lisp.scm +2 -0
@@ 1413,6 1413,8 @@ be built as a stand-alone REPL interpreter.")
                           version "-source.tar.bz2"))
       (sha256
        (base32 "1bm9hvsrg21mzqhcayiyghz0nkfp43ks840p0bg3bxlma22kwq57"))
       ;; TODO: Remove this patch when upgrading to SBCL > 2.5.8.
       (patches (search-patches "sbcl-fix-arm64-shared-lib.patch"))
       (modules '((guix build utils)))
       (snippet
        '(begin

A gnu/packages/patches/sbcl-fix-arm64-shared-lib.patch => gnu/packages/patches/sbcl-fix-arm64-shared-lib.patch +129 -0
@@ 0,0 1,129 @@
From b25c5a9f89922554e1221dab761e1eb583113953 Mon Sep 17 00:00:00 2001
From: Douglas Katzman <dougk@google.com>
Date: Thu, 4 Sep 2025 13:28:15 -0400
Subject: [PATCH 1/2] Change asm to avoid 'ld' error making libsbcl.so on linux

Fixes lp#2122059
---
 src/runtime/arm64-assem.S | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/runtime/arm64-assem.S b/src/runtime/arm64-assem.S
index 95e0bfc89..b708f4ca0 100644
--- a/src/runtime/arm64-assem.S
+++ b/src/runtime/arm64-assem.S
@@ -235,9 +235,15 @@ no_args:
 
         // load CARDTABLE-TN. reg_NAME macros aren't autogenerated for native asm code
         // and it hardly seems worth #defining it to use in one assembly statement.
+#ifdef LISP_FEATURE_LINUX
+	adrp	x28, :got:gc_card_mark
+	ldr	x28, [x28, #:got_lo12:gc_card_mark]
+	ldr	x28, [x28]
+#else
         adrp x28, PAGE(gc_card_mark)
         add x28, x28, PAGELOW(gc_card_mark)
         ldr x28, [x28]
+#endif
 
         // Load the closure-fun (or simple-fun-self), in case we're
 	// trying to call a closure.
-- 
2.51.0

From 076ae8dfc67d23bda158666847c5f1b627d90778 Mon Sep 17 00:00:00 2001
From: Stas Boukarev <stassats@gmail.com>
Date: Thu, 4 Sep 2025 20:39:24 +0300
Subject: [PATCH 2/2] Fix libsbcl.so on linux arm64

It got already fixed but this one has a macro.
---
 src/runtime/GNUmakefile   |  2 +-
 src/runtime/arm64-assem.S | 43 ++++++++++++++++++++++-----------------
 2 files changed, 25 insertions(+), 20 deletions(-)

diff --git a/src/runtime/GNUmakefile b/src/runtime/GNUmakefile
index cb34b5586..3a63d1c67 100644
--- a/src/runtime/GNUmakefile
+++ b/src/runtime/GNUmakefile
@@ -138,7 +138,7 @@ libsbcl.so: $(PIC_OBJS)
 %.pic.o: %.c
 	$(CC) -fPIC -c $(CPPFLAGS) $(filter-out -fno-pie,$(CFLAGS)) $< -o $@
 %.pic.o: %.S # (-fPIC doesn't affect hand-written assembly source)
-	$(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@
+	$(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@ -DLIBSBCL
 
 SHRINKWRAP_DEPS = ../../output/sbcl.core ../../tools-for-build/elftool.lisp
 shrinkwrap-sbcl.s shrinkwrap-sbcl-core.o: $(SHRINKWRAP_DEPS)
diff --git a/src/runtime/arm64-assem.S b/src/runtime/arm64-assem.S
index b708f4ca0..1794fc60e 100644
--- a/src/runtime/arm64-assem.S
+++ b/src/runtime/arm64-assem.S
@@ -13,24 +13,37 @@
 
 #endif
 
-#ifdef LISP_FEATURE_DARWIN
-#define GNAME(var) _##var
-#define PAGE(var) _##var@PAGE
-#define PAGELOW(var) _##var@PAGEOFF
-#else
-#define GNAME(var) var
-#define PAGE(var) var
-#define PAGELOW(var) #:lo12:##var
-#endif
-
 #ifdef LISP_FEATURE_DARWIN
 #define TYPE(name)
 #define SIZE(name)
+#define GNAME(var) _##var
+
+.macro  LOAD_GNAME, dest, symbol
+    adrp    \dest, _\symbol@PAGE
+    ldr     \dest, [\dest, _\symbol@PAGEOFF]
+.endm
+
 #else
+
 #define TYPE(name) .type name,%function
 #define SIZE(name) .size name,.-name
+#define GNAME(var) var
+
+#ifdef LIBSBCL
+.macro  LOAD_GNAME, dest, symbol
+    adrp    \dest, :got:\symbol
+    ldr     \dest, [\dest, #:got_lo12:\symbol]
+    ldr     \dest, [\dest]     
+.endm
+#else
+.macro  LOAD_GNAME, dest, symbol
+    adrp    \dest, \symbol
+    ldr     \dest, [\dest, #:lo12:\symbol]
+.endm
+#endif
 #endif
 
+
 #ifdef LISP_FEATURE_SB_THREAD
 .macro ENTER_PA
         str reg_wNULL,[reg_THREAD,THREAD_PSEUDO_ATOMIC_BITS_OFFSET]
@@ -235,15 +248,7 @@ no_args:
 
         // load CARDTABLE-TN. reg_NAME macros aren't autogenerated for native asm code
         // and it hardly seems worth #defining it to use in one assembly statement.
-#ifdef LISP_FEATURE_LINUX
-	adrp	x28, :got:gc_card_mark
-	ldr	x28, [x28, #:got_lo12:gc_card_mark]
-	ldr	x28, [x28]
-#else
-        adrp x28, PAGE(gc_card_mark)
-        add x28, x28, PAGELOW(gc_card_mark)
-        ldr x28, [x28]
-#endif
+        LOAD_GNAME x28, gc_card_mark
 
         // Load the closure-fun (or simple-fun-self), in case we're
 	// trying to call a closure.
-- 
2.51.0