Skip to content

dylib install name issues (OSX) #57

Closed

Description

@kaneod

On OSX openblas has the same problem GOTOblas used to have regarding the generation of .dylib files: the install name is not set correctly and the subsequent dylib is not valid:

$ otool -L libopenblas_core2p-r0.1alpha2.3.dylib
libopenblas_core2p-r0.1alpha2.3.dylib:
../libopenblas_core2p-r0.1alpha2.3.dylib (compatibility version 0.0.0, current version 0.0.0)
/usr/local/gcc/lib/libgfortran.3.dylib (compatibility version 4.0.0, current version 4.0.0)
/usr/local/gcc/lib/libgomp.1.dylib (compatibility version 2.0.0, current version 2.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.11)
/usr/local/gcc/lib/libquadmath.0.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/local/gcc/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)

The "../libopenblas_core2p-r0.1alpha2.3.dylib (compatibility version 0.0.0, current version 0.0.0)" line is the problem: dylibs on OSX must know where they are absolutely (yes, it is silly). The dylib is generated by the Makefile in the exports directory, line 88:

$(PREFIX)gcc $(CFLAGS) -all_load -dynamiclib -o ../$(LIBDYNNAME) $< -Wl,-exported_symbols_list,osx.def  $(FEXTRALIB)

Now, two points:

  1. Why is the command $(PREFIX)gcc when everything else has the generic and portable $(CC) which, for example, takes into account the CC variable set in Makefile.rule? $PREFIX is supposed to be the installation directory. I think this is an error and no one has picked it up simply because no one bothers to set $PREFIX in Makefile.rule on OSX.

  2. The option -install_name has to be used here, but I'm not sure how to specify this in a portable way if this is even possible. I modify line 88 to look like the following as a workaround:

    $(CC) $(CFLAGS) -all_load -install_name $(PREFIX)/$(LIBDYNNAME) -dynamiclib -o $(PREFIX)/$(LIBDYNNAME) $&lt; -Wl,-exported_symbols_list,osx.def $(FEXTRALIB)

where $PREFIX is set in Makefile.rule, but this will fail if $PREFIX is blank (ie, commented out). Further, if the dylib is subsequently moved to anywhere except $PREFIX, it cannot be loaded by any apps that link against it.

To be honest I'm not an expert on the Right Way of constructing dylibs for portability so I don't know a good way to fix this generically. Any good ideas?

Kane

