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

1

9

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?

Receptor answered 13/2, 2017 at 18:15 Comment(0)
J
11

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.

Janeyjangle answered 14/2, 2017 at 2:29 Comment(2)
I think I see what you mean. Does it make sense to say: "This is the path that will be copied into the binaries that link to it"?Lydon
Yes, that is accurate.Janeyjangle

© 2022 - 2024 — McMap. All rights reserved.