sasagawa888 / eisl

ISLisp interpreter/compiler
Other
267 stars 22 forks source link

Build failure on MacOS 14.5 #315

Closed ariane-emory closed 1 month ago

ariane-emory commented 2 months ago

I tried building this on MacOS 14.5 Sonoma and encountered the following build failure. I have included clang -vs output as well as that of kill -l: it does not appear that SIGRTMIN is on the list of signals available.

Any advice on how to proceed? Thanks.

[02:53:30 am] ~/lisp/eisl 🐈 make
cc -Icii/include -g -Wall -Wextra -D_FORTIFY_SOURCE=2 -D_DARWIN_C_SOURCE -I/usr/local/include/ncursesw -I/usr/local/include -U_XOPEN_SOURCE -Inana/src -O3 -flto -DNDEBUG=1 -DWITHOUT_NANA=1 -std=c17 -DSHAREDIR=/usr/local/share/eisl -c main.c -o main.o
main.c:342:12: error: use of undeclared identifier 'SIGRTMIN'
        sigaction(SIGRTMIN, &child_action, NULL);
                  ^
main.c:443:4: error: call to undeclared function 'sigqueue'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
                        sigqueue(getppid(), SIGRTMIN, value);
                        ^
main.c:443:24: error: use of undeclared identifier 'SIGRTMIN'
                        sigqueue(getppid(), SIGRTMIN, value);
                                            ^
main.c:546:31: warning: unused parameter 'sig' [-Wunused-parameter]
void signal_handler_child(int sig, siginfo_t *siginfo, void *context) {
                              ^
main.c:546:62: warning: unused parameter 'context' [-Wunused-parameter]
void signal_handler_child(int sig, siginfo_t *siginfo, void *context) {
                                                             ^
2 warnings and 3 errors generated.
make: *** [main.o] Error 1

[02:53:37 am] ~/lisp/eisl 🐈 clang -v
Apple clang version 15.0.0 (clang-1500.3.9.4)
Target: arm64-apple-darwin23.5.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

[02:53:40 am] ~/lisp/eisl 🐈 kill -l
 1) SIGHUP   2) SIGINT   3) SIGQUIT  4) SIGILL
 5) SIGTRAP  6) SIGABRT  7) SIGEMT   8) SIGFPE
 9) SIGKILL 10) SIGBUS  11) SIGSEGV 12) SIGSYS
13) SIGPIPE 14) SIGALRM 15) SIGTERM 16) SIGURG
17) SIGSTOP 18) SIGTSTP 19) SIGCONT 20) SIGCHLD
21) SIGTTIN 22) SIGTTOU 23) SIGIO   24) SIGXCPU
25) SIGXFSZ 26) SIGVTALRM   27) SIGPROF 28) SIGWINCH
29) SIGINFO 30) SIGUSR1 31) SIGUSR2 

[02:53:45 am] ~/lisp/eisl 🐈 uname -a
Darwin XXXX.local 23.5.0 Darwin Kernel Version 23.5.0: Wed May  1 20:16:51 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T8103 arm64
sasagawa888 commented 2 months ago

It seems that the issue is caused by using functions defined by POSIX but not supported on macOS. I am considering using alternative code for macOS.

sasagawa888 commented 2 months ago

I inserted alternative code at the error location. Please try compiling to see if it works. However, since the signal isn't functioning, the (mp-part) function won't work.

ariane-emory commented 2 months ago

Okay, now the build gets a little bit further before reaching an incompatible function type related error:

[03:48:24 am] ~/lisp/eisl 🐈 git reflog
7c86299 (HEAD -> master, origin/master, origin/HEAD) HEAD@{0}: pull: Fast-forward
ab40127 HEAD@{1}: clone: from github.com:sasagawa888/eisl.git

[03:48:28 am] ~/lisp/eisl 🐈 make clean
rm -f *.o cii/src/except.o cii/src/fmt.o cii/src/str.o cii/src/text.o cii/src/mem.o  dextension.o disl.o library/bit.o library/escape.o library/i18n.o library/logger.o library/ndbm.o library/opengl.o library/regex.o library/tcltk.o library/tcpip.o library/virtty.o library/prolog.o library/datetime.o library/plot.o library/unistd.o eisl edlis

