Pi4J/pi4j-v1

UnsatisfiedLinkError: /tmp/libpi4j.so

drvonnostrand opened this issue · 3 comments

The logic in public static boolean isHardFloatAbi() in SystemInfo.java fails against Oracle's jdk1.8.0(hard-float) running Wheezy. Looks like others out there are discussing the best way to determine hard vs soft float at runtime as well.
One solution is to use 'readelf -A /proc/self/exe' and check for Tag_ABI_VPF_args or
'readelf -a /usr/bin/readelf | grep armh'. I decided to use the former. See:

http://www.raspberrypi.org/phpBB3/viewtopic.php?f=33&t=20873&p=201219
for all the details.

I added the following method to SystemInfo.java:
public static boolean hasReadElfTag(String tag) {
boolean hasTag = false;
try {
String cmd =
"/usr/bin/readelf -A /proc/self/exe";
Process p=Runtime.getRuntime().exec(cmd);
p.waitFor();
BufferedReader reader=
new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = reader.readLine();
while(line != null) {
if (line.contains(tag)) {
hasTag = true;
break;
}
line = reader.readLine();
}
}
catch (IOException ioe) {
}
catch (InterruptedException ie) {
}
return hasTag;
}
and then added this to the checks in isHardFloatAbi() like so:
if ( contains(System.getProperty("sun.boot.library.path"),
gnueabihf) ||
contains(System.getProperty("java.library.path"),
gnueabihf) ||
contains(System.getProperty("java.home"), gnueabihf) ||
hasReadElfTag("Tag_ABI_VFP_args")) {
return true;
}

recompiled and tested just fine but only on my pi. If checking the tag is robust enough then the other checks can be removed as well.

Hi drvonnostrand,

I have updated the source code to include two new pieces of logic to help detect hard-float.
I added a slightly modified version of the code you posted as well as a method that obtains the "bash" version which includes a unique tag for hard-float as shown below:

.. on hard-float ABI :
GNU bash, version 4.2.36(1)-release (arm-unknown-linux-gnueabihf)

.. on soft-float ABI :
GNU bash, version 4.2.36(1)-release (arm-unknown-linux-gnueabi)

On the hasReadElfTag() check, I am keying off this tag instead: "Tag_ABI_HardFP_use".

see:
https://github.com/Pi4J/pi4j/blob/develop/pi4j-core/src/main/java/com/pi4j/system/SystemInfo.java#L157

I did deploy a new 0.0.5-SNAPSHOT build to include this fix.
http://code.google.com/p/pi4j/downloads/list

Look Good?
Thanks, Robert

Hi Robert,

Great. I took a look at the code and it looks good. A couple minor comments:

  • Since getBashVersionInfo and getReadElfTag are public, it would be consistent with the other
    public methods to throw these exceptions up or they could be made private since they seem to
    be helpers for isHardFloatAbi().
  • In getReadElfTag(String tag):
    I'm not sure if all Tags are guaranteed to have values(ie. text after the colon). If not,
    the following code will throw when trying to access lineParts[1]:
    if (line.startsWith(tag) && line.contains(":")) {
    String lineParts[] = line.split(":", 2);
    tagValue = lineParts[1].trim();
    break;
    }

Thanks for all your work.

cheers,
-- rick

On Sun, Dec 30, 2012 at 09:53:02AM -0800, Robert Savage wrote:

Hi drvonnostrand,

I have updated the source code to include two new pieces of logic to help
detect hard-float.
I added a slightly modified version of the code you posted as well as a
method that obtains the "bash" version which includes a unique tag for
hard-float as shown below:

.. on hard-float ABI :
GNU bash, version 4.2.36(1)-release (arm-unknown-linux-gnueabihf)

.. on soft-float ABI :
GNU bash, version 4.2.36(1)-release (arm-unknown-linux-gnueabi)

On the hasReadElfTag() check, I am keying off this tag instead:
"Tag_ABI_HardFP_use".

see:
https://github.com/Pi4J/pi4j/blob/develop/pi4j-core/src/main/java/com/pi4j/system/SystemInfo.java#L157

I did deploy a new 0.0.5-SNAPSHOT build to include this fix.
http://code.google.com/p/pi4j/downloads/list

Look Good?
Thanks, Robert

Reply to this email directly or view it on GitHub.

Hi Rick, thanks for the feedback. I actually intended to make those private but forgot to go back and do it before the commit. I have now made them private and added the additional logic to handle the cases where a value may not be a value after the split().

Thanks, Robert