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

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

> What's the output of `nm libhello.so`?

(bookworm-amd64-sbuild)karme@amalthea:/tmp$ nm libhello.so 
0000000000003e78 d _DYNAMIC
0000000000003fe8 d _GLOBAL_OFFSET_TABLE_
                 w _ITM_deregisterTMCloneTable
                 w _ITM_registerTMCloneTable
00000000000020a0 r __FRAME_END__
0000000000002000 r __GNU_EH_FRAME_HDR
0000000000004008 d __TMC_END__
                 w __cxa_finalize
00000000000010b0 t __do_global_dtors_aux
0000000000003e70 d __do_global_dtors_aux_fini_array_entry
0000000000004000 d __dso_handle
0000000000003e68 d __frame_dummy_init_array_entry
                 w __gmon_start__
0000000000001110 t _fini
0000000000001000 t _init
00000000000010f9 T add
0000000000004008 b completed.0
0000000000001040 t deregister_tm_clones
00000000000010f0 t frame_dummy
0000000000001070 t register_tm_clones

> Could you also try the following patch to src/c-ffi.c?   My take is that
> the error is raised because dlsym returns NULL here, but I want to make
> sure.
>
> ```
> *** c-ffi.c.orig Sun Apr 28 22:32:10 2024
> --- c-ffi.c Mon Apr 29 21:14:27 2024
> ***************
> *** 624,630 ****
>
>   static void *lookup_symbol(const char *sym)
>   {
> !     return dlsym(RTLD_DEFAULT, sym);
>   }
>
>   #endif
> --- 624,632 ----
>
>   static void *lookup_symbol(const char *sym)
>   {
> !     void *r = dlsym(RTLD_DEFAULT, sym);
> !     fprintf(stderr, "dlsym(%s) => %p\n", sym, r);
> !     return r;
>   }
>
>   #endif
> ```

(bookworm-amd64-sbuild)karme@amalthea:/tmp$ LD_LIBRARY_PATH=. ./test-libhello.scm 
#?="././test-libhello.scm":13:(add 10 32)
dlsym(add) => (nil)
*** ERROR: function add is not found.
Stack Trace:
_______________________________________
  0  (report-error e)
  1  (add 10 32)
        at "././test-libhello.scm":13
  2  (main args)

jens