Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the significance of a macOS Mach-O dylib LC_ID_DYLIB name, or install_name?

I'm working on developing a macOS dylib framework, developed outside of Xcode, and I'm trying to understand the significance of the install_name option.

For example, I can set the LC_ID_DYLIB section name to something more-like what you would find in a application bundle's framework using the install_name argument like so.

clang++ ... -install_name @executable_path/../Frameworks/somelib.framework/Versions/somelib ...

Then with otool -l I can see that my name has been set in the binary, different from the default (which matches the -o option by default).

otool -l somelib
...
          cmd LC_ID_DYLIB
      cmdsize 96
         name @executable_path/../Frameworks/somelib.framework/Versions/A/somelib (offset 24)
   time stamp 1 Wed Dec 31 19:00:01 1969
      current version 1.0.0
compatibility version 1.0.0
....

So I understand how to set it, but what I don't understand is what exactly the value is used for to know what it should be, nor can I find any documentation on it.

I can see why the LC_LOAD_DYLIB sections would need information on where to find a binary (as these sections reference other binaries), but why does a dylib need information on where to find itself? The binary that links against it should be the one that finds it?

So what exactly does a macOS dylib LC_ID_DYLIB install_name do?

like image 380
Alexander O'Mara Avatar asked Feb 13 '17 18:02

Alexander O'Mara


1 Answers

Any clients that link against the dylib record the path specified in the LC_ID_DYLIB load command as the path at which to find the dylib at runtime. This is useful as the path where the dylib lives at build time is often not where it will be found at runtime.

like image 128
bdash Avatar answered Oct 23 '22 09:10

bdash