openSUSE / libpathrs

C-friendly API to make path resolution safer on Linux.
GNU Lesser General Public License v3.0
70 stars 6 forks source link

cdylib: symbol versioning #38

Open cyphar opened 2 months ago

cyphar commented 2 months ago

In order to avoid compatibility issues in the future, we should make use of symbol versioning from the first release in order to avoid having to bump the SONAME when we eventually run into an incompatible change.

There are a few issues to note (I haven't tested these yet, I'm just collecting my notes from reading about this for a bit):

  1. Rust appears to specify its own version map (though it seems that this isn't the case for panic="abort"?) which means some magic is necessary to use our version map for our own symbols. It also appears to include our symbols in its default version map, so you also need to define the symbols with alternative names and then use -Wl,--defsym=foo=foo_impl to remap them. This will probably cause issues with cbindgen...
  2. There is no way to do asm(".symver ...")/__attribute__(symver()) in Rust at the moment, so if we ever end up having the same symbol name in two different versions (ie. there was an incompatible semantics change for a function and we want new programs to not use the function) it might not be possible to generate a version map with the right symbols. I suspect that --defsym=... can't be used for this purpose but we might want to look into that.

I suspect defining a version map from the outset even if we don't know how to deal with (2) is probably a good idea.

cyphar commented 2 months ago

Duplicate of #12, but I'll migrate that here.

Right now we don't have any kind of real versioning in the C API. It would be nice to have symbol versioning (this post has some interesting advice), and probably also some kind of pathrs_version() function which gives you the version of libpathrs you're dealing with.