3-way universal jnilibs: libvernier_ccsd_<arch>

7 views
Skip to first unread message

Stephen Bannasch

unread,
Sep 13, 2010, 2:38:52 AM9/13/10
to org-conco...@googlegroups.com
I'm much closer to getting arch-specific vernier goio ccsd.jnilibs working.

I pushed a git fork of the sensor-native project here: http://github.com/concord-consortium/sensor-native

There's also an update to the goio-sdk repo: http://github.com/concord-consortium/goio_sdk to enable 3-way universal build of
the static libGoIO_DLL.a

Here's the size of each arch-specific nar the sensor-native project can create now (the pack.gz files are practically the same
size) -- they are much smaller!

$ ls -lh *-1.jar

100K vernier-goio-macosx-i386-nar__V0.1.0-20100913.004325-1.jar
89K vernier-goio-macosx-ppc7400-nar__V0.1.0-20100913.004324-1.jar
108K vernier-goio-macosx-x86_64-nar__V0.1.0-20100913.004326-1.jar

I updated the include and binary files from the vernier goio SDK to those created in v2.28.

I was having compile errors in VernierSensorDevice_wrap.c with references to jenv which went away when I switched swig to
generating C++ ... and those errors went away.

The old Makefile is renamed to Makefile-not-mac and I copied Makefile-mac to Makefile.

I hacked a number of additional changes to the Makefile:

make vernier-swig
make bin/local/libvernier_ccsd.jnilib
make vernier_lipo
vernier_nar_archives

make vernier_lipo extracts these from bin/local/libvernier_ccsd.jnilib

bin/libvernier_ccsd_ppc7400.jnilib
bin/libvernier_ccsd_i386.jnilib
bin/libvernier_ccsd_x86_64.jnilib

There's a similar ruby file for packaging and deploying them to the local jnlp server for testing: see: deploy_nar_archives.rb
at this gist: http://gist.github.com/575897

I also included arch-specific dylibs. I haven't tested them yet with the ruby-ffi test program:

vernier_goio_sdk/libGoIO_DLL_i386.dylib
vernier_goio_sdk/libGoIO_DLL_ppc7400.dylib
vernier_goio_sdk/libGoIO_DLL_x86_64.dylib

They're just extracted form the universal 3-way dylib -- they aren't used in the make process.

But ... running make bin/local/libvernier_ccsd.jnilib generates these arch errors which are probably why the jnilibs don't
work right yet:

[sensor-native (master)]$ make bin/local/libvernier_ccsd.jnilib
mkdir -p nativelib
mkdir -p nativelib/test
g++ -Iinclude -Ivernier_goio_sdk -DTARGET_OS_MAC -arch i386 -arch ppc -arch x86_64 -c src/c/GoLinkSensorDevice.c -o
nativelib/GoLinkSensorDevice.o
src/c/GoLinkSensorDevice.c: In function 'int configure_sensor(GO_STATE*, SensorConfig*, SensorConfig*)':
src/c/GoLinkSensorDevice.c:361: warning: format not a string literal and no format arguments
src/c/GoLinkSensorDevice.c:446: warning: unknown conversion type character 'R' in format
src/c/GoLinkSensorDevice.c:455: warning: unknown conversion type character 'T' in format
src/c/GoLinkSensorDevice.c:743: warning: unknown conversion type character 'R' in format
src/c/GoLinkSensorDevice.c: In function 'void open_go(GO_STATE*)':
src/c/GoLinkSensorDevice.c:839: warning: format '%d' expects type 'int', but argument 2 has type 'void*'
src/c/GoLinkSensorDevice.c: In function 'int SensDev_start(void*)':
src/c/GoLinkSensorDevice.c:930: warning: format '%d' expects type 'int', but argument 2 has type 'void*'
src/c/GoLinkSensorDevice.c: In function 'int configure_sensor(GO_STATE*, SensorConfig*, SensorConfig*)':
src/c/GoLinkSensorDevice.c:361: warning: format not a string literal and no format arguments
src/c/GoLinkSensorDevice.c:446: warning: unknown conversion type character 'R' in format
src/c/GoLinkSensorDevice.c:455: warning: unknown conversion type character 'T' in format
src/c/GoLinkSensorDevice.c:743: warning: unknown conversion type character 'R' in format
src/c/GoLinkSensorDevice.c: In function 'void open_go(GO_STATE*)':
src/c/GoLinkSensorDevice.c:839: warning: format '%d' expects type 'int', but argument 2 has type 'void*'
src/c/GoLinkSensorDevice.c: In function 'int SensDev_start(void*)':
src/c/GoLinkSensorDevice.c:930: warning: format '%d' expects type 'int', but argument 2 has type 'void*'
src/c/GoLinkSensorDevice.c: In function 'int configure_sensor(GO_STATE*, SensorConfig*, SensorConfig*)':
src/c/GoLinkSensorDevice.c:361: warning: format not a string literal and no format arguments
src/c/GoLinkSensorDevice.c:446: warning: unknown conversion type character 'R' in format
src/c/GoLinkSensorDevice.c:455: warning: unknown conversion type character 'T' in format
src/c/GoLinkSensorDevice.c:743: warning: unknown conversion type character 'R' in format
src/c/GoLinkSensorDevice.c: In function 'void open_go(GO_STATE*)':
src/c/GoLinkSensorDevice.c:839: warning: format '%d' expects type 'int', but argument 2 has type 'void*'
src/c/GoLinkSensorDevice.c: In function 'int SensDev_start(void*)':
src/c/GoLinkSensorDevice.c:930: warning: format '%d' expects type 'int', but argument 2 has type 'void*'
mkdir -p nativelib/swig
g++ -c src/swig/VernierSensorDevice_wrap.c -I/System/Library/Frameworks/JavaVM.framework/Headers -Iinclude -o
nativelib/swig/VernierSensorDevice_wrap.o
g++ -bundle nativelib/GoLinkSensorDevice.o vernier_goio_sdk/libGoIO_DLL.a nativelib/swig/VernierSensorDevice_wrap.o -o
bin/local/libvernier_ccsd.jnilib -framework JavaVM -bind_at_load -framework IOKit -framework Cocoa -framework Carbon
-I/System/Library/Frameworks/JavaVM.framework/Headers -arch i386 -arch ppc -arch x86_64
ld: warning: in nativelib/swig/VernierSensorDevice_wrap.o, file was built for unsupported file format which is not the
architecture being linked (i386)
ld: warning: in nativelib/swig/VernierSensorDevice_wrap.o, file was built for unsupported file format which is not the
architecture being linked (ppc)
#gcc -bundle nativelib/GoLinkSensorDevice.o nativelib/swig/VernierSensorDevice_wrap.o -o bin/local/libvernier_ccsd.jnilib
-framework JavaVM

lipo thinks there are three arches -- but they aren't yet working archs:

[sensor-native (master)]$ lipo -detailed_info bin/local/libvernier_ccsd.jnilib
Fat header in: bin/local/libvernier_ccsd.jnilib
fat_magic 0xcafebabe
nfat_arch 3
architecture i386
cputype CPU_TYPE_I386
cpusubtype CPU_SUBTYPE_I386_ALL
offset 4096
size 341968
align 2^12 (4096)
architecture ppc7400
cputype CPU_TYPE_POWERPC
cpusubtype CPU_SUBTYPE_POWERPC_7400
offset 348160
size 358772
align 2^12 (4096)
architecture x86_64
cputype CPU_TYPE_X86_64
cpusubtype CPU_SUBTYPE_X86_64_ALL
offset 708608
size 400840
align 2^12 (4096)

Here are the errors in the consoles when running the applet on all three arches:

MacOS X 10.4.11 PowerPC G4
network: Connecting
http://stepheneb-2.local.:4321/jnlp/org/concord/sensor/vernier/vernier-goio/vernier-goio-macosx-ppc7400-nar.jar with proxy=HTTP
@ /127.0.0.1:8888
Created temp file: /tmp/vsl1052899654680383045/libvernier_ccsd_ppc7400-5983828347548774778.jnilib
loading: /tmp/vsl1052899654680383045/libvernier_ccsd_ppc7400-5983828347548774778.jnilib
java.lang.UnsatisfiedLinkError: /private/tmp/vsl1052899654680383045/libvernier_ccsd_ppc7400-5983828347548774778.jnilib:
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1751)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1647)
at java.lang.Runtime.load0(Runtime.java:769)
at java.lang.System.load(System.java:968)
at org.concord.sensor.applet.NativeLibraryHandler.loadLib(NativeLibraryHandler.java:71)
at org.concord.sensor.applet.NativeLibraryHandler.initializeLibrary(NativeLibraryHandler.java:41)
at org.concord.sensor.applet.OTSensorApplet.init(OTSensorApplet.java:69)
at sun.applet.AppletPanel.run(AppletPanel.java:380)
at java.lang.Thread.run(Thread.java:613)
basic: Exception: java.lang.UnsatisfiedLinkError:
/private/tmp/vsl1052899654680383045/libvernier_ccsd_ppc7400-5983828347548774778.jnilib:

