Opened 14 years ago

Closed 14 years ago

#1927 closed Bugs (fixed)

MacOS (Darwin) should use the -headerpad_max_install_name option

Reported by: andrew@… Owned by: René Rivera
Milestone: Boost 1.36.0 Component: build
Version: Boost 1.35.0 Severity: Problem
Keywords: darwin macos library dylib Cc:

Description

Because of the way that dynamic linking works on MacOS, to be able to redistribute dynamic libraries it is necessary to include the path to the library in the executable.

Attached is a patch (from the MacPorts people) to make relocation much, much easier using MacOS's 'install_name_tool'.

Attachments (1)

patch-tools-build-v2-tools-darwin.jam (757 bytes ) - added by andrew@… 14 years ago.
add header padding to the dylib

Download all attachments as: .zip

Change History (8)

by andrew@…, 14 years ago

add header padding to the dylib

comment:1 by Vladimir Prus, 14 years ago

I cannot find any information about this option in google. Can you either point me at option's doc, and explanation why it's necessary, or describe it yourself?

Thanks.

in reply to:  1 comment:2 by andrew@…, 14 years ago

Sure - sorry, you couldn't google it because I was missing an 's' (the patch-file is fine, my bug summary missed the letter).

From the Apple 'ld' linker man page:

       -headerpad_max_install_names (32-bit only)
              Add  to  the  header  padding enough space to allow changing all
              dynamic shared library paths recorded in the output file  to  be
              changed to MAXPATHLEN in length.

(The option is not needed for 64-bit objects, and is silently ignored.)

Basically, when creating shared objects, the apple linker places a semi-absolute pathname of the library and all dependent dynamic objects into the object. Think of it as the apple 'solution' to Linux's ld.so conf file. To see the paths of embedded objects, use "otool -L". To change the embedded path name, use "install_name_tool".

It is the changing-part that needs the header padding. Suppose I build boost and install it into /opt/local. Then all the libraries reference themselves (and any other required libs) as '/opt/local/lib/libboost-blah.dyld'. If I want to redistribute my software binaries plus libraries, I need to rename the internal name of the libraries.

Without the headerpad option to the linker, the new path must be equal or shorter in length than the old path. Blech! With the headerpad option, I can use any valid filesystem path.

Thus, building redistributable binaries in boost is only practical on darwin with this option.

Yes, it is a kludge... and that's why apple fixed it for the 64-bit sub-file-format.

Cheers, -Andrew.

comment:3 by Vladimir Prus, 14 years ago

Do you mean that on OSX, it is the standard practice to embed full path to dependency libraries into shipped applications? Is each application supposed to be installed into a fixed location?

in reply to:  3 comment:4 by andrew@…, 14 years ago

The short, but inaccurate answer, is "yes".

Dynamic library paths and linking on Apple is not as simple topic. Libraries (inside frameworks) are usually in fixed locations. There is (under 10.4) a "magic" file name so libraries can be located with respect to the executable file bundle.

Apple has extensive documentation on how dyld files are searched for.

A brief (and informative) summary is here.

Leopard (10.5) introduced RPATH semantics see here.

But basically... using the "-headerpad_max_install_names" linker option allows the boost user to compile boost once and then package up the libraries as "application-specific framework bundles" in a final application. Without the headerpad option, boost must be custom-compiled to its final installation directory for every project that uses it.

comment:5 by René Rivera, 14 years ago

Component: Building Boostbuild
Milestone: Boost 1.35.1Boost 1.36.0
Owner: set to René Rivera
Status: newassigned

in reply to:  5 comment:6 by andrew@…, 14 years ago

Replying to grafik: Sorry - forgot to mention this earlier - but the attached patch has been part of the MacPorts build system for a while, so a fair number of people have been using/compiling with it already. I just didn't want you to think that it was totally untried...

comment:7 by René Rivera, 14 years ago

Resolution: fixed
Status: assignedclosed

Fixed in rev [46793], along with other cleanups.

Note: See TracTickets for help on using tickets.