0

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?

1

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.

  • I know it maybe is off-topic, but why haven't Apple simply ported the Linux strip? And is the strip from the above Github (opensource) repository the same strip that's installed on my Macbook or some opensource version? – Shuzheng Feb 25 at 18:54
  • Well, there are many reasons. Firstly macOS uses the Mach-O binary file format and Linux uses ELF - so there's really no point in porting it. Secondly, the macOS program probably predates the Linux version by multiple years. Linux used the a.out format the first years, they switched to ELF in 1995. The Mach-O format is from approx. 1985, so Apple/NeXT employees probably wrote their strip implementation long before the Linux one existed. And yes, the strip I linked to is the strip that is installed on your MacBook (assuming you're on the same version). It is also an open source version... – jksoegaard Feb 25 at 20:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .