Android NDK, no Link-Time Optimization?
See original GitHub issueHi 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
Issue Analytics
- State:
- Created 2 years ago
- Comments:20 (20 by maintainers)
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.
Here’s some thin_lto setup https://github.com/bazelbuild/bazel/pull/15039 for Android, still opt-in