Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add libvips version number to shared library SONAME and filename #252

Merged
merged 1 commit into from
Oct 9, 2024

Conversation

lovell
Copy link
Owner

@lovell lovell commented Oct 9, 2024

This should help improve support for multiple versions of sharp that use differing versions of libvips running within the same process by ensuring dlopen accesses the relevant shared library.

Before:

lrwxrwxrwx 1 root root       17 Oct  8 15:05 libvips-cpp.so -> libvips-cpp.so.42
lrwxrwxrwx 1 root root       22 Oct  8 15:05 libvips-cpp.so.42 -> libvips-cpp.so.42.17.5
-rwxr-xr-x 1 root root 16313040 Oct  8 15:05 libvips-cpp.so.42.17.5
-rwxr-xr-x   1 runner  staff  18178880 Oct  8 15:13 libvips-cpp.42.dylib
lrwxr-xr-x   1 runner  staff        20 Oct  8 15:13 libvips-cpp.dylib -> libvips-cpp.42.dylib

After:

lrwxrwxrwx 1 root root       21 Oct  8 18:18 libvips-cpp.so -> libvips-cpp.so.8.15.5
-rwxr-xr-x 1 root root 16313040 Oct  8 18:18 libvips-cpp.so.8.15.5
-rwxr-xr-x   1 runner  staff  18178880 Oct  8 18:26 libvips-cpp.8.15.5.dylib
lrwxr-xr-x   1 runner  staff        24 Oct  8 18:26 libvips-cpp.dylib -> libvips-cpp.8.15.5.dylib

Relates to lovell/sharp#4095

This should help improve support for multiple versions of sharp
that use multiple versions of libvips running within the same
process by ensuring dlopen accesses the relevant shared library.
@lovell lovell requested a review from kleisauke October 9, 2024 07:32
Copy link
Collaborator

@kleisauke kleisauke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Tested with:

Details
$ readelf -d node_modules/@img/sharp-libvips-linux-x64/lib/libvips-cpp.so.42 | grep SONAME
 0x000000000000000e (SONAME)             Library soname: [libvips-cpp.so.42]
$ patchelf --set-soname libvips-cpp.so.8.15.2 node_modules/@img/sharp-libvips-linux-x64/lib/libvips-cpp.so.42
$ mv node_modules/@img/sharp-libvips-linux-x64/lib/libvips-cpp.so.42 node_modules/@img/sharp-libvips-linux-x64/lib/libvips-cpp.so.8.15.2
$ readelf -d node_modules/@img/sharp-libvips-linux-x64/lib/libvips-cpp.so.8.15.2 | grep SONAME
 0x000000000000000e (SONAME)             Library soname: [libvips-cpp.so.8.15.2]
$ readelf -d node_modules/@img/sharp-linux-x64/lib/sharp-linux-x64.node | grep libvips-cpp.so
 0x0000000000000001 (NEEDED)             Shared library: [libvips-cpp.so.42]
$ patchelf --replace-needed libvips-cpp.so.42 libvips-cpp.so.8.15.2 node_modules/@img/sharp-linux-x64/lib/sharp-linux-x64.node
$ node index
8.15.2
{ semver: '8.15.2', isGlobal: false, isWasm: false }
$ LD_DEBUG=libs node index 2>&1 | grep "libvips-cpp.so"
     10200:	find library=libvips-cpp.so.42 [0]; searching
     10200:	  trying file=/redacted/node_modules/fast-average-color-node/node_modules/@img/sharp-linux-x64/lib/../../sharp-libvips-linux-x64/lib/glibc-hwcaps/x86-64-v4/libvips-cpp.so.42
     10200:	  trying file=/redacted/node_modules/fast-average-color-node/node_modules/@img/sharp-linux-x64/lib/../../sharp-libvips-linux-x64/lib/glibc-hwcaps/x86-64-v3/libvips-cpp.so.42
     10200:	  trying file=/redacted/node_modules/fast-average-color-node/node_modules/@img/sharp-linux-x64/lib/../../sharp-libvips-linux-x64/lib/glibc-hwcaps/x86-64-v2/libvips-cpp.so.42
     10200:	  trying file=/redacted/node_modules/fast-average-color-node/node_modules/@img/sharp-linux-x64/lib/../../sharp-libvips-linux-x64/lib/libvips-cpp.so.42
     10200:	calling init: /redacted/node_modules/fast-average-color-node/node_modules/@img/sharp-linux-x64/lib/../../sharp-libvips-linux-x64/lib/libvips-cpp.so.42
     10200:	find library=libvips-cpp.so.8.15.2 [0]; searching
     10200:	  trying file=/redacted/node_modules/@img/sharp-linux-x64/lib/../../sharp-libvips-linux-x64/lib/glibc-hwcaps/x86-64-v4/libvips-cpp.so.8.15.2
     10200:	  trying file=/redacted/node_modules/@img/sharp-linux-x64/lib/../../sharp-libvips-linux-x64/lib/glibc-hwcaps/x86-64-v3/libvips-cpp.so.8.15.2
     10200:	  trying file=/redacted/node_modules/@img/sharp-linux-x64/lib/../../sharp-libvips-linux-x64/lib/glibc-hwcaps/x86-64-v2/libvips-cpp.so.8.15.2
     10200:	  trying file=/redacted/node_modules/@img/sharp-linux-x64/lib/../../sharp-libvips-linux-x64/lib/libvips-cpp.so.8.15.2
     10200:	calling init: /redacted/node_modules/@img/sharp-linux-x64/lib/../../sharp-libvips-linux-x64/lib/libvips-cpp.so.8.15.2
     10200:	calling fini: /redacted/node_modules/fast-average-color-node/node_modules/@img/sharp-linux-x64/lib/../../sharp-libvips-linux-x64/lib/libvips-cpp.so.42 [0]
     10200:	calling fini: /redacted/node_modules/@img/sharp-linux-x64/lib/../../sharp-libvips-linux-x64/lib/libvips-cpp.so.8.15.2 [0]

Of course, running two (or more) instances of libvips in the same process might degrade performance, but that might be better than having version mismatches.

Note that I'm unsure if we should apply the same approach to Windows builds, as these C++ DLLs are also used by projects other than sharp.

@lovell
Copy link
Owner Author

lovell commented Oct 9, 2024

Thanks Kleis, I agree we should not apply this to the Windows builds.

(For sharp the C++ DLL is built/named via gyp.)

@lovell lovell merged commit 1210419 into main Oct 9, 2024
27 checks passed
@lovell lovell deleted the libvips-cpp-version-soname branch October 9, 2024 10:15
akash-akya added a commit to akash-akya/sharp-libvips that referenced this pull request Oct 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants