Skip to content

cmake: soname for output .so file - #5935

Closed
jainvishal wants to merge 2 commits into
curl:bagder/sonamefrom
jainvishal:bagder/soname
Closed

jainvishal wants to merge 2 commits into
curl:bagder/sonamefrom
jainvishal:bagder/soname

Conversation

@jainvishal

Copy link
Copy Markdown

Originally the output .so file lacked the soname number under CMake.
It was available in makefile. The change collects the libcurl version
from libcurl.soname and then uses it for generated .so file.

Originally the output .so file lacked the soname number under CMake.
It was available in makefile. The change collects the libcurl version
from libcurl.soname and then uses it for generated .so file.
@bagder bagder added the cmake label Sep 8, 2020
@bagder

bagder commented Sep 8, 2020

Copy link
Copy Markdown
Member

Does this also make make install work correctly ?

Further, does it setup the symlinks for .so and .so.4 ? When I build curl with configure (and if I check my Linux distro installation) the libs look like this:

$ ls -l libcurl.so*
lrwxrwxrwx 1 daniel daniel     16 Sep  8 07:58 libcurl.so -> libcurl.so.4.7.0
lrwxrwxrwx 1 daniel daniel     16 Sep  8 07:58 libcurl.so.4 -> libcurl.so.4.7.0
-rwxr-xr-x 1 daniel daniel 632216 Sep  8 07:58 libcurl.so.4.7.0

@jzakrzewski

Copy link
Copy Markdown
Contributor

Yeah, I've tried to do that once already. You haven't taken into account other platforms. This seems to be correct for linux but will diverge from what autotools produce on other supported platforms. See my failed try here: https://github.com/jzakrzewski/curl/commits/soname
Unfortunately, I haven't got time to get back to it to fix all the review issues...

@bagder

bagder commented Sep 8, 2020

Copy link
Copy Markdown
Member

@jzakrzewski do you think it would work as a first step if @jainvishal restricted this particular new logic to just Linux?

I'm thinking it could be worth taking it step by step and fixing this one platform at a time.

@jzakrzewski

Copy link
Copy Markdown
Contributor

@bagder yes, absolutely. It has to be restricted to platforms where it's actually true. Would probably also be nice to be able to turn it off completely. Even if it's not a complete solution, it's progress.

@jainvishal

jainvishal commented Sep 13, 2020 •

Copy link
Copy Markdown
Author

Another change is needed in src/CMakefile.txt for RPATH for curl binary to find the right libcurl.so after installation otherwise LD_LIBRARY_PATH has to be used to run properly. I have locally fixed this by adding the RPATH within the binary. @bagder, @jzakrzewski, do you guys think it will impose any issues for the other users. See below dump from my local binary. If you guys like to see the code, I can push it.

readelf -d bin/curl | grep RUNPATH

 0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN/../lib]

So ldd shows

ldd bin/curl | grep curl
        libcurl.so.4 => /home/vishalj/release/test/bin/../lib/libcurl.so.4 (0x00007f2f78013000)

And two more questions:

  1. cmake has the standard way for naming the shared objects which was the first question @bagder had asked. So is this acceptable?
  2. Finally about restricting the change to only Linux. For now, I have restricted for the "NOT WIN32" platform. Since many people are using this software, I can look into limiting it exclusively for Linux for now and slowly add more platforms. Is that what you guys have in mind?

@bagder

bagder commented Sep 13, 2020 •

Copy link
Copy Markdown
Member

First, rpath would be a separate change and a separate discussion. In my personal opinion, curl itself should not set it unless asked for, but I would not object to an option that explicitly enables the use of it.

There are many ways for users to make sure the right lib is found at run-time, rpath is just one.

@jainvishal

jainvishal commented Sep 13, 2020 •

Copy link
Copy Markdown
Author

Hello @bagder, I compared output of make with cmake and found that make is also setting up RUNPATH and it is fully qualified. Please see below comparison. My cmake method can add the fully qualified RPATH or set the relative one using $ORIGIN. Latter ($ORIGIN) allows users to relocate compiled curl binary as long as libcurl remains in the relative path.

~/release > readelf -d make/bin/curl | grep RUNPATH
 0x000000000000001d (RUNPATH)            Library runpath: [/home/vishalj/release/make/lib]
 ~/release > readelf -d cmake/bin/curl | grep RUNPATH
 0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN/../lib]

This allows ldd to find libcurl as below:

~/release > ldd make/bin/curl | grep curl
        libcurl.so.4 => /home/vishalj/release/make/lib/libcurl.so.4 (0x00007fd09a59e000)
~/release > ldd cmake/bin/curl | grep curl
        libcurl.so.4 => /home/vishalj/release/cmake/bin/../lib/libcurl.so.4 (0x00007f3a8e8e9000)

@bagder

bagder commented Sep 13, 2020

Copy link
Copy Markdown
Member
  1. this has nothing to do with the SONAME, why are we discussing this in this PR?
  2. rpath != runpath. You mentioned rpath before and now runpath.

@jainvishal

jainvishal commented Sep 14, 2020 via email •

Copy link
Copy Markdown
Author

@jzakrzewski

Copy link
Copy Markdown
Contributor

If my old PR is any good, the "linux scheme" can be used for "AIX", "Linux", "GNU/kFreeBSD", "FreeBSD" (version 3.x and above), "Haiku", and "SunOS" (version 5 and 6).
I think restricting this to those platforms will be an improvement without hurting people that build on, for example, "NetBSD".

@bagder

bagder commented Oct 21, 2020

Copy link
Copy Markdown
Member

Now this flaw is mentioned specifically in the known bugs document: https://curl.haxx.se/docs/knownbugs.html#cmake_use_correct_SONAME_for_sh

Any progress?

@jainvishal

jainvishal commented Oct 25, 2020 •

Copy link
Copy Markdown
Author

I posted a commit to limit the soname changes to Linux for now. Since curl supports cmake 3.2 and above, I noticed incompatibility with the list handling I had implemented earlier. So I have made the changes for list handling to be compatible with older versions of cmake. During testing with cmake 3.2 I noticed another issue in tests/CMakeLists.txt:34 but that we can address separately.

Limited soname changes to linux for now to avoid breaking any other OS.
Also changed cmake list handling to make it compatible with the range of
older cmake versions that curl supports.
@bagder

bagder commented Dec 21, 2020

Copy link
Copy Markdown
Member

@jzakrzewski, do you think this is an improvement enough limited to just Linux like this? It introduces yet another platform difference, which is bad, but it could also be seen as a first step towards actually making this work properly in more places... and I'm not sure we can expect that we can fix "all platforms" in one go anyway.

@bagder bagder closed this Feb 12, 2021
@bagder
bagder deleted the branch curl:bagder/soname February 12, 2021 08:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

3 participants