Skip to content

ffi does not form libname correctly on Alpine #727

Description

@jcupitt

Hello, thank you for this very useful gem.

On Alpine (a non-glibc Linux), it fails to guess versioned library names correctly. Here's what happens:

  1. My gem needs to open the library glib-2.0. This shared library is installed like this on Alpine:
/ # ls /usr/lib/libglib*
/usr/lib/libglib-2.0.so.0         /usr/lib/libglib-2.0.so.0.5800.1

ie. the .so symlink is only installed with the glib-dev package. This means ffi will need an ABI version. My library therefore asks ffi for glib-2.0.so.0.

  1. ffi_lib calls map_library_name to turn this into a platform native name. This adds a lib prefix to make libglib-2.0.so.0 (the correct name).

  2. However, ffi then checks FFI::Platform::IS_GNU, finds it nil (this is a musl Linux, not glibc), and erroneously adds an extra .so suffix.

  3. libglib-2.0.so.0.so is not found and my gem fails to start.

Here's the map_library_name method for reference:

https://github.com/ffi/ffi/blob/master/lib/ffi/library.rb#L34

I'm probably being naive here, but it seems to me that IS_GNU is being used to mean something like "is linux" (ie. not macos or win).

How about changing that line to be:

      r = Platform::IS_WINDOWS || Platform::IS_MAC ? 
          "\\.#{Platform::LIBSUFFIX}$" :
          "\\.so($|\\.[1234567890]+)" 

ie. only attach the suffix on windows and mac (the only two platforms which always use it, I think).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions