Skip to content

lld/mac add option to change install names at link time #53549

@rsesek

Description

@rsesek

This is a new feature request of Mach-O lld, and this feature does not exist in ld64. It would be helpful to have an option to change the install name of a dependent library directly on the linker, without needing to run a post-link install_name_tool. The use case is if you had a bundle structure like this:

Foo.app/Contents/
    MacOS/
        Foo
    Frameworks/
        libcore.dylib
    Helpers/
        Helper.app/
            Contents/
                MacOS/
                    Helper

Both the Helper and Foo executables need to link to libcore.dylib, but they are at different relative path depths to libcore.dylib. If you do not want to ship a binary that uses @rpath-based loading, one (or both) of the executables will need to change their recorded install names. This has to be done after linking, e.g.:

install_name_tool -change libcore.dylib @executable_path/../Frameworks/libcore.dylib Foo.app/Contents/MacOS/Foo

And

install_name_tool -change libcore.dlyb @executable_path/../../../../../Frameworks/libcore.dylib Foo.app/Contents/Helpers/Helper.app/Contents/MacOS/Helper

It would be much more convenient to be able to tell the linker that the install name of the dependent dylib should be recorded as a different value when linking. Something like:

clang -o Foo -lcore -Lpath/to/libcore -Wl,-change_install_name,libcore.dylib,@executable_path/../Frameworks/libcore.dylib Foo.app/Contents/MacOS/Foo Foo.c

Note that this is not the same as the documented-dylib_file option that exists in ld64 and is currently unimplemented in lld. The -dylib_file option changes where the linker looks for the dependent library, but it does not change the install name that gets recorded in the output image.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions