runtime detection whether ARMv7 ELF binaries can be loaded on ARMv6 host

117 Views Asked by At

Consider a host application that has been compiled for armv6 (think: Raspbian) and can dlopen() extensions/plugins. Some of these plugins might be compiled for armv7.

If the host application is running on a recent hardware, there shouldn't be any problem loading and running these plugins. OTOH, if the application is running on legacy hardware (e.g. RPi2), the dlopen() will probably fail.

Now I would like to determine, whether the host application is capable of loading armv7 binaries, without actually trying to do so.

My use case is: writing a package manager that queries an online resource for available plugins; only compatible packages should be displayed: if the host is running on armv6, only armv6 plugins will be shown, but if it is running on armv7 both armv7 and armv6 binaries are presented.

The package architecture (as can be queried via the online resource) is detected via something like readelf -A <binary> | grep Tag_CPU_arch.

My original attempt used the __ARM_ARCH macro on the host, but that is obviously a compile-time check rather than a runtime check. On x86, there's __builtin_cpu_supports() (for gcc and friends), but that is not available on ARM. Parsing /proc/cpuinfo might be an option, but honestly I have no clue what to check for...

Ideas?

0

There are 0 best solutions below