Improve binary stripping for Apple platforms#14951
Improve binary stripping for Apple platforms#14951keith wants to merge 1 commit intobazelbuild:masterfrom
Conversation
|
cc @trybka |
This change implements the suggestions from https://github.com/trybka/scraps/blob/f78a7fdb3a05a0d46ac4e1ba69e223157c966028/Apple_Stripping.md#proposal Previously stripping for Apple platforms had a few different cases: 1. Passing `--strip=always` / `--strip=sometimes` + fastbuild passes `-Wl,-S` to link invocations 2. Using the `.stripped` outputs of some rules like cc_binary takes `--stripopt` into account 3. Passing `--objc_enable_binary_stripping` + opt enabled `-dead_strip`, and called `strip` on linked binaries (passing `-x` for dylibs and similar) With this change there is a different setup: 1. The behavior of `--strip` is unchanged 2. The behavior of `--stripopt` is unchanged 3. `-dead_strip` is enabled by default for all opt builds 4. `strip -rSTx` is invoked for any builds that produced dSYMs 5. `--objc_enable_binary_stripping` is now a no-op This simplifies what flags people have to be aware of to get the right stripping behavior. This also unifies the stripping behavior for cc_binary, all users of cc_common.link, and other Apple binary rules when building for macOS.
c95af6f to
7d0e116
Compare
|
There are 2 potentially underserved cases here:
|
|
cc: @googlewalt @jyknight |
|
Bump. |
|
@comius I assume Walt is the right person to review this? |
Yes. |
|
Anyone looking into this? Would love to see this land as it removes a lot of dead weight from apple binaries, especially for folks who care about staying under that appstore OTA download limit 😬 |
|
Sorry for not responding sooner. I did look into this internally. This commit changes several distinct aspects of binary stripping. It would be better to split each distinct aspect into a separate commit. That way:
Suggestion for how to break this up, in steps:
|
|
@googlewalt (and others), any chance there's a way we could keep dead_strip on for dylibs, too, in opt builds? [Will explain why below--please say if you think I've misunderstood something.] Seems to me like the avoid_deps bug you're describing is rooted in dylib not always linking dependencies. By default, all symbols are exported from a dylib, right? So the not-always-linking optimization seems fundamentally buggy in this instance, since it changes the interface of the resulting library. Regardless, in the absence of specifying the interface of a dylib, nothing should get dead stripped by the linker because all symbols are exported, right? And conversely, things are only stripped when you specify the interface with a symbols list or linker script or whatever, in which case all is well, since you get what you explicitly ask for. Maybe I'm missing something, but it seems offhand like dead_strip would be good to have on by default in opt (rather than exacerbating the root problem, above) because I'd expect it to be a no-op if you don't specify which symbols to export and behave very usefully if you do specify which symbols to export. Super appreciate all you guys do! Some related crossrefs in my memory, in case ever useful: |
|
cpsauer@ I think you're right; it's been a while but the failures I had were from dead_strip of binaries, not dylibs. So we may be able to keep dead_strip on for dylibs, even if by default it's not likely to be able to strip anything. |
|
Yay! Thanks for reading and being open to it @googlewalt |
|
Closing this as obsolete. If we still want it, it should be splitted as indicated above |
This change implements the suggestions from https://github.com/trybka/scraps/blob/f78a7fdb3a05a0d46ac4e1ba69e223157c966028/Apple_Stripping.md#proposal
Previously stripping for Apple platforms had a few different cases:
--strip=always/--strip=sometimes+ fastbuild passes-Wl,-Sto link invocations.strippedoutputs of some rules like cc_binary takes--stripoptinto account--objc_enable_binary_stripping+ opt enabled-dead_strip,and called
stripon linked binaries (passing-xfor dylibs andsimilar)
With this change there is a different setup:
--stripis unchanged--stripoptis unchanged-dead_stripis enabled by default for all opt buildsstrip -rSTxis invoked for any builds that produced dSYMs--objc_enable_binary_strippingis now a no-opThis simplifies what flags people have to be aware of to get the right
stripping behavior. This also unifies the stripping behavior for
cc_binary, all users of cc_common.link, and other Apple binary rules
when building for macOS.