From a21b93c394a8e5233b85639c6552c47e05419215 Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Thu, 9 Feb 2023 14:45:08 -0600 Subject: [PATCH] Clean up and clarify Android targeting code Use the online NDK compiler docs at [0] as a reference to document some of the existing behavior and supplement with a linker argument. Don't rely on vague things like "x86 doesn't contain eabi" and just test for the architectures we are targeting in the Android-specific code. [0]: https://developer.android.com/ndk/guides/standalone_toolchain --- src/lib.rs | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 435537d1b..d90c67d55 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1930,17 +1930,34 @@ impl Build { } } - // (x86 Android doesn't say "eabi") - if target.contains("-androideabi") && target.contains("v7") { - // -march=armv7-a handled above + // -march=armv7-a (handled above) and -mthumb (handled above) can be + // present separately or together. In the absence of an explicit --target, + // only -march=armv7-a targets armv7-none-linux-androideabi, only -mthumb + // targets thumb-non-linux-androideabi, while supplying both targets + // thumbv7-non-linux-androideabi. It is recommended to supply -mthumb to + // force the use of 16-bit Thumb-2 instructions instead of 32-bit ARM + // instructions. + // Source: https://developer.android.com/ndk/guides/standalone_toolchain + if (target.starts_with("thumbv7") || target.starts_with("armv7")) + && target.contains("-androideabi") + { cmd.args.push("-mthumb".into()); if !target.contains("neon") { - // On android we can guarantee some extra float instructions - // (specified in the android spec online) - // NEON guarantees even more; see below. + // On android we can guarantee some extra float instructions (per + // the online spec). NEON guarantees even more; see below. cmd.args.push("-mfpu=vfpv3-d16".into()); } cmd.args.push("-mfloat-abi=softfp".into()); + + // Android NDK link above says to make sure the following flag is + // passed to the linker to work around a CPU bug on some Cortex-A8 + // implementations. + cmd.args.push("-Wl,--fix-cortex-a8".into()); + } + + if target.contains("neon") { + // This automatically forces the use of VFPv3-D32, per ARM specifications + cmd.args.push("-mfpu=neon-vfpv4".into()); } // Looks like `musl-gcc` makes it hard for `-m32` to make its way @@ -1951,10 +1968,6 @@ impl Build { if target == "i686-unknown-linux-musl" || target == "i586-unknown-linux-musl" { cmd.args.push("-Wl,-melf_i386".into()); } - - if target.contains("neon") { - cmd.args.push("-mfpu=neon-vfpv4".into()); - } } }