MacOS X 10.5.8 Intel Core 2 Duo33ee3333333333233
network: Connecting
http://stepheneb-2.local.:4321/jnlp/org/concord/sensor/vernier/vernier-goio/vernier-goio-macosx-i386-nar.jar with proxy=DIRECT
network: Downloading resource:
http://stepheneb-2.local.:4321/jnlp/org/concord/sensor/vernier/vernier-goio/vernier-goio-macosx-i386-nar.jar
Content-Length: 102,288
Content-Encoding: null
network: CleanupThread used 6 us
network: Wrote URL http://stepheneb-2.local.:4321/jnlp/org/concord/sensor/vernier/vernier-goio/vernier-goio-macosx-i386-nar.jar
to File /Users/stephen/Library/Caches/Java/cache/6.0/41/76b27a29-3eb4b8c6-temp
security: Blacklist file not found or revocation check is disabled
security: Trusted libraries list file not found
network: CleanupThread used 8 us
Created temp file:
/var/folders/zK/zK+A4xtxHSevr7D+EoIsPE+++TI/-Tmp-/vsl649843773438273062/libvernier_ccsd_i386-7982643381950570282.jnilib
loading: /var/folders/zK/zK+A4xtxHSevr7D+EoIsPE+++TI/-Tmp-/vsl649843773438273062/libvernier_ccsd_i386-7982643381950570282.jnilib
java.lang.UnsatisfiedLinkError:
/private/var/folders/zK/zK+A4xtxHSevr7D+EoIsPE+++TI/-Tmp-/vsl649843773438273062/libvernier_ccsd_i386-7982643381950570282.jnilib:
no suitable image found. Did find:
/private/var/folders/zK/zK+A4xtxHSevr7D+EoIsPE+++TI/-Tmp-/vsl649843773438273062/libvernier_ccsd_i386-7982643381950570282.jnilib:
unknown required load command 0x80000022
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1824)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1704)
at java.lang.Runtime.load0(Runtime.java:769)
at java.lang.System.load(System.java:968)
at org.concord.sensor.applet.NativeLibraryHandler.loadLib(NativeLibraryHandler.java:71)
at org.concord.sensor.applet.NativeLibraryHandler.initializeLibrary(NativeLibraryHandler.java:44)
at org.concord.sensor.applet.OTSensorApplet.init(OTSensorApplet.java:69)
at sun.applet.AppletPanel.run(AppletPanel.java:425)
at java.lang.Thread.run(Thread.java:613)
basic: Exception: java.lang.UnsatisfiedLinkError:

Mac OS X 10.6.4 Intel Core i7

Created temp file:
/var/folders/zK/zK+A4xtxHSevr7D+EoIsPE+++TQ/-Tmp-/vsl3719393089652381596/libvernier_ccsd_x86_64-2637092261220407504.jnilib
loading:
/var/folders/zK/zK+A4xtxHSevr7D+EoIsPE+++TQ/-Tmp-/vsl3719393089652381596/libvernier_ccsd_x86_64-2637092261220407504.jnilib
sensor started init
sensor codebase: http://stepheneb-2.local.:4321/jnlp/
applet.start called on sensor
sensor url otml/temperature.otml
Sep 13, 2010 1:59:15 AM org.concord.otrunk.xml.XMLDatabase loadObjects
INFO: Loaded 7 objects from: http://stepheneb-2.local.:4321/otml/temperature.otml (unknown size) opened url in 0ms downloaded
and parsed xml in 251ms loaded ot db in 59ms
sensor found: sensor
Loading sensor device: org.concord.sensor.nativelib.NativeVernierSensorDevice
Ignored exception: java.security.PrivilegedActionException: java.lang.reflect.InvocationTargetException

Scott Cytacki

unread,
Sep 13, 2010, 8:17:23 AM9/13/10
to org-conco...@googlegroups.com
Sorry I didn't respond to this sooner.
You can do make -f Makefile.mac if you want to run it without renaming.
The jnilib is currently linked with a static version of the GoIOLib.   This is because when loading from webstart it didn't used to be able to find secondary dynamic libraries.  However this is how JNA works it loads in a secondary dynamic library and it works, so it certainly is possible, but I think you need so special native code so the first library can find the second.

Instead you probably want to try compiling your 64bit GoIOlib as a static library.  If you look at the linking line: 

g++ -bundle nativelib/GoLinkSensorDevice.o vernier_goio_sdk/libGoIO_DLL.a nativelib/swig/VernierSensorDevice_wrap.o -o bin/local/libvernier_ccsd.jnilib -framework JavaVM -bind_at_load -framework IOKit -framework Cocoa -framework Carbon -I/System/Library/Frameworks/JavaVM.framework/Headers -arch i386 -arch ppc -arch x86_64

It is linking vernier_goio_sdk/libGoIO_DLL.a,  my guess is that is an old library that you haven't recompiled to contain the 64bit arch.

I think that is why it isn't working on the 64bit mac.  The reason it isn't working on the other macs seems different.

I'd prefer to finish up the JNA vernier support instead of spending much time on this.

Scott

--
You received this message because you are subscribed to the Google
Groups "org-concord-sensor" group.
To post to this group, send email to org-conco...@googlegroups.com
To unsubscribe from this group, send email to
org-concord-sen...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/org-concord-sensor?hl=en?hl=en
Google Code project for org-concord-sensor: http://code.google.com/p/org-concord-sensor/

Stephen Bannasch

unread,
Sep 13, 2010, 8:18:27 AM9/13/10
to org-conco...@googlegroups.com
There are also updates in a git fork of the sensor-applets project to enable arch-specific downloading of then archive files:
http://github.com/concord-consortium/sensor-applets

Stephen Bannasch

unread,
Sep 13, 2010, 10:45:19 AM9/13/10
to org-conco...@googlegroups.com
At 8:17 AM -0400 9/13/10, Scott Cytacki wrote:
>Sorry I didn't respond to this sooner.

I posted at at almost 3 in the morning and you responded just after 8AM -- seems pretty responsive to me ;-)

>You can do make -f Makefile.mac if you want to run it without renaming.
>The jnilib is currently linked with a static version of the GoIOLib. This is because when loading from webstart it didn't used to be able to find secondary dynamic libraries. However this is how JNA works it loads in a secondary dynamic library and it works, so it certainly is possible, but I think you need so special native code so the first library can find the second.
>
>Instead you probably want to try compiling your 64bit GoIOlib as a static library. If you look at the linking line:
>
>g++ -bundle nativelib/GoLinkSensorDevice.o vernier_goio_sdk/libGoIO_DLL.a nativelib/swig/VernierSensorDevice_wrap.o -o bin/local/libvernier_ccsd.jnilib -framework JavaVM -bind_at_load -framework IOKit -framework Cocoa -framework Carbon -I/System/Library/Frameworks/JavaVM.framework/Headers -arch i386 -arch ppc -arch x86_64
>
>
>It is linking vernier_goio_sdk/libGoIO_DLL.a, my guess is that is an old library that you haven't recompiled to contain the 64bit arch.

I had already updated the static lib:

http://github.com/concord-consortium/sensor-native/commit/ee323ea963374c35b3f2163c4dd1bca3a9937c81

$ lipo -detailed_info vernier_goio_sdk/libGoIO_DLL.a
Fat header in: vernier_goio_sdk/libGoIO_DLL.a
fat_magic 0xcafebabe
nfat_arch 3


architecture x86_64
cputype CPU_TYPE_X86_64
cpusubtype CPU_SUBTYPE_X86_64_ALL

offset 68
size 2170600
align 2^2 (4)
architecture ppc
cputype CPU_TYPE_POWERPC
cpusubtype CPU_SUBTYPE_POWERPC_ALL
offset 2170668
size 2263272
align 2^2 (4)


architecture i386
cputype CPU_TYPE_I386
cpusubtype CPU_SUBTYPE_I386_ALL

offset 4433940
size 2083776
align 2^2 (4)

But perhaps I should extract the arch-specific libs from the universal builds in the goio_sdk project and test all of them withmy ruby-ffi program on the three archs to get an outof-band confirmation that they work.

>I think that is why it isn't working on the 64bit mac. The reason it isn't working on the other macs seems different.

I think there is something else I need to do to fix these problems with the i386 and ppc arches when the library is compiled:

ld: warning: in nativelib/swig/VernierSensorDevice_wrap.o,
file was built for unsupported file format which is not the
architecture being linked (i386)

ld: warning: in nativelib/swig/VernierSensorDevice_wrap.o,
file was built for unsupported file format which is not

architecture being linked (ppc)

I suspect there is some problem with the compiler invocation:

g++ -Iinclude -Ivernier_goio_sdk -DTARGET_OS_MAC -arch i386 -arch ppc -arch x86_64 -c \
src/c/GoLinkSensorDevice.c -o nativelib/GoLinkSensorDevice.o

Obviously the VernierSensorDevice_wrap.o files need to be built for all three archs.

Your vernier-lipo task made one jnilib about of the mactintel and ppc jnilibs. I didn't see anything that made them -- but perhaps I should first generate each arch-specific jnilib separately and then combine them instead of the other way around.

>I'd prefer to finish up the JNA vernier support instead of spending much time on this.

Possibly with a bit more help I can have this finished today ...

src/swig/CCSensorDevice.i has these includes:

%include "carrays.i"
%include "typemaps.i"

The files don't exist in the repo. Are they headers coming from swig?

Reply all
Reply to author
Forward
0 new messages