libLTO on Mac OS X

Dear LLVMers,

I'm currently working on creating an alternate libLTO.so that will run some whole-program analysis and transforms of mine during the final linking of an executable. The idea is for it to link all of the bitcode files together, run the regular LTO passes, and then run my passes. For Linux, I should be able to get the Gold linker to load my libLTO.so instead of the standard one, thereby allowing my passes to be run seamlessly when compiling large programs with complicated build systems.

Can something similar be done on Mac OS X? Does the XCode linker dynamically load libLTO.dylib to perform link-time optimization?

-- John T.

Yes, it looks relative to itself to find it. If you link with /Developer/usr/bin/ld, it uses /Developer/usr/lib/libLTO.dylib.

-Chris

Alternatively, you could set the ‘DYLD_LIBRARY_PATH’ environment variable. The paths specified by it are searched *before* the both the path specified in the binary as well as the system fallback path. I often use it myself for newer versions of LLVM; the only caveat is that it won't work for e.g. ‘nm’, ‘ar’ and so on. Unlike ‘ld’ they load the library at runtime using a hardcoded path.

For example:
  DYLD_LIBRARY_PATH=/opt/llvm/lib make -j2

Hope that helps,