how to determine armel vs armhf


11 posts
by savageautomate » Wed Oct 24, 2012 2:33 am
Is there a way to programmatically determine the ABI at runtime?
Looking for a way to determine if the system is armel or armhf at program startup.

Thanks, Robert
Robert Savage | Follow me @savageautomate
http://www.pi4j.com | http://www.pislices.com
http://www.savagehomeautomation.com
User avatar
Posts: 184
Joined: Thu Aug 16, 2012 3:20 pm
Location: USA
by jecxjo » Wed Oct 24, 2012 3:25 am
The defacto standard binary format for Linux is ELF (Executable and Linkable Format). ELF binaries have a standard header format that contains information about the system the executable was compiled for. If you google ELF Header Format you'll be able to get the whole list of parameters.

If you have a binary on your system you could also try running `readelf`

Code: Select all
[jeff@blue tmp]$ echo "int main () {return 0;}" > test.c
[jeff@blue tmp]$ gcc test.c -o test
[jeff@blue tmp]$ readelf -h test
ELF Header:
  Magic:   7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
  Class:                             ELF64
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              EXEC (Executable file)
  Machine:                           Advanced Micro Devices X86-64
  Version:                           0x1
  Entry point address:               0x4003c0
  Start of program headers:          64 (bytes into file)
  Start of section headers:          2472 (bytes into file)
  Flags:                             0x0
  Size of this header:               64 (bytes)
  Size of program headers:           56 (bytes)
  Number of program headers:         8
  Size of section headers:           64 (bytes)
  Number of section headers:         30
  Section header string table index: 27
[jeff@blue tmp]$


But now that I've gone on too long...to your question. The executable is what is compiled to be armel or armhf, not the system. If you use a compiler with hard float support then you get a hard float executable. If it is your own executable it may be easier to implement a header file in your Makefile that is built at compile time that is included in your executable. If the makefile determines its armel or armhf it outputs the appropriate value to the header file and builds.

My question to you though is why you want to know at run time. In most cases I would assume you'd write code separated by pre-processor commands to switch from armel optimized code to armhf optimized at compile time. What's your reasoning for wanting to know at runtime?
IRC (w/ SSL Support): jecxjo.mdns.org
Blog: http://jecxjo.motd.org/code
ProjectEuler Friend: 79556084281370_44d12dd95e92b1d9453aba2bdc94101b
User avatar
Posts: 157
Joined: Sat May 19, 2012 5:22 pm
Location: Ames, IA (USA)
by savageautomate » Wed Oct 24, 2012 6:04 am
jecxjo wrote:My question to you though is why you want to know at run time. In most cases I would assume you'd write code separated by pre-processor commands to switch from armel optimized code to armhf optimized at compile time. What's your reasoning for wanting to know at runtime?


Great question :D

In my use case, I am writing a Java library that depends on native libraries (via JNI). When the Java library is initialized I want to dynamically load the correct native library which is embedded inside the Java library's JAR file. I am trying to support both hard-float and soft-float native library .so files prepackaged inside a single JAR file and dynamically load the appropriate one based on the ABI of the system. So as you can see, since my starting point is a Java application, if I can determine the ABI at that layer, then I can make a decision on the correct pre-compiled native library (.so) file to extract from the JAR and dynamically load.

Thanks, Robert
Robert Savage | Follow me @savageautomate
http://www.pi4j.com | http://www.pislices.com
http://www.savagehomeautomation.com
User avatar
Posts: 184
Joined: Thu Aug 16, 2012 3:20 pm
Location: USA
by xranby » Wed Oct 24, 2012 8:53 am
savageautomate wrote:Is there a way to programmatically determine the ABI at runtime?
Looking for a way to determine if the system is armel or armhf at program startup.

Thanks, Robert


This is a hard problem we have discussed it on the OpenJDK IRC channel some months ago:
http://icedtea.classpath.org/wiki/New_o ... chitecture
Unfortunally OpenJDK and Oracle Java by itself do not contain any easy way to differentiate armel and armhf at runtime.

Like jecxjo pointed out it is possible to look at the elf header of the java binary.
This did also got mentioned by aph in the IRC chat that a quick oneliner solution is to execute
readelf -A /proc/self/exe | grep Tag_ABI_VFP_args
and then look if this Tag is found, if it is then you are running on a armhf system.

For JogAmp gluegen sgothel implemented a armhf detection by looking for the "gnueabihf" or "armhf" name in the system library paths to find out if we are running on a armhf system at runtime. Look at the guessABITypeImpl function:
https://github.com/sgothel/gluegen/blob ... .java#L160
Last edited by xranby on Wed Oct 24, 2012 9:16 am, edited 1 time in total.
Xerxes Rånby @xranby I once had two, then I gave one away. Now both are in use every day!
twitter.com/xranby
User avatar
Posts: 401
Joined: Sat Mar 03, 2012 10:02 pm
by Matt Harris » Wed Oct 24, 2012 9:12 am
In JMRI, we use the following snippet in our launch shell script to determine hard or soft float:
Code: Select all
  #determine hard vs. soft float using readelf
  HARDFLOAT=`readelf -a /usr/bin/readelf | grep armhf` 
  if [ -z "$HARDFLOAT" ]; then
    ARCH="armv5"
  else   
    ARCH="armv6l"
  fi
This is then used later on to determine the correct libraries to use.
Posts: 6
Joined: Fri Dec 23, 2011 11:22 pm
by plugwash » Wed Oct 24, 2012 11:30 am
xranby wrote:readelf -A /proc/self/exe | grep Tag_ABI_VFP_args

Be careful

That one liner will tell you whether readelf is armel or armhf.

While there are some issues that mean that we don't currently support such setups on the Pi it is possible to have a multiarch system with both armel and armhf. So readelf isn't nessecerally going to be the same as java.

What you actually want to do is read /proc/self/exe from your java code (or otherwise determine the location of the java executable that is being used) and then pass that to readelf.
Moderator
Moderator
Posts: 1965
Joined: Wed Dec 28, 2011 11:45 pm
by savageautomate » Thu Oct 25, 2012 3:55 am
xranby wrote:For JogAmp gluegen sgothel implemented a armhf detection by looking for the "gnueabihf" or "armhf" name in the system library paths to find out if we are running on a armhf system at runtime.


Thanks everybody for the very helpful info!

@xranby
I did use the example from JogAmp gluegen and it seems to be working just fine ... at least for my current needs. Now Pi4J will load its embedded native library using this ABI logic rather than relying on trial and exception logic.

Thanks! Robert
Robert Savage | Follow me @savageautomate
http://www.pi4j.com | http://www.pislices.com
http://www.savagehomeautomation.com
User avatar
Posts: 184
Joined: Thu Aug 16, 2012 3:20 pm
Location: USA
by xranby » Mon Jan 14, 2013 12:33 pm
There is an ongoing discussion inside the OpenJDK porters-dev mailing-list to add new system properties in OpenJDK 8/JDK 8 to allow easy armel vs armhf autodetection.
http://mail.openjdk.java.net/pipermail/ ... 00426.html
Xerxes Rånby @xranby I once had two, then I gave one away. Now both are in use every day!
twitter.com/xranby
User avatar
Posts: 401
Joined: Sat Mar 03, 2012 10:02 pm
by xranby » Fri Feb 08, 2013 2:29 pm
#JogAmp #gluegen have now implemented the check using a ELF header parser to determine ABI (armel/armhf) in use without relying if #JVM os.arch properties are set or not.
JogAmp Bug 681: Add Basic ELF Header + ARM EABI Section Parsing, allowing to distinguish ARM soft-float/hard-float
http://jogamp.org/git/?p=gluegen.git;a= ... bdabf8a6a9
Xerxes Rånby @xranby I once had two, then I gave one away. Now both are in use every day!
twitter.com/xranby
User avatar
Posts: 401
Joined: Sat Mar 03, 2012 10:02 pm
by xranby » Fri Feb 08, 2013 7:59 pm
xranby wrote:#JogAmp #gluegen have now implemented the check using a ELF header parser to determine ABI (armel/armhf) in use without relying if #JVM os.arch properties are set or not.
JogAmp Bug 681: Add Basic ELF Header + ARM EABI Section Parsing, allowing to distinguish ARM soft-float/hard-float
http://jogamp.org/git/?p=gluegen.git;a= ... bdabf8a6a9


JogAmp Bug 681: Use ELF Header + ARM EABI Section Parsing in PlatformPropsImpl to to distinguish ARM soft-float/hard-float (part-2)
http://jogamp.org/git/?p=gluegen.git;a= ... abb06eed82

This commit show how to switch from guessABITypeImpl to queryABITypeImpl thus allows your application to find out the ABI ar runtime without relying if proper #JVM os.arch & ABI properties are set or not.
Xerxes Rånby @xranby I once had two, then I gave one away. Now both are in use every day!
twitter.com/xranby
User avatar
Posts: 401
Joined: Sat Mar 03, 2012 10:02 pm
by Bobthepeanut » Sun May 05, 2013 7:28 am
There is also a way to get the information with apt-get. Just run apt-get update and you will see that some of the package names contain armel/armhf.
Posts: 1
Joined: Sun May 05, 2013 7:26 am