Discussion:
[petsc-users] soname seems to be absent in OS-X
Denis Davydov
2015-10-27 16:28:30 UTC
Permalink
Dear developers,

It seems that the compiled PETSc library does not have a soname (-Wl,-install_name=xyz.dylib in OS-X).
I compile PETSc/SLEPc using Homebrew both on OS-X and Linux and judging from ldd/otool there is indeed a difference:

Linux (soname is there):
$ ldd .linuxbrew_openblas/opt/slepc/lib/libslepc.so | grep "petsc"
libpetsc.so.3.6 => /home/woody/iwtm/iwtm108/.linuxbrew_openblas/Cellar/petsc/3.6.2/real/lib/libpetsc.so.3.6 (0x00007fac7822f000)
OS-X (no soname):

$ otool -L /usr/local/opt/slepc/lib/libslepc.dylib | grep "petsc"
/usr/local/opt/petsc/real/lib/libpetsc.3.6.2.dylib (compatibility version 3.6.0, current version 3.6.2)

I do not see `-Wl,-soname=xyz` in linking flags and nothing like `-Wl,-install_name=xyz` is there on OS-X either.
Any mac users can comment on this?

p.s. as Macports web is down i can’t check what folks are doing there.

Kind regards,
Denis
Mohammad Mirzadeh
2015-10-27 19:00:09 UTC
Permalink
Denis,

I use Homebrew to manage petsc and all related dependencies on OSX which
uses .dylib for shared libs instead of .so. However, I have not had any
issues linking against them just the usual way by passing -L/path/to/lib
-lwhatever (you need to pass -Wl,-rpath,/path/to/lib as well if lib is not
in run-time search path).

Hope this helps.
Post by Denis Davydov
Dear developers,
It seems that the compiled PETSc library does not have a soname
(-Wl,-install_name=xyz.dylib in OS-X).
I compile PETSc/SLEPc using Homebrew both on OS-X and Linux and judging
$ ldd .linuxbrew_openblas/opt/slepc/lib/libslepc.so | grep "petsc"
libpetsc.so.3.6 => /home/woody/iwtm/iwtm108/.linuxbrew_openblas/Cellar/petsc/3.6.2/real/lib/libpetsc.so.3.6 (0x00007fac7822f000)
$ otool -L /usr/local/opt/slepc/lib/libslepc.dylib | grep "petsc"
/usr/local/opt/petsc/real/lib/libpetsc.3.6.2.dylib (compatibility version 3.6.0, current version 3.6.2)
I do not see `-Wl,-soname=xyz` in linking flags and nothing like
`-Wl,-install_name=xyz` is there on OS-X either.
Any mac users can comment on this?
p.s. as Macports web is down i can’t check what folks are doing there.
Kind regards,
Denis
Barry Smith
2015-10-29 21:01:59 UTC
Permalink
Denis,

We don't understand what purpose a soname serves on Apple or how to add it. If you need it let us know how to install PETSc so that it is set and we will do it.

Barry
Post by Denis Davydov
Dear developers,
It seems that the compiled PETSc library does not have a soname (-Wl,-install_name=xyz.dylib in OS-X).
$ ldd .linuxbrew_openblas/opt/slepc/lib/libslepc.so | grep "petsc"
libpetsc.so.3.6 => /home/woody/iwtm/iwtm108/.linuxbrew_openblas/Cellar/petsc/3.6.2/real/lib/libpetsc.so.3.6 (0x00007fac7822f000)
$ otool -L /usr/local/opt/slepc/lib/libslepc.dylib | grep "petsc"
/usr/local/opt/petsc/real/lib/libpetsc.3.6.2.dylib (compatibility version 3.6.0, current version 3.6.2)
I do not see `-Wl,-soname=xyz` in linking flags and nothing like `-Wl,-install_name=xyz` is there on OS-X either.
Any mac users can comment on this?
p.s. as Macports web is down i can’t check what folks are doing there.
Kind regards,
Denis
Denis Davydov
2015-11-01 09:49:12 UTC
Permalink
Hi Barry,

