[Chibi Scheme] Compilation issues with v0.10, master, TCC and muslc

66 views
Skip to first unread message

Fernando Oleo Blanco

unread,
May 23, 2022, 3:52:06 PM5/23/22
to chibi-...@googlegroups.com
Hi Chibi community,

following John Cowan's recommendation to report back on my testing I
bring forth quite a bit of content.

This is going to be a heavy email. If you think this should be broken
up in different topics, just say so.

TCC is the Tiny C Compiler [1]. It is a small,
fast and quite capable C compiler. It is going to be used as a
bootstrapping compiler [2], that is why I am going to focus on it.

A simple `CC=tcc make` works in both the v0.10 release and master.

------------------------------------
However, a `CC=tcc make CFLAGS=-Os CPPFLAGS=-DSEXP_USE_NO_FEATURES=1`
on v0.10 and master fails with:
```
LD_LIBRARY_PATH=".:/usr/lib64/mpi/gcc/mpich/lib64"
DYLD_LIBRARY_PATH=".:" CHIBI_IGNORE_SYSTEM_PATH=1 CHIBI_MODULE_PATH=lib
./chibi-scheme -q tools/chibi-ffi lib/chibi/filesystem.stub
ERROR: undefined variable: chibi
make: *** [Makefile.libs:73: lib/chibi/filesystem.c] Fehler 70
```
But it does generate a chibi-scheme executable that does seem to run.
This seems like an issue on the Makefile. Taking out
`CPPFLAGS=-DSEXP_USE_NO_FEATURES=1` works as expected.

Trying this target with GCC fails in the exact same way. GCC
v12.1.0 generates quite a few warnings. This may be worth looking into
(probably a missplaced #if/#endif). Clang fails in the same way an
dalso produces a few errors. The GCC and Clang tests where carried out
in master.

The musl-gcc wrapper (a GCC driver that uses musl libc), see [3] fails
with the same error on master.

------------------------------------

On v0.10 and on master trying to compile chibi-scheme-static following
the documentation (so running `CC=tcc make chibi-scheme-static
SEXP_USE_DL=0`) fails to generate the static binary with the following
error:
```
/home/fernando/Builds/tcc-0.9.27-master/tcc -Wall -DSEXP_USE_DL=0 -g
-g3 -O3 -static -DSEXP_USE_DL=0 -o chibi-scheme-static main.o gc.o
sexp.o bignum.o gc_heap.o opcodes.o vm.o eval.o simplify.o -lm -ldl
-lutil
tcc: error: undefined symbol '__ehdr_start'
tcc: error: undefined symbol '__gcc_personality_v0'
tcc: error: undefined symbol '_Unwind_Resume'
tcc: error: undefined symbol '_Unwind_GetCFA'
tcc: error: undefined symbol '_Unwind_ForcedUnwind'
tcc: error: undefined symbol '__multf3'
tcc: error: undefined symbol '__addtf3'
tcc: error: undefined symbol '__unordtf2'
tcc: error: undefined symbol '__letf2'
make: *** [Makefile:135: chibi-scheme-static] Fehler 1
```
This seems like a libc/TCC/GCC issue. Maybe some linker library flag
should be added explicitly for this to work with TCC.

This target worked with GCC and Clang on master. However, when I try to
execute the newly generated chibi-scheme-static binary, I get the
following error:
```
ERROR: undefined variable: |ELF>|
called from <anonymous> on line 211 of file
/usr/local/share/chibi/meta-7.scm
called from <anonymous> on line 1186 of file
/usr/local/share/chibi/init-7.scm
called from <anonymous> on line 255 of file
/usr/local/share/chibi/init-7.scm
called from <anonymous> on line 1253 of file
/usr/local/share/chibi/init-7.scm
called from for1 on line 82 of file /usr/local/share/chibi/init-7.scm
called from for1 on line 82 of file /usr/local/share/chibi/init-7.scm
called from <anonymous> on line 255 of file
/usr/local/share/chibi/init-7.scm
called from call-with-current-continuation on line 823 of file
/usr/local/share/chibi/init-7.scm
called from <anonymous> on line 255 of file
/usr/local/share/chibi/init-7.scm
called from <anonymous> on line 246 of file
/usr/local/share/chibi/meta-7.scm
called from <anonymous> on line 255 of file
/usr/local/share/chibi/init-7.scm
called from for1 on line 81 of file /usr/local/share/chibi/init-7.scm
called from for1 on line 81 of file /usr/local/share/chibi/init-7.scm
called from <anonymous> on line 255 of file
/usr/local/share/chibi/init-7.scm
called from <anonymous> on line 245 of file
/usr/local/share/chibi/meta-7.scm
called from <anonymous> on line 255 of file
/usr/local/share/chibi/init-7.scm
called from for1 on line 81 of file /usr/local/share/chibi/init-7.scm
called from for1 on line 81 of file /usr/local/share/chibi/init-7.scm
called from <anonymous> on line 255 of file
/usr/local/share/chibi/init-7.scm
called from <anonymous> on line 245 of file
/usr/local/share/chibi/meta-7.scm
called from <anonymous> on line 255 of file
/usr/local/share/chibi/init-7.scm
called from for1 on line 81 of file /usr/local/share/chibi/init-7.scm
called from for1 on line 81 of file /usr/local/share/chibi/init-7.scm
called from <anonymous> on line 255 of file
/usr/local/share/chibi/init-7.scm
called from <anonymous> on line 245 of file
/usr/local/share/chibi/meta-7.scm
called from <anonymous> on line 255 of file
/usr/local/share/chibi/init-7.scm
called from for1 on line 80 of file /usr/local/share/chibi/init-7.scm
called from <anonymous> on line 235 of file
/usr/local/share/chibi/meta-7.scm
```

Is this expected? It seems that the static executable is trying to read
my chibi installation in /usr/local... The musl-gcc wrapper generated
the exact same issue: it compiles the target, but fails to run it with
the same error.

-----------------------------------

Trying the `CC=tcc make clibs.c` target on v0.10 fails with the
following error:
```
git ls-files lib | grep .sld |
LD_LIBRARY_PATH=".:/usr/lib64/mpi/gcc/mpich/lib64"
DYLD_LIBRARY_PATH=".:" CHIBI_IGNORE_SYSTEM_PATH=1 CHIBI_MODULE_PATH=lib
./chibi-scheme -q ./tools/chibi-genstatic > clibs.c
fatal: Kein Git-Repository (oder irgendeines der Elternverzeichnisse):
.git
```

It tries to use git when it does not exists, since it it is a release
tarball. The contents of clibs.c is:
```
#include "chibi/eval.h"


struct sexp_library_entry_t sexp_static_libraries_array[] = {
{ NULL, NULL }
};

struct sexp_library_entry_t* sexp_static_libraries =
sexp_static_libraries_array;
```

Which seems to be too empty. This is probably a Makefile issue. It
works, however, when using the git repo. The `git ls-files lib` should
be changed IMH(umble)O.
However, in master, once the clibs.c target has been finished, trying
to run `CC=tcc make -B chibi-scheme-static SEXP_USE_DL=0
CPPFLAGS=-DSEXP_USE_STATIC_LIBS` fails with the same error as
previously documented (undefined symbols).

Trying the clibs.c target with GCC works and generates a fairly long
clibs.c file that seems to be correct. However, trying to run `make -B
chibi-scheme-static SEXP_USE_DL=0 CPPFLAGS=-DSEXP_USE_STATIC_LIBS` as
indicated in the documentation fails with
```
cc -Wall -DSEXP_USE_DL=0 -g -g3 -O3 -static -DSEXP_USE_DL=0 -o
chibi-scheme-static main.o gc.o sexp.o bignum.o gc_heap.o opcodes.o
vm.o eval.o simplify.o -lm -ldl -lutil
/usr/lib64/gcc/x86_64-suse-linux/12/../../../../x86_64-suse-linux/bin/ld:
eval.o: en la función `sexp_find_static_library':
/home/fernando/Builds/chibi-scheme/chibi-scheme/eval.c:1388: referencia
a `sexp_static_libraries' sin definir
/usr/lib64/gcc/x86_64-suse-linux/12/../../../../x86_64-suse-linux/bin/ld:
/home/fernando/Builds/chibi-scheme/chibi-scheme/eval.c:1388: referencia
a `sexp_static_libraries' sin definir
collect2: error: ld returned 1 exit status
make: *** [Makefile:135: chibi-scheme-static] Fehler 1
```

The symbol `sexp_static_libraries' is not defined. The same issue
happens in Clang and musl-gcc.

Also, the clibs.c file is not removed with neither `make clean` nor
`make dist-clean`. I believe this is not intended.

----------------------------------

Sorry for the mix of locales. I do not take this report of issues as a
demand for fixes. I just want to share my experience. The fixes are
probably somewhat simple to implement but probably require knowledge on
Chibi's internals. I sadly cannot afford the time right now...

[1] https://bellard.org/tcc/
[2] https://github.com/fosslinux/live-bootstrap/blob/master/parts.rst
[3] https://www.musl-libc.org/how.html

Thank you for your time. Best regards,
Fer

Alex Shinn

unread,
May 28, 2022, 6:53:17 AM5/28/22
to chibi-...@googlegroups.com
Sorry for the late reply, somehow this got labeled as spam.

In general when trying different build options it's important to "make dist-clean" between commands.  Some of your issues may be related to this (in particular changing compilers or feature flags without cleaning is sure to fail).

The static build with "make chibi-scheme-static SEXP_USE_DL=0" works fine for me, but the resulting binary will not work with locally compiled or system installed Chibi modules.  As a sanity check try "chibi-scheme-static -q" (just load init-7.scm) or "-Q" (just primitives, don't load any files).

To build a static executable with the standard libraries pre-compiled (including those necessary for the default (scheme small) language), do as the manual says[1] and run:

$ make clibs.c
$ make -B chibi-scheme-static SEXP_USE_DL=0 CPPFLAGS=-DSEXP_USE_STATIC_LIBS

(note the -B to recompile all deps).


--
Alex

--
You received this message because you are subscribed to the Google Groups "chibi-scheme" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chibi-scheme...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/chibi-scheme/20220523215157.04bcb15b%40linux.fritz.box.
Reply all
Reply to author
Forward
0 new messages