Re: gauche-c-wrapper's cwcompile stopped working: function is not found

Jens Thiele <[email protected]> Tue, 30 Apr 2024 10:09:01 +0200
Newsgroups gmane.lisp.scheme.gauche
Message-ID <[email protected]>
Jens Thiele <[email protected]> writes:

> i think i found the problem
>
> (bookworm-amd64-sbuild)karme@amalthea:/tmp$ cwcompile -v test-libhello.scm 
> gauche-package compile --verbose --cflags=  --cppflags=   --ldflags=   --libs=  -L. -lhello  libgauche-hello libgauche-hello.stub
> gcc -c    '-I/usr/local/lib/gauche-0.98/0.9.15/include'   -fPIC -o 'libgauche-hello.o' 'libgauche-hello.c'
> gcc '-L/usr/local/lib/gauche-0.98/0.9.15/x86_64-pc-linux-gnu'
> '-L/usr/local/lib/gauche-0.98/site/x86_64-pc-linux-gnu' -shared -o
> libgauche-hello.so 'libgauche-hello.o' -lgauche-0.98 -lmbedtls -lcrypt
> -lrt -lm -lpthread -L. -lhello
>
> but:
>
> (bookworm-amd64-sbuild)karme@amalthea:/tmp$ ldd ./libgauche-hello.so
>         linux-vdso.so.1 (0x00007ffd9b3f9000)
>         libgauche-0.98.so.0.15 => /usr/local/lib/libgauche-0.98.so.0.15 (0x00007f9f5a3a0000)
>         libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f9f5a1bf000)
>         libcrypt.so.1 => /lib/x86_64-linux-gnu/libcrypt.so.1 (0x00007f9f5a183000)
>         libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f9f5a0a4000)
>         /lib64/ld-linux-x86-64.so.2 (0x00007f9f5afb9000)
>
> => the dependency on libhello.so somehow got optimized away?

if i manually add something like this to the stub file:
"extern int bar() { return add(0,10);}"
the dependency isn't optimized away and it works

(bookworm-amd64-sbuild)karme@amalthea:/tmp$ LD_LIBRARY_PATH=. ldd libgauche-hello.so
        linux-vdso.so.1 (0x00007ffd2758e000)
        libgauche-0.98.so.0.15 => /usr/local/lib/libgauche-0.98.so.0.15 (0x00007f39282a9000)
        libhello.so => ./libhello.so (0x00007f39282a4000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f39280c3000)
        libcrypt.so.1 => /lib/x86_64-linux-gnu/libcrypt.so.1 (0x00007f3928087000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f3927fa8000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f3928ec2000)

now I only don't know how to stop the linker from doing this
optimization

jens