Skip to content

Keg relocation should also relocate RPATHs on macOS #11329

@carlocab

Description

@carlocab

Provide a detailed description of the proposed feature

On macOS, the relocation of kegs does not touch LC_RPATH entries in MachO files. This behaviour differs from that on Linux, where RPATHs are relocated, and I believe this partly explains why more formulae are relocatable on Linux than on macOS.

I propose that brew also apply the existing relocation logic to LC_RPATH entries. That is, it should substitute path prefixes in each LC_RPATH entry with the appropriate placeholders (e.g. @@HOMEBREW_PREFIX@@, @@HOMEBREW_CELLAR@@, etc) upon bottling, and substitute those placeholders with the correct prefixes upon pouring.

This complements #10846. Personally, I think this should be implemented first before we do any binary patching.

There is some existing (but, AFAICT, unused) logic in brew that clears MachO files of "unused" RPATHs:

# If none of the install names reference RPATH(s), then we can safely
# remove all RPATHs from the file.
if ENV["HOMEBREW_RELOCATE_METAVARS"] &&
file.dynamically_linked_libraries.none? { |lib| lib.start_with?("@rpath") }
# NOTE: This could probably be made more efficient by reverse-sorting
# the RPATHs by offset and calling MachOFile#delete_command
# with repopulate: false.
file.rpaths.each { |r| file.delete_rpath(r) }
end

but my (admittedly limited) testing suggests that the test it uses for deciding whether to clear redundant RPATHs is incorrect, and actually breaks formulae.

What is the motivation for the feature?

More relocatable bottles.

How will the feature be relevant to at least 90% of Homebrew users?

Probably won't be.

What alternatives to the feature have been considered?

Doing nothing, or just relying fully on binary patching instead.

Metadata

Metadata

Assignees

Labels

outdatedPR was locked due to age

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions