chibi-scheme icon indicating copy to clipboard operation
chibi-scheme copied to clipboard

Will not execute after being compiled on Termux

Open kozross opened this issue 7 years ago • 8 comments

I compiled a git clone of the Chibi repo on Termux, using Clang. This produced the following warning at the link step:

WARNING: linker: libchibi-scheme.so.0: unused DT entry: type 0xf arg 0x2152

I then attempted to run the Chibi interpreter as follows:

$ LD_LIBRARY_PATH=/data/data/com.termux/files/home/chibi-scheme ./chibi-scheme

The LD_LIBRARY_PATH is the directory where Chibi's code got cloned to. I then get the above warning, and then the following error:

ERROR: count's load dynamic library: "./lib/srfi/18/threads.so"

Am I doing something wrong, or is this a bug?

kozross avatar Jul 07 '17 23:07 kozross

Clang is the primary compiler I use for Chibi development, I'm surprised you're having problems.

Are you sure the error is "count's load" and not "couldn't load"?

LD_LIBRARY_PATH is needed to find libchibi-scheme.so, but the chibi dynamically loaded libraries are searched for in the module path. If you run "make install" then this path (defaulting to /usr/local/lib/chibi/) will be searched automatically. ./ and ./lib/ are also automatically searched. For testing, if you neither want to install nor run from the build directory for some reason then you can use chibi-scheme -I /path/to/libraries/.

ashinn avatar Jul 08 '17 23:07 ashinn

Yeah, it was "couldn't load" - this is what happens when I retype things from a tablet.

The problems are not Clang-specific, but rather, Android (and Termux)-specific I think. I wanted to try Chibi after compiling it (Termux doesn't supply it as a package), and got this issue before I could even get to installing.

Per your suggestion, I tried

$ LD_LIBRARY_PATH=/data/data/com.termux/files/home/chibi-scheme ./chibi-scheme -I /data/data/com.termux/files/home/chibi-scheme/lib
WARNING: linker: libchibi-scheme.so.0: unused DT entry: type 0xf arg 0x2153
ERROR: couldn't load dynamic library: "/data/data/com.termux/files/home/chibi-scheme/lib/srfi/18/threads.so
$ ls -A /data/data/com.termux/files/home/chibi-scheme/lib/srfi/18
interface.scm test.sld threads.c threads.so types.scm

Am I missing something?

kozross avatar Jul 09 '17 07:07 kozross

According to this, https://stackoverflow.com/questions/33206409/unused-dt-entry-type-0x1d-arg, it looks like you're cross-compiling with the wrong flags, most likely the RLDFLAGS from Makefile.detect. You can try unsetting this, it shouldn't strictly be needed. If that doesn't help, can you try some of the debugging from the SO answer and send me the output?

ashinn avatar Jul 10 '17 13:07 ashinn

I unset RLDFLAGS in the appropriate makefile, and I compiled and linked everything without warnings. However, I still get this:

$ LD_LIBRARY_PATH=`pwd` ./chibi-scheme -I`pwd`/lib
ERROR: couldn't load dynamic library: "/data/data/com.termux/files/home/chibi-scheme/lib/srfi/18/threads.so"
$ pwd
/data/data/com.termux/files/home/chibi-scheme
$ ls -A `pwd`/lib/srfi/18
interface.scm  test.sld  threads.c  threads.so  types.scm

Not sure that anything in that SO answer covers this issue as far as I can tell. I believe that, given that this is an Android problem, you might want to add Android platform detection (and not setting of these flags). Your uname-based approach should work (uname -o returns Android on Androids).

kozross avatar Jul 10 '17 23:07 kozross

I've added detection for Android.

It looks like Android expects shared libraries in pre-specified directories and won't honor LD_LIBRARY_PATH? https://stackoverflow.com/questions/15719149/how-to-integrate-native-runtime-library-with-dlopen-on-ndk. You may want to try building chibi-scheme-static.

ashinn avatar Aug 26 '17 13:08 ashinn

@ashinn I tried a fresh clone and doing make chibi-scheme-static. When I did so, the process went as far as linking, but then errored out:

cc -Wall -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
/data/data/com.termux/files/usr/bin/ld: cannot find -lm
/data/data/com.termux/files/usr/bin/ld: cannot find -lc
clang-4.0: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [Makefile:146: chibi-scheme-static] Error 1

Looking into it further, I can't seem to find a static libc anywhere (something called libc.a), which I presume is the cause of this.

kozross avatar Aug 28 '17 22:08 kozross

Hmmm... actually you don't need a static executable, you just need to disable dynamic lib loading. You should be to do:

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

ashinn avatar Aug 29 '17 14:08 ashinn

@ashinn I tried these steps. I got as far as the last one, when I got this:

cc -DSEXP_USE_STATIC_LIBS -Iinclude  -Wall -DSEXP_USE_DL=0 -g -g3 -O3   -o chibi-scheme main.o -L. -lchibi-scheme
./libchibi-scheme.so: undefined reference to `sexp_static_libraries'
clang-4.0: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [Makefile:143: chibi-scheme] Error 1

kozross avatar Aug 29 '17 22:08 kozross