I think you use it already. After configure /lib/petsc/conf/petscvariables :

SL_LINKER_FUNCTION = -dynamiclib -install_name $(call SONAME_FUNCTION,$(1),$(2)) -compatibility_version $(2) -current_version $(3) -single_module -multiply_defined suppress -undefined dynamic_lookup
SONAME_FUNCTION = $(1).$(2).dylib

on the linking stage in the homebrew logs I see that the exact linking line contains -install_name :

-Wl,-multiply_defined,suppress -Wl,-multiply_defined -Wl,suppress -Wl,-commons,use_dylibs -Wl,-search_paths_first -fPIC -Wall -Wwrite-strings -Wno-strict-aliasing -Wno-unknown-pragmas -O -dynamiclib -install_name /private/tmp/petsc20151027-97392-7khduu/petsc-3.6.2/real/lib/libpetsc.3.6.dylib -compatibility_version 3.6 -current_version 3.6.2 -single_module -multiply_defined suppress -undefined dynamic_lookup


If I do configure manually (bare-bones PETSc) and compile it, the install_name seems to be correct (note that it’s libpetsc.3.6.dylib instead of libpetsc.3.6.2.dylib) :
—————
$ otool -D arch-darwin-c-debug/lib/libpetsc.3.6.2.dylib
arch-darwin-c-debug/lib/libpetsc.3.6.2.dylib:
/Users/davydden/Downloads/petsc-3.6.2/arch-darwin-c-debug/lib/libpetsc.3.6.dylib

executable linked against end up using correct ABI version:
$ otool -L test | grep petsc
/Users/davydden/Downloads/petsc-3.6.2/arch-darwin-c-debug/lib/libpetsc.3.6.dylib (compatibility version 3.6.0, current version 3.6.2)
—————


however after installation to —prefix=/Users/davydden/Downloads/petsc-3.6.2/real the install name ends up being wrong:
—————
$ otool -D real/lib/libpetsc.3.6.2.dylib
real/lib/libpetsc.3.6.2.dylib:
/Users/davydden/Downloads/petsc-3.6.2/real/lib/libpetsc.3.6.2.dylib

executable linked against end up using libpetsc.3.6.2.dylib instead of ABI version:
otool -L test | grep petsc
/Users/davydden/Downloads/petsc-3.6.2/real/lib/libpetsc.3.6.2.dylib (compatibility version 3.6.0, current version 3.6.2)
—————

My guess would be there is something wrong happening in `make install`.
Perhaps when using “install_name_tool” with "-id” flag to change a library’s install name.
As a workaround i will fix install name manually, but you may consider investigating this issue further.


p.s. an excerpt from http://cocoadev.com/ApplicationLinking :

Unlike many OSes, OS X does not have a search path for the dynamic linker**. This means that you can't simply put a dynamic library in some "standard" location and have dyld find it, because there is no standard location. Instead, OS X embeds an "install name" inside each dynamic library. This install name is the path to where the library can be found when dyld needs to load it. When you build an application that links against a dynamic library, this install name is copied into the application binary. When the application runs, the copied install name is then used to locate the library or framework.

** Technically, dyld does have a search path, defined in the DYLD_FRAMEWORK_PATH and DYLD_LIBRARY_PATH variables. However, these are empty on OS X by default, so they rarely matter.

Kind regards,
Denis
Post by Mohammad Mirzadeh
Denis,
We don't understand what purpose a soname serves on Apple or how to add it. If you need it let us know how to install PETSc so that it is set and we will do it.
Barry
Barry Smith
2015-11-03 03:55:20 UTC
Permalink
Denis,

Thanks for your careful explanation; I had no clue. Please find attached a patch for 3.6 that seems to give the behavior you desire.

It is also in the maint, master and next branches in the repository

Barry

Loading...