Anti-AIClone

Log date · Tue

How should you rebaseline native builds for Android NDK r30?

Upgrade the NDK separately and recheck release optimization, LTO, exception paths and artifacts; our local Clang comparison illustrates why.

Start with a new release baseline

After upgrading to NDK r30, keep plugins and build settings fixed, rerun tests on real devices and compare native artifacts. In our local C++ sample, builds with and without LTO returned the same results for three inputs, but differed by 56 bytes and had different hashes. Matching behavior does not mean identical artifacts, and a changed artifact does not by itself imply a defect.

The release makes exception paths and optimized builds particularly useful checks: r30 fixes a runtime segfault involving LTO and nested exception handlers. [1]

Questions and results
QuestionFinding
Did the two runs agree?Three inputs returned 7, 22 and -1.
Were the binaries identical?No: 34,424 versus 34,368 bytes, with different hashes.
Did this verify the r30 fix?No; this is a local Clang illustration.

What changed in r30

Released at 19:19 UTC on 2026-09-08, r30 updates LLVM to clang-r574158c. Its notes also list fixes for an ARM -O3 compiler hang (Issue 2215), a references-and-pointers miscompilation (2225), an AArch64 defaulted equality operator compiler crash (2226), and LLDB failing to read a shared library that is the last APK entry (2234); the LTO issue is 2073. [1]

The same release raises the sysroot maximum API level to 37, improves ARM dot-product code generation and makes simpleperf prebuilts work on Android 10. Upstream LLVM 23.1.1 appeared at 10:58 UTC that day; Android ships its own Clang build, so the two are not interchangeable version labels. [1][2]

A fix does not establish that every app built with an older version was affected. The notes also make no compatibility promise for LLVM plugins: ask the provider about the specific Clang revision and evaluate a plugin upgrade separately.

A local comparison: same outputs, different binaries

We wrote a C++ program that calculates 3x+7 for nonnegative input and returns -1 for a negative input through nested exception handlers. We compiled and ran it on macOS arm64 with Apple clang 21.0.0, once with -O3 and once with -O3 -flto. This illustrates the baseline method with another tool; it is not an Android build, an r30 test or a reproduction of Issue 2073.

Measured output, copied verbatim.
== plain: -O3 ==
0 -> 7
5 -> 22
-1 -> -1
bytes: 34424

sha256: 4ce11e8c6c998dbfbf3e2510c8e22935331b5b7ba7203a7e65b7195da20779a9
== lto: -O3 -flto ==
0 -> 7
5 -> 22
-1 -> -1
bytes: 34368

sha256: 9bf6dd5d638ab8ff9112a14270483869065ae17e773b4246ce307c816dad1160
== binary comparison ==
different

The three inputs exercise ordinary results and one throw, rethrow and catch path. They are a small regression check, not proof of correctness for every input in a real program. Size and hashes depend on compilation, linking and environment; do not treat 56 bytes as a general LTO saving. Clang documents optimization levels and LTO as compiler options. [4]

Core commands in the comparison; we also recorded the version, sizes and hashes.
clang++ -std=c++17 -O3 sample.cpp -o build/plain
clang++ -std=c++17 -O3 -flto sample.cpp -o build/lto
build/plain
build/lto

Recommendations by case

These are engineering recommendations, not measured effects. Hold source, dependencies, ABI, build type and test data constant, and record the actual compiler and linker arguments. Retain the old baseline and unstripped symbols so differences and crashes can be investigated.

Recommendations: check one change at a time
CaseRecommendation
LLVM protection pluginConfirm the supported Clang revision; upgrade separately from the NDK.
LTO and exceptions enabledTest normal, caught and rethrown paths under release optimization.
Artifact changedCompare exports, stripping, size and behavior; do not rely on hashes alone.
Targeting API 37Validate relevant behavior and compatibility on Android 17 devices.

When comparing exports, first establish the library’s intended public interface. A changed export set can follow from visibility, linking or stripping settings, or from an intentional API change. Check callers for each difference and have the team responsible for the native interface review it. Investigate unexpected size changes alongside dependencies, build identifiers and linker settings instead of applying a fixed threshold in isolation. Record which checks need human judgment, so CI does not merely report a changed hash without an explanation. Keep the review with the release record and compare the same checks again after each subsequent compiler or plugin change.

First produce a reproducible reference build with the old NDK and current plugin. Change only the NDK and rerun the same tests. Once that passes, upgrade the plugin separately and compare again. If a stage fails, retain commands, device logs, the unstripped library and a minimal reproduction to distinguish toolchain, plugin and application effects.

Run the checks on your own app

Record the NDK and Clang used by each CI or local build. Substitute your installed NDK and host tag below. Android recommends passing the target triple directly; 21 in the example is the minimum API level, so use your project’s value. [3]

Record the compiler and compile your own source for the project target; add your project’s headers and flags.
TOOLCHAIN="$NDK/toolchains/llvm/prebuilt/$HOST_TAG"
"$TOOLCHAIN/bin/clang++" --version
"$TOOLCHAIN/bin/clang++" --target=aarch64-linux-android21 -c your_file.cpp -o your_file.o

Then build old and new releases through your normal project pipeline. On real devices, run functional, exception, startup and crash-diagnosis tests for each shipped ABI. Inspect packaged .so files alongside unstripped copies, retaining export lists, sizes, build identifiers and matching symbols. When results differ, first verify that the configurations match, then decide whether the change is expected or a regression that needs fixing.

Your checklist

  • Record the NDK and Clang revision for each release build.
  • Confirm plugin compiler support and upgrade it separately.
  • Exercise exception paths on real devices with release LTO settings.
  • Compare exports, stripping and size for every shipped ABI.
  • Retain matching unstripped symbols and verify crash diagnosis.

Primary sources

All sources and reproduction status ↗