MacOS – How to remove specific local symbols using `strip` on macOS

developmentmacos

Using Linux, I can remove specific local symbols using strip -N SYM.

However, using strip on macOS, I can only see options -X and -x that respectively, remove all local symbols that begin with L and ALL local symbols.

When it comes to global symbols, I can use the -R filename option to remove the global symbols in filename.

Why can't I remove a specific subset of local symbols only?

Best Answer

You can't remove a subset of local symbols only because the strip program doesn't support it. The reasoning behind is out of scope for AskDifferent, but I would assume that it is simply because the need to do haven't come up for Apple Engineers or third party software developers often enough.

If you still want to do this, it is relatively simple to enhance strip to work like the Linux version, where you can strip a single, named, local symbol. Download the code for strip here:

https://github.com/opensource-apple/cctools/blob/master/misc/strip.c

Then take a look at the code for the -X option, and make your own option that strips the symbol you want instead of the ones beginning with L.

Others have in past created more capable versions of strip. For example the "striptease" program here:

https://github.com/mackyle/striptease

You can find inspiration there for possible enhancements.