Activity

  1. xianyi commented on Sep 11, 2011

    @xianyi
    Collaborator

    2011 9 11 05:23"Kane O'Donnell" <
    reply@reply.github.com

    д

    On OSX openblas has the same problem GOTOblas used to have regarding the
    generation of .dylib files: the install name is not set correctly and the
    subsequent dylib is not valid:

    $ otool -L libopenblas_core2p-r0.1alpha2.3.dylib
    libopenblas_core2p-r0.1alpha2.3.dylib:
    ../libopenblas_core2p-r0.1alpha2.3.dylib (compatibility version
    0.0.0, current version 0.0.0)
    /usr/local/gcc/lib/libgfortran.3.dylib (compatibility version
    4.0.0, current version 4.0.0)
    /usr/local/gcc/lib/libgomp.1.dylib (compatibility version 2.0.0,
    current version 2.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current
    version 125.2.11)
    /usr/local/gcc/lib/libquadmath.0.dylib (compatibility version
    1.0.0, current version 1.0.0)
    /usr/local/gcc/lib/libgcc_s.1.dylib (compatibility version 1.0.0,
    current version 1.0.0)

    The "../libopenblas_core2p-r0.1alpha2.3.dylib (compatibility version
    0.0.0, current version 0.0.0)" line is the problem: dylibs on OSX must know
    where they are absolutely (yes, it is silly). The dylib is generated by the
    Makefile in the exports directory, line 88:

       $(PREFIX)gcc $(CFLAGS) -all_load -dynamiclib -o ../$(LIBDYNNAME) $<
    

    -Wl,-exported_symbols_list,osx.def $(FEXTRALIB)

    Now, two points:

    1. Why is the command $(PREFIX)gcc when everything else has the generic
      and portable $(CC) which, for example, takes into account the CC variable
      set in Makefile.rule? $PREFIX is supposed to be the installation directory.
      I think this is an error and no one has picked it up simply because no one
      bothers to set $PREFIX in Makefile.rule on OSX.

    Yes, it looks like a bug. I'm on holiday. I will check it in next week.

    1. The option -install_name has to be used here, but I'm not sure how to
      specify this in a portable way if this is even possible. I modify line 88 to
      look like the following as a workaround:

      $(CC) $(CFLAGS) -all_load -install_name $(PREFIX)/$(LIBDYNNAME)
      -dynamiclib -o $(PREFIX)/$(LIBDYNNAME) $< -Wl,-exported_symbols_list,osx.def
      $(FEXTRALIB)

    where $PREFIX is set in Makefile.rule, but this will fail if $PREFIX is
    blank (ie, commented out). Further, if the dylib is subsequently moved to
    anywhere except $PREFIX, it cannot be loaded by any apps that link against
    it.

    To be honest I'm not an expert on the Right Way of constructing dylibs for
    portability so I don't know a good way to fix this generically. Any good
    ideas?

    Thank you

    Kane

    Reply to this email directly or view it on GitHub:
    #57

  2. kaneod commented on Sep 11, 2011

    @kaneod
    Author

    Ok. Maybe one option is to set -headerpad_max_install_names on the initial build of the dylib and then if the user actually runs "make install", install_name_tool can be used to set the dylib path for the specified prefix, the syntax would be:

    install_name_tool -change ../libopenblas_core2p-r0.1alpha2.3.dylib $(PREFIX)/libopenblas_core2p-r0.1alpha2.3.dylib libopenblas_core2p-r0.1alpha2.3.dylib

    assuming the initial name is set to ../libopenblas_core2p-r0.1alpha2.3.dylib, which it currently is. Setting -headerpad_max_install_names also allows a user who doesn't use make install to change the name themselves later - perhaps if the target is Darwin a message needs to be printed out along with the build information at the end of the compile saying the dylib won't work as-is.

  3. ghost assigned on Sep 12, 2011
  4. xianyi commented on Sep 12, 2011

    @xianyi
    Collaborator

    Hi Kane,

    Thank you for the patch and suggestions.

    I'm not a Mac or OSX user. Thus, I can't address this issue. :(
    I will apply your patch in future release.

    Thanks
    Xianyi

  5. kaneod commented on Sep 12, 2011

    @kaneod
    Author

    Hi Xianyi,

    My pleasure. I believe there are some latent problems with the construction of the dylib in any case - it may be worth putting a warning in the README of the next release saying the dylib is unusable on OSX at present as there are symbols missing (at least dlamch and ilaenv). The static library works perfectly fine. Let me know if you need me to check whether the patch works.

    Kane

  6. added a commit that references this issue on Sep 16, 2011
  7. xianyi commented on Sep 16, 2011

    @xianyi
    Collaborator

    Hi Kane,

    I just added your patch into this branch ( https://github.com/xianyi/OpenBLAS/tree/hotfix-0.1alpha2.4 ).
    Please help me test it on Mac.

    Thank you

    Xianyi

  8. kaneod commented on Sep 16, 2011

    @kaneod
    Author

    Hi Xianyi,

    No, the patch doesn't work. You need absolute paths in the install name, so pwd/../$(DYLIBNAME) is not valid. I have attached a patch that has the correct behaviour. I've also updated the warning in Makefile to give the user more options and fixed the English slightly.

    Kane

    On 16/09/2011, at 12:08 PM, Xianyi Zhang wrote:

    Hi Kane,

    I just added your patch into this branch ( https://github.com/xianyi/OpenBLAS/tree/hotfix-0.1alpha2.4 ).
    Please help me test it on Mac.

    Thank you

    Xianyi

    Reply to this email directly or view it on GitHub:
    #57 (comment)

  9. added a commit that references this issue on Sep 17, 2011
  10. xianyi commented on Sep 17, 2011

    @xianyi
    Collaborator

    Hi Kane,

    I just applied your patch. However, I used this in generating shared
    library.

    $(CC) $(CFLAGS) -all_load -headerpad_max_install_names -install_name$(CURDIR)/../$(LIBDYNNAME) -dynamiclib -o ../$(LIBDYNNAME) $&lt; -Wl,-exported_symbols_list,osx.def $(FEXTRALIB)

    CURDIR is a standard make variable, which contains the absolute path of current working directory. I think you could use this shared library in OpenBLAS top directory.

    Thanks

    Xianyi

    Kane O'Donnell write:Sent: 2011/9/17 1:06

    Hi Xianyi,

    No, the patch doesn't work. You need absolute paths in the install name, so pwd/../$(DYLIBNAME) is not valid. I have attached a patch that has the correct behaviour. I've also updated the warning in Makefile to give the user more options and fixed the English slightly.

    Kane

  11. kaneod commented on Sep 17, 2011

    @kaneod
    Author

    Hi Xianyi,

    Apart from the fact that you need a space between the -install_name switch and the $(CURDIR) variable, the line you substituted works fine.

    One other thing: there is an inconsistency between the install behaviour of OpenBLAS and other GNU-make style software. Normally when building a library on Linux/Unix/OSX, if user supplies PREFIX, the libraries go to $PREFIX/lib and the headers to $PREFIX/include. OpenBLAS is instead sending everything to $PREFIX. Since the configuration scripts of the codes using OpenBLAS can be quite subtle it would be best if the OpenBLAS install is changed to put things in their correct location relative to $PREFIX.

    Kane

    On 17/09/2011, at 10:45 AM, Xianyi Zhang wrote:

    Hi Kane,

    I just applied your patch. However, I used this in generating shared
    library.

    $(CC) $(CFLAGS) -all_load -headerpad_max_install_names -install_name$(CURDIR)/../$(LIBDYNNAME) -dynamiclib -o ../$(LIBDYNNAME) $&lt; -Wl,-exported_symbols_list,osx.def $(FEXTRALIB)

    CURDIR is a standard make variable, which contains the absolute path of current working directory. I think you could use this shared library in OpenBLAS top directory.

    Thanks

    Xianyi

    Kane O'Donnell write:Sent: 2011/9/17 1:06

    Hi Xianyi,

    No, the patch doesn't work. You need absolute paths in the install name, so pwd/../$(DYLIBNAME) is not valid. I have attached a patch that has the correct behaviour. I've also updated the warning in Makefile to give the user more options and fixed the English slightly.

    Kane

    Reply to this email directly or view it on GitHub:
    #57 (comment)

  12. added a commit that references this issue on May 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions