-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Android NDK, no Link-Time Optimization? #13287
Comments
Hey, so to clarify: This really is not a support question--I know how to enable LTO/stripping and had already done so. Instead it's either a defaults bug or a doc request depending on Bazel's intent for opt meant to be shorthand for (fully) optimized binaries? -> Missing LTO flags when building with the Android NDK (among several other important missing flags, see #10837) opt indeed meant to be per-translation-unit-optimization only? -> Docs should probably say that, since other platforms have interpreted it the other way. |
ThinLTO seems like a reasonable default, not much build time overhead on top of |
Good call on ThinLTO :) |
@cpsauer Thanks. I think it was intended to be opt-in using build --copt -flto=thin
build --linkopt -flto=thin |
The android crosstool doesn't actually have the thin_lto feature, and therefore doesn't support it. I think this is something we should add, similar to how it works in the unix toolchain (assuming the NDK's tools support the same flags) |
We were looking at this yesterday and found that if you're trying to use As far as opt-in vs opt-out, I imagine folks would want us to mirror the current behavior where it is supported, but I'm not sure, either way I think adding it to make it as easy as flipping a feature for all platforms would be great. |
Keith with a blazingly fast, good crossref, as usual :) There's an interaction I didn't know about. @keith, could I ask what breakage you saw? Same fatal linker error as in the issue you linked android/ndk#721? Asking bc we'd been running |
IMO, we should really turn on thin LTO by default for Lots of users will never get deeper than requesting an optimized build. And I think they'd be surprised that |
It's probably more likely to get through review and testing to just stick with implementing |
@cpsauer you are also passing https://developer.android.com/ndk/downloads/revision_history?authuser=1
|
Yes this one.
What optimization level are you using? we're explicitly passing |
Here's some thin_lto setup #15039 for Android, still opt-in |
Woo! Thanks for doing, Keith. Keith, re
|
Interesting find! I would assume that bazel wouldn't treat them special at all, so if you didn't explicitly pass |
@cpsauer at the time I wrote this, we were still on Bazel 4.2.2 (I don't think 5.0 had officially released yet). 4.2.2 only supported up to r19c. |
@keith: Pretty wild, right! I feel like I read something about this long ago, but can't find doc on it for the life of me. If you do ever run into it, I'd love it if you'd say something! @jgavris: Makes sense. We've been using Bazelisk to stay at or near HEAD with rolling releases. It's been pretty sweet. Huge thanks to Keith for (among many things) helping the rolling story get working with mobile. |
@gregestren, sorry to add one more thing to your plate, but could we remove the support tag? This really isn't. |
Update: The thin_lto feature is supported by the Google NDK toolchains, which Alex released as a replacement for the old, built-in ones that had ben falling behind! https://github.com/bazelbuild/rules_android_ndk I'm leaving this issue open because I really do want to propose that optimized builds ought to have (thin) link time optimization on by default. @keith, I think the new toolchain should also solve the -O# linking issue you mentioned above, by virtue of being NDK >=r22! Do you know offhand if thin_lto is already supported by the Apple toolchains? I didn't see it on a quick pass, but I could have missed it. |
don't think so, although just passing |
Hi awesome Bazel folks,
I was debugging an NDK build and looking at the link commands being run. I happened to notice that dbg and opt builds are getting the exact same set of linker flags--no
-flto
(or-O#
) flags in either case. That made me wonder if Bazel is accidentally omitting link-time optimization (LTO) in optimized builds.[I'm assume Bazel (a) intends to have optimized (opt) builds run with LTO, and (b) that those flags would be show up in the link command dumped in
--verbose_failures
. Apologies if I've missed something somewhere and this is a false alarm, but then maybe we should clarify the docs and have consistency across platforms.]Easiest way to repro should be the Bazel NDK example. (I'm using NDK21, macOS 11, Bazel 4, if that might matter.) I was looking at it by building with an invalid linker flag and
--verbose_failures
.Thanks for taking a peek,
Chris
The text was updated successfully, but these errors were encountered: