diff options
author | David 'Digit' Turner <digit@google.com> | 2014-04-17 09:58:51 +0200 |
---|---|---|
committer | David 'Digit' Turner <digit@google.com> | 2014-05-20 14:48:54 +0200 |
commit | 882ac8f3392858991a0e1af33b4b7387ec856bd2 (patch) | |
tree | 8c11f0ba9d7b655a0b4c5c3a94d71a7a815d93b7 /tests | |
parent | 0aeff661b8c3c949865dbfe811b7ba9fef2f256a (diff) | |
download | ndk-882ac8f3392858991a0e1af33b4b7387ec856bd2.tar.gz |
cpu-features: Support 32-bit ARM binaries running on an ARM64 kernel.
This addresses several issues related to 32-bit ARM binaries running
on an ARMv8 CPU.
The first one is that API level 20 exposes getauxval() in <sys/auxv.h>
which provides a reliably way to extract the ARM ELF HwCaps, so try
to use it when possible. Note that this adds -ldl as a LDLIBS
export for the library.
The second one is that /proc/self/auxv should always be the preferred
to /proc/cpuinfo for a process to access the 32-bit ARM ELF HWCaps.
Unfortunately, this file is not always accessible on some recent
Android platform versions, even though this may be fixed in the future.
When the file is not accessible, parse /proc/cpuinfo as a fallback,
but deal with the fact that the 'Features' field only list features
that are optional for the device's CPU reference architecture revision.
I.e. when running on an ARMv8 CPU, it will not list the typical
ARMv7 extensions that became mandatory in ARMv8.
+ Refresh and clarify documentation to explain that the output of
android_getCpuFamily() depends on the process' bitness, not the
target device's CPU.
+ Check that android_getCpuFeatures() returns 0 as expected on
anything except 32-bit ARM and 32-bit Intel.
+ Fix the reporting of ARM IDIV instruction by Goldfish kernels
/ Android emulators.
BUG=13679666
Change-Id: Icad8a9d0a7cf651f42a717219c597205586a0a72
Diffstat (limited to 'tests')
-rw-r--r-- | tests/device/test-cpufeatures/jni/test_cpufeatures.c | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/tests/device/test-cpufeatures/jni/test_cpufeatures.c b/tests/device/test-cpufeatures/jni/test_cpufeatures.c index c5fe0c738..861032a69 100644 --- a/tests/device/test-cpufeatures/jni/test_cpufeatures.c +++ b/tests/device/test-cpufeatures/jni/test_cpufeatures.c @@ -13,7 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#define __STDC_FORMAT_MACROS 1 + #include <cpu-features.h> +#include <inttypes.h> #include <stdio.h> int main(void) @@ -87,7 +90,21 @@ int main(void) #undef CHECK } + int result = 0; + + // Check that the CPU features mask is empty for anything that isn't + // 32-bit ARM or 32-bit x86. + if (family != ANDROID_CPU_FAMILY_ARM && + family != ANDROID_CPU_FAMILY_X86) { + uint64_t features = android_getCpuFeatures(); + if (features != 0) { + printf("ERROR: Unexpected CPU features mask: %016" PRIX64 "\n", + features); + result = 1; + } + } + int count = android_getCpuCount(); printf( "Number of CPU cores: %d\n", count); - return 0; + return result; } |