patchelf icon indicating copy to clipboard operation
patchelf copied to clipboard

Support idempotent addition of RPATHs and NEEDEDs (i.e. remove duplicates)

Open de11n opened this issue 2 years ago • 0 comments

patchelf --add-needed libX Y && patchelf --add-needed libX Y will add libX twice. The same goes for patchelf --add-rpath.

It would be very handy if there were a way to enable patchelf to only make additions when the requested NEEDED/RPATH is not already present.

Ordering matters for both of these, so this feature would likely only come into effect for duplicates that would otherwise have a lower precedence than an existing entry.

This feature could be added numerous ways:

patchelf --add-needed libX --add-rpath /path/y --uniq-needed --uniq-rpaths Z

This would be strictly more general than merely making --add-needed/--add-rpath idempotent, but it would achieve the goal.

(Indeed, --shrink-rpath probably has this effect, but it cannot be used when the RPATH contains directories that don't exist yet.)

A more granular option could be:

patchelf --add-needed-idempotent libX Z

Obviously this functionality can be achieved with a few calls to patchelf --print-needed/patchelf --print-rpath along with some tr and awk. But that's also true of many features (e.g. --add-rpath could be implemented in terms of --print-rpath and --set-rpath) and I think it's probably the semantics people mean when they say --add-needed etc. It's also just much more convenient for patchelf to do it, while also more efficient.

de11n avatar May 15 '23 19:05 de11n