jlouis / enacl

Erlang bindings for NaCl / libsodium
MIT License
197 stars 59 forks source link

on_load_function_failed #54

Closed BenoitDuffez closed 3 years ago

BenoitDuffez commented 3 years ago

Hello,

I am new to Erlang so this is not likely a bug. I have cross compiled this to enacl_nif.so, after having cross compiled libsodium-1.0.18.

The generated lib references libsodium:

$ readelf -a priv/enacl_nif.so |grep NEEDED
 0x00000001 (NEEDED)                     Shared library: [libsodium.so.18]
 0x00000001 (NEEDED)                     Shared library: [libc.so.6]

which is available on the target:

# ll /usr/lib/libsodium.so*
-rwxr-xr-x    1 root     root      346.7K Dec 22 22:51 /usr/lib/libsodium.so
-rwxr-xr-x    1 root     root      346.7K Dec 22 22:51 /usr/lib/libsodium.so.18
-rwxr-xr-x    1 root     root      346.7K Dec 22 22:51 /usr/lib/libsodium.so.18.1.1

However when I run my erlang app that uses enacl, here's what I get:

Kernel pid terminated (application_controller) ({application_start_failure,kernel,{{shutdown,{failed_to_start_child,kernel_safe_sup,{on_load_function_failed,enacl_nif}}},{kernel,start,[normal,[]]}}})

It seems it fails to load enacl_nif. Does that ring a bell? Did I do something wrong?

Build machine: x86_64 (linux, ubuntu, elementary os) Target machine: armv7hf (linux, busybox)

jlouis commented 3 years ago

The on_load function is used here:

https://github.com/jlouis/enacl/blob/master/src/enacl_nif.erl#L207-L219

I'd check if there's a .so in there (this is the NIF part, it should dynamically load libsodium when it is loaded into the VM.

BenoitDuffez commented 3 years ago

It seems there was a mismatch of the sodium versions. I was using the 18, I switched to 17 and it has solved the problem. It was indeed a .so load error.

Thanks!