[03:48:31 am] ~/lisp/eisl 🐈 make 
cc -Icii/include -g -Wall -Wextra -D_FORTIFY_SOURCE=2 -D_DARWIN_C_SOURCE -I/usr/local/include/ncursesw -I/usr/local/include -U_XOPEN_SOURCE -Inana/src -O3 -flto -DNDEBUG=1 -DWITHOUT_NANA=1 -std=c17 -DSHAREDIR=/usr/local/share/eisl -c main.c -o main.o
main.c:554:31: warning: unused parameter 'sig' [-Wunused-parameter]
void signal_handler_child(int sig, siginfo_t *siginfo, void *context) {
                              ^
main.c:554:62: warning: unused parameter 'context' [-Wunused-parameter]
void signal_handler_child(int sig, siginfo_t *siginfo, void *context) {
                                                             ^
2 warnings generated.
cc -Icii/include -g -Wall -Wextra -D_FORTIFY_SOURCE=2 -D_DARWIN_C_SOURCE -I/usr/local/include/ncursesw -I/usr/local/include -U_XOPEN_SOURCE -Inana/src -O3 -flto -DNDEBUG=1 -DWITHOUT_NANA=1 -std=c17 -DSHAREDIR=/usr/local/share/eisl -c function.c -o function.o
function.c:4191:16: warning: variable 'str' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
    } else if (isUni6(c)) {
               ^~~~~~~~~
./eisl.h:79:21: note: expanded from macro 'isUni6'
#define isUni6(c)   (((unsigned char)(c) >= 0xfc) && \
                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function.c:4206:10: note: uninitialized use occurs here
    FREE(str);
         ^~~
cii/include/mem.h:20:37: note: expanded from macro 'FREE'
#define FREE(ptr) ((void)(Mem_free((ptr), \
                                    ^~~
function.c:4191:12: note: remove the 'if' if its condition is always true
    } else if (isUni6(c)) {
           ^~~~~~~~~~~~~~~
function.c:4191:16: warning: variable 'str' is used uninitialized whenever '&&' condition is false [-Wsometimes-uninitialized]
    } else if (isUni6(c)) {
               ^~~~~~~~~
./eisl.h:79:22: note: expanded from macro 'isUni6'
#define isUni6(c)   (((unsigned char)(c) >= 0xfc) && \
                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
function.c:4206:10: note: uninitialized use occurs here
    FREE(str);
         ^~~
cii/include/mem.h:20:37: note: expanded from macro 'FREE'
#define FREE(ptr) ((void)(Mem_free((ptr), \
                                    ^~~
function.c:4191:16: note: remove the '&&' if its condition is always true
    } else if (isUni6(c)) {
               ^
./eisl.h:79:22: note: expanded from macro 'isUni6'
#define isUni6(c)   (((unsigned char)(c) >= 0xfc) && \
                     ^
function.c:4125:14: note: initialize the variable 'str' to silence this warning
    char *str, c;
             ^
              = NULL
function.c:4436:20: warning: unused function 'SET_FLAG' [-Wunused-function]
static inline void SET_FLAG(int addr, flag x)
                   ^
3 warnings generated.
cc -Icii/include -g -Wall -Wextra -D_FORTIFY_SOURCE=2 -D_DARWIN_C_SOURCE -I/usr/local/include/ncursesw -I/usr/local/include -U_XOPEN_SOURCE -Inana/src -O3 -flto -DNDEBUG=1 -DWITHOUT_NANA=1 -std=c17 -DSHAREDIR=/usr/local/share/eisl -c extension.c -o extension.o
extension.c:1414:9: warning: unused variable 'i' [-Wunused-variable]
    int i,bytes_read;
        ^
extension.c:1440:1: warning: non-void function does not return a value [-Wreturn-type]
}
^
extension.c:1462:1: warning: non-void function does not return a value [-Wreturn-type]
}
^
extension.c:1594:13: warning: variable 'res' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
    else if(opt == T){
            ^~~~~~~~
extension.c:1603:12: note: uninitialized use occurs here
    return(res);
           ^~~
extension.c:1594:10: note: remove the 'if' if its condition is always true
    else if(opt == T){
         ^~~~~~~~~~~~
extension.c:1564:17: note: initialize the variable 'res' to silence this warning
    int temp,res,n,i,exp,opt;
                ^
                 = 0
4 warnings generated.
cc -Icii/include -g -Wall -Wextra -D_FORTIFY_SOURCE=2 -D_DARWIN_C_SOURCE -I/usr/local/include/ncursesw -I/usr/local/include -U_XOPEN_SOURCE -Inana/src -O3 -flto -DNDEBUG=1 -DWITHOUT_NANA=1 -std=c17 -DSHAREDIR=/usr/local/share/eisl -c syntax.c -o syntax.o
cc -Icii/include -g -Wall -Wextra -D_FORTIFY_SOURCE=2 -D_DARWIN_C_SOURCE -I/usr/local/include/ncursesw -I/usr/local/include -U_XOPEN_SOURCE -Inana/src -O3 -flto -DNDEBUG=1 -DWITHOUT_NANA=1 -std=c17 -DSHAREDIR=/usr/local/share/eisl -c data.c -o data.o
cc -Icii/include -g -Wall -Wextra -D_FORTIFY_SOURCE=2 -D_DARWIN_C_SOURCE -I/usr/local/include/ncursesw -I/usr/local/include -U_XOPEN_SOURCE -Inana/src -O3 -flto -DNDEBUG=1 -DWITHOUT_NANA=1 -std=c17 -DSHAREDIR=/usr/local/share/eisl -c gbc.c -o gbc.o
gbc.c:34:1: warning: unused function 'IS_EMPTY' [-Wunused-function]
DEF_PREDICATE(EMPTY, EMP)
^
./eisl.h:403:24: note: expanded from macro 'DEF_PREDICATE'
    static inline bool IS_ ## NAME (int addr)   \
                       ^
<scratch space>:123:1: note: expanded from here
IS_EMPTY
^
1 warning generated.
cc -Icii/include -g -Wall -Wextra -D_FORTIFY_SOURCE=2 -D_DARWIN_C_SOURCE -I/usr/local/include/ncursesw -I/usr/local/include -U_XOPEN_SOURCE -Inana/src -O3 -flto -DNDEBUG=1 -DWITHOUT_NANA=1 -std=c17 -DSHAREDIR=/usr/local/share/eisl -c cell.c -o cell.o
cell.c:266:16: warning: variable 'res' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
    } else if (!concurrent_flag) {
               ^~~~~~~~~~~~~~~~
cell.c:283:13: note: uninitialized use occurs here
    return (res);
            ^~~
cell.c:266:12: note: remove the 'if' if its condition is always true
    } else if (!concurrent_flag) {
           ^~~~~~~~~~~~~~~~~~~~~~
cell.c:238:12: note: initialize the variable 'res' to silence this warning
    int res;
           ^
            = 0
1 warning generated.
cc -Icii/include -g -Wall -Wextra -D_FORTIFY_SOURCE=2 -D_DARWIN_C_SOURCE -I/usr/local/include/ncursesw -I/usr/local/include -U_XOPEN_SOURCE -Inana/src -O3 -flto -DNDEBUG=1 -DWITHOUT_NANA=1 -std=c17 -DSHAREDIR=/usr/local/share/eisl -c error.c -o error.o
cc -Icii/include -g -Wall -Wextra -D_FORTIFY_SOURCE=2 -D_DARWIN_C_SOURCE -I/usr/local/include/ncursesw -I/usr/local/include -U_XOPEN_SOURCE -Inana/src -O3 -flto -DNDEBUG=1 -DWITHOUT_NANA=1 -std=c17 -DSHAREDIR=/usr/local/share/eisl -c bignum.c -o bignum.o
cc -Icii/include -g -Wall -Wextra -D_FORTIFY_SOURCE=2 -D_DARWIN_C_SOURCE -I/usr/local/include/ncursesw -I/usr/local/include -U_XOPEN_SOURCE -Inana/src -O3 -flto -DNDEBUG=1 -DWITHOUT_NANA=1 -std=c17 -DSHAREDIR=/usr/local/share/eisl -c compute.c -o compute.o
cc -Icii/include -g -Wall -Wextra -D_FORTIFY_SOURCE=2 -D_DARWIN_C_SOURCE -I/usr/local/include/ncursesw -I/usr/local/include -U_XOPEN_SOURCE -Inana/src -O3 -flto -DNDEBUG=1 -DWITHOUT_NANA=1 -std=c17 -DSHAREDIR=/usr/local/share/eisl -c edit.c -o edit.o
cc -Icii/include -g -Wall -Wextra -D_FORTIFY_SOURCE=2 -D_DARWIN_C_SOURCE -I/usr/local/include/ncursesw -I/usr/local/include -U_XOPEN_SOURCE -Inana/src -O3 -flto -DNDEBUG=1 -DWITHOUT_NANA=1 -std=c17 -DSHAREDIR=/usr/local/share/eisl -c syn_highlight.c -o syn_highlight.o
cc -Icii/include -g -Wall -Wextra -D_FORTIFY_SOURCE=2 -D_DARWIN_C_SOURCE -I/usr/local/include/ncursesw -I/usr/local/include -U_XOPEN_SOURCE -Inana/src -O3 -flto -DNDEBUG=1 -DWITHOUT_NANA=1 -std=c17 -DSHAREDIR=/usr/local/share/eisl -c long.c -o long.o
cc -Icii/include -g -Wall -Wextra -D_FORTIFY_SOURCE=2 -D_DARWIN_C_SOURCE -I/usr/local/include/ncursesw -I/usr/local/include -U_XOPEN_SOURCE -Inana/src -O3 -flto -DNDEBUG=1 -DWITHOUT_NANA=1 -std=c17 -DSHAREDIR=/usr/local/share/eisl -c link.c -o link.o
link.c:176:32: error: incompatible function pointer types passing 'void (int, int)' to parameter of type 'fn2' (aka 'int (*)(int, int)')
      [-Wincompatible-function-pointer-types]
    init_f2(WRITE_TO_PIPE_IDX, write_to_pipe);
                               ^~~~~~~~~~~~~
1 error generated.
make: *** [link.o] Error 1
ariane-emory commented 2 months ago

Casting the relevant function pointer on line 176 or link.c might have gotten me a little further:

init_f2(WRITE_TO_PIPE_IDX, (fn2)write_to_pipe);

The build now ends as follows:

cc -flto -Wl,-S,-x main.o function.o extension.o syntax.o data.o gbc.o cell.o error.o bignum.o compute.o edit.o syn_highlight.o long.o link.o cii/src/except.o cii/src/fmt.o cii/src/str.o cii/src/text.o cii/src/mem.o -o eisl   -lpthread
echo '(load "library/compiler.lsp") (compile-file "library/bit.lsp")' | ./eisl -r
Not a function at Unbound function at  Unbound function at 
UNDEF-FUNC"UNDEF-FUNC" "UNDEEasy-ISLisp Ver3.96
F-FUNC"
> ()
UNDEF-VAR> debug mode ?(help)
UNDEF-VAR >>
debug mode ?(help)
>>
UNDEF-VAR
debug mode ?(help)
>>
VARIABLE 
()()debug mode ?(help)
/bin/sh: line 1:  1670 Done                    echo '(load "library/compiler.lsp") (compile-file "library/bit.lsp")'
      1671 Segmentation fault: 11  | ./eisl -r
make: *** [library/bit.o] Error 139

Now an eisl binary is produced, but starting it results in a segfault... I will continue to experiment.

sasagawa888 commented 2 months ago

I think there's an error occurring at the 'apply' function in main.c. It might be due to differences between GCC and Clang.If there are options to make Clang compatible with GCC, please try using them.

sasagawa888 commented 2 months ago

void -> int write_to_pipe(int n, int x);

ariane-emory commented 2 months ago

I did try editing the makefile to use GCC instead of clang and a very similar error occurs:

(some non-fatal warnings omitted for brevity)

gcc-14 -flto -Wl,-S,-x main.o function.o extension.o syntax.o data.o gbc.o cell.o error.o bignum.o compute.o edit.o syn_highlight.o long.o link.o cii/src/except.o cii/src/fmt.o cii/src/str.o cii/src/text.o cii/src/mem.o -o eisl   -lpthread
lto-wrapper: warning: using serial compilation of 8 LTRANS jobs
lto-wrapper: note: see the '-flto' option documentation for more information
echo '(load "library/compiler.lsp") (compile-file "library/bit.lsp")' | ./eisl -r
eisl(29820,0x17187b000) malloc: *** error for object 0x100000001: pointer being freed was not allocated
eisl(29820,0x17187b000) malloc: *** set a breakpoint in malloc_error_break to debug
/bin/sh: line 1: 29819 Done                    echo '(load "library/compiler.lsp") (compile-file "library/bit.lsp")'
     29820 Abort trap: 6           | ./eisl -r
make: *** [library/bit.o] Error 134

[15:01:21 pm] ~/lisp/eisl 🐈 head makefile
head makefile
.POSIX:
.DELETE_ON_ERROR:
CC := gcc-14
#CC := cc
DC := ldc2
LD := $(CC)
ifneq  ($(shell uname),Darwin)
    ifeq  ($(shell uname),OpenBSD)
        LIBS := -lm
    else

[15:01:35 pm] ~/lisp/eisl 🐈 gcc-14 -v
gcc-14 -v
Using built-in specs.
COLLECT_GCC=gcc-14
COLLECT_LTO_WRAPPER=/opt/homebrew/Cellar/gcc/14.1.0/bin/../libexec/gcc/aarch64-apple-darwin23/14/lto-wrapper
Target: aarch64-apple-darwin23
Configured with: ../configure --prefix=/opt/homebrew/opt/gcc --libdir=/opt/homebrew/opt/gcc/lib/gcc/current --disable-nls --enable-checking=release --with-gcc-major-version-only --enable-languages=c,c++,objc,obj-c++,fortran --program-suffix=-14 --with-gmp=/opt/homebrew/opt/gmp --with-mpfr=/opt/homebrew/opt/mpfr --with-mpc=/opt/homebrew/opt/libmpc --with-isl=/opt/homebrew/opt/isl --with-zstd=/opt/homebrew/opt/zstd --with-pkgversion='Homebrew GCC 14.1.0' --with-bugurl=https://github.com/Homebrew/homebrew-core/issues --with-system-zlib --build=aarch64-apple-darwin23 --with-sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 14.1.0 (Homebrew GCC 14.1.0) 
sasagawa888 commented 2 months ago

It might be caused by a lack of memory. Please try reducing the cell size. file ffi.h #define CELLSIZE 20000000 -> 10000000