Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions lang/chicken-scheme/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2019-2020 Jerônimo Cordoni Pellegrini <j_p@aleph0.info>
# Copyright (C) 2019-2024 Jerônimo Pellegrini <j_p@aleph0.info>
#
# This file is free software, licensed under the GNU General Public License v3
# or later.
Expand All @@ -8,13 +8,13 @@
include $(TOPDIR)/rules.mk

PKG_NAME:=chicken-scheme
PKG_VERSION:=5.2.0
PKG_RELEASE:=2
Comment thread
BKPepe marked this conversation as resolved.
PKG_VERSION:=5.4.0
PKG_RELEASE:=1

PKG_BUILD_DIR:=$(BUILD_DIR)/chicken-$(PKG_VERSION)
PKG_SOURCE:=chicken-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=https://code.call-cc.org/releases/$(PKG_VERSION)/
PKG_HASH:=819149c8ce7303a9b381d3fdc1d5765c5f9ac4dee6f627d1652f47966a8780fa
PKG_HASH:=3c5d4aa61c1167bf6d9bf9eaf891da7630ba9f5f3c15bf09515a7039bfcdec5f
PKG_MAINTAINER:=Jeronimo Pellegrini <j_p@aleph0.info>

PKG_LICENSE:=BSD-3-Clause
Expand All @@ -30,9 +30,12 @@ define Package/chicken-scheme/Default
ABI_VERSION:=11
endef

##
## chicken-scheme-interpreter
##

###############################
###
### chicken-scheme-interpreter
###
###############################

define Package/chicken-scheme-interpreter
$(call Package/chicken-scheme/Default)
Expand Down Expand Up @@ -73,27 +76,33 @@ $(eval $(call BuildPackage,chicken-scheme-interpreter))



##
## chicken-scheme-full
##
########################
###
### chicken-scheme-full
###
########################

## ABOUT NOT STRIPPING THE BINARIES:
## --------------------------------
#
# mips-openwrt-linux-musl-gcc dowsn't seem to link with libchicken.so.
# already tried -lchicken and passing /usr/lib/libchicken.so on the command
# line.
# also tried -Wl,-R/usr/lib,-R/usr/lib/chicken/$(ABI_VERSION)
Comment on lines 88 to 91
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit skeptical if that's the case, but at the very least no-stripping can be architecture-specific to MIPS. Something like (you'll need to actually test if this works of course):

ifneq ($(filter $(CONFIG_ARCH),mips mipsel),)
  RSTRIP:=:
  STRIP:=:
endif

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And can you post the relevant log output when linking fails on MIPS? I'm curious.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at the very least no-stripping can be architecture-specific to MIPS

Hmmm, interesting. I'll check!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And can you post the relevant log output when linking fails on MIPS? I'm curious.

So - after the compiler is built and installed on the device, it will call mips-openwrt-linux-musl-gcc:

root@router:~# csc -v hello.scm 
'/usr/bin/chicken' 'hello.scm' -output-file 'hello.c' '-verbose'
'mips-openwrt-linux-musl-gcc' 'hello.c' -o 'hello.o' -c  '-fno-strict-aliasing' '-fwrapv' '-DHAVE_CHICKEN_CONFIG_H' '-DC_ENABLE_PTABLES' '-Os' '-pipe' '-mno-branch-likely' '-mips32r2' '-mtune=24kc' '-fno-caller-saves' '-fno-plt' '-fhonour-copts' '-msoft-float' '-mips16' '-minterlink-mips16' '-Wformat' '-Werror=format-security' '-fstack-protector' '-D_FORTIFY_SOURCE=1' '-Wl,-z,now' '-Wl,-z,relro' '-I/usr/include/chicken'
rm hello.c
'mips-openwrt-linux-musl-gcc' 'hello.o' -o 'hello' '-L/usr/lib' '-Wl,-rpath=/usr/lib' -lchicken -lm 
/usr/bin/ld: /usr/lib/libchicken.so: error adding symbols: file in wrong format
collect2: error: ld returned 1 exit status

Error: shell command terminated with non-zero exit status 256: 'mips-openwrt-linux-musl-gcc' 'hello.o' -o 'hello' '-L/usr/lib' '-Wl,-rpath=/usr/lib' -lchicken -lm 

That is the error...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do think that the trivial CI test is not enough. I'll add a test to check if csc can compile a trivial program, like a "Hello world".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps an alternative to either stripping all or nothing, could be stripping some sections. e.g. debug info.

Yes, but it seems like there is something else going on... Probably the filter I used in the Makefile is not correct. I'll do the partial stripping as you suggest, and also try to get the tests to work properly.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps an alternative to either stripping all or nothing, could be stripping some sections. e.g. debug info.

But how do I do that? The buildroot seems to offer superstrip only, and it doesn't seem to support many option flags. In particular, it doesn't seem to be possible to choose what to strip

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First of all make sure this builds and compile tests pass. Even without stripping. Then figure out the MIPS issue. And leave the stripping till after i.e. leave it unstripped, as that's the least important. You can always selectively strip the binaries yourself.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I removed the stripping pass (or so I believe - am I wrong?) and half of the archs still fail. But this time "csc was not found". i'll check

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you test this locally? Does the build produce working binaries?

#
# current solution: we do not strip binaries in chicken-scheme-full
# we do this by unsetting STRIP and RSTRIP, *and* reloading rules.mk
#
# Here:
STRIP:=:
RSTRIP:=:

include $(TOPDIR)/rules.mk

define Package/chicken-scheme-full
$(call Package/chicken-scheme/Default)
TITLE+=full package
# csc depends on gcc; chicken-install uses the 'install' command from coreutils
DEPENDS:=gcc coreutils-install
DEPENDS:=+gcc +coreutils-install
endef

define Package/chicken-scheme-full/description
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
From: Jeronimo Pellegrini <j_p@aleph0.info>
Date: 2025-11-20
Subject: Patch description - fix Chicken Scheme compiler behavior

Chicken is a Scheme interpreter and compiler. csi is the interpreter,
and csc is the compiler, which translates Scheme into C and calls gcc.

This patch changes the compiler, csc.

The Chicken build system will dynamically build the file chicken-config.h,
and for OpenWRT this is done *inside the buildroot*. But then, the values
in that file are hardcoded into the csc binary, and they don't work well
in the target device:
1. -ldl is passed to ld
2. -fmacro-prefix-map=... is passed to gcc, with the original path from the
buildroot
and these two will not work on OpenWRT (and are not needed anyway), so the
patch included actually modifies the build system to remove those two flags.
Then csc works on the target device!

Signed-off-by: Jeronimo Pellegrini <j_p@aleph0.info>

--- a/defaults.make
+++ b/defaults.make
@@ -506,6 +506,8 @@ else
endif
$(call echo, >>, $@,#endif)
$(call echo, >>, $@,/* END OF FILE */)
+ # For OpenWRT:
+ sed -i -e's/\-fmacro-prefix-map[^ ]*//' -e's/\-ldl//' $@

chicken-install.rc:
$(call echo, >, $@,/* GENERATED */)
22 changes: 22 additions & 0 deletions lang/chicken-scheme/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh

# Tries to run csi to check if the version is the same that
# we believe is being built.
csi -version 2>1 | grep -F "$2"

if [ $? -ne 0 ]
then
echo "csi version different from expected"
return 1
fi

# Tries to compile silent.scm. If it fails, then csc is not
# suitable for packaging. We just send an S-expression to its
# standard input. If this fails, csc is not working.
echo "(+ 2 3)" | csc -

if [ $? -ne 0 ]; then
echo "csc cannot compile a s-expression from standard input"
return 2
fi

Loading