question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Android NDK, no Link-Time Optimization?

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:20 (20 by maintainers)

github_iconTop GitHub Comments

1reaction
cpsauercommented, Sep 4, 2022

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.

1reaction
keithcommented, Mar 14, 2022

Here’s some thin_lto setup https://github.com/bazelbuild/bazel/pull/15039 for Android, still opt-in

Read more comments on GitHub >

github_iconTop Results From Across the Web

Link-time optimization with android-ndk r8e - Stack Overflow
I wanted to compile sources (SDL and similar things) using the new android ndk r8e. The changelog states "Enabled -flto in GCC 4.7,...
Read more >
Link time optimization - Google Groups
Has anyone played around with gcc or llvm's link time optimization ... Currently the latest GCC included in the Android NDK is 4.8....
Read more >
Linker error when enabling Link Time Optimization in NDK-C++
The error is caused by https://github.com/android-ndk/ndk/issues/721. Clang's LTO plugin just doesn't accept -Os or -Oz . This is a bug.
Read more >
Build System Maintainers Guide
The NDK uses the LLVM family of tools for building C/C++ code. ... Android no longer supports ARMv5, but if your build system...
Read more >
Sample: native-activity - NDK - Android Developers
An app with only native code must not specify an Android API level lower ... Suppress link-time optimization that removes unreferenced code
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found