6

On AIX 6.1 ppc64, in order to load libm.a, our application uses the System.loadLibrary("m"). Or it fails with an error message

the module has invalid magic number

According to IBM documentation, this can happen when there is a mismatch between 32 bits and 64 bits binaries. Or this happens whether we use Java6 (32 bits) or Java6_64 (64 bits) JVM. So it is NOT the case.

Another possible causes is /usr/lib/libm.a is NOT a shared library. But we just can't find a shared mode libm.a on the platform to use!

Acccdoring to Javadoc, in System.loadLibrary("name") , the mapping of "name" on to a real library is system dependent. On most Unix system, it is mapped to lib.so, while on AIX, it is mapped on to lib.a ; Note that on AIX, .a can be hybrid, ie. it can contain both static and shared object, 32 bits as well as 64 bits object. My problem is find a shared mode libm.a on AIX.

Does anybody know how to use System.loadLibrary("m") to load a libm.a?

P.S System.loadLibrary("m") works fine on most UNIX platforms we have tested.

  • 5
    Could be wrong, but aren't files ending with ".a" in Linux/Unix-environments usually compiled static objects, that need to be linked to form a binary? AFAIK, shared objects (dynamic libraries) end in .so. – esaj Jan 22 '12 at 13:51
  • 1
    You can only load shared libraries dynamically. `.a` libraries need to be compiled into the program. In the case of the JVM, when you build the JVM. – Peter Lawrey Jan 22 '12 at 13:53
  • 2
    Acccdoring to Javadoc, in System.loadLibrary("name") , the mapping of "name" on to a real library is system dependent. On most Unix system, it is mapped to lib.so, while on AIX, it is mapped on to lib.a ; Note that on AIX, .a can be hybrid, ie. it can contain both static and shared object, 32 bits as well as 64 bits object. My problem is find a shared mode libm.a on AIX... – Chen Nam Sit Jan 22 '12 at 14:54
  • @esaj: AIX is a bit odd in that respect. To quote the manual: "The naming convention for a shared object on AIX is name.o" and "The naming convention for a shared library on AIX is of the form libname.a" http://publib.boulder.ibm.com/infocenter/comphelp/v7v91/index.jsp?topic=%2Fcom.ibm.vacpp7a.doc%2Fgetstart%2Foverview%2Fport_aix_obj_lib.htm – NPE Jan 22 '12 at 16:01
  • 1
    Could you explain why you need to load libm from Java? – Mat Jan 22 '12 at 17:42
  • Well, as a matter of fact, I am using JNA to access a native library. Although I have ported JNA on aix-ppc and aix-ppc64, and pass 94% of the JUNIT tests, I still have some troubles in using JNA's Native.loadLibrary("m"). It fails with the same error message: the module has invalid magic number. So I want to boil down the problem by trying to see how pure Java System.loadLibrary() behaves. Unfortunately, it is the same behavior. If I could find out a shared mode libm.a on AIX, I would be saved. I have also google on the subject, but always without success. – Chen Nam Sit Jan 22 '12 at 19:00
  • @shellter I haven't tried libm.o ; but I don't think it is applicable, .o is single object, while .a is a collection of objects. I have also use dump -ov /usr/lib/libm.a, and it looks there are NO shared objects in side, all objects are static! unless I miss something.... – Chen Nam Sit Jan 22 '12 at 19:30

2 Answers2

1

On AIX, the shared objects that come with the distribution are placed into ar-archives, for example in 32-bit, it is:

System.load("/usr/lib/libbsd.a(shr.o)")

In 64-bit:

System.load("/usr/lib/libbsd.a(shr_64.o)")

Sadly, libm.a doesn't contain any shared objects (only ordinary .o object modules), so dynamic linking is not possible.

Lorinczy Zsigmond
  • 1,749
  • 1
  • 14
  • 21
1

You can use 'dump -H' (AIX equivalent of ldd) to verify that libm.a is a shared library. The 'file' command should distinguish 32- and 64-bit libraries, but AIX also supports hybrid 32 and 64-bit in one library. If the file looks ok, check that your apps is loading the right libm using 'truss'.

Colm Smyth
  • 104
  • 2
  • Well, I have already done that. dump -vo show "Loader Section is not available", and there is no "shr.o" like in libc.a. That is why I said it is a staic library. My question is where can I find a shared version of "libm.a" or equivalent. – Chen Nam Sit Feb 23 '12 at 08:30
  • libm.a is probably the AIX math library. Bundled versions of this library are sometimes buggy; you might find it easiest to build an AIX version of the GNU math library, see for example http://sourceware.org/ml/libc-help/2008-06/msg00049.html for some instructions that may help you build it independently of GNU libc. – Colm Smyth Feb 24 '12 at 01:06
  • One other thought - if you've already tested your app on Linux, you'll probably find using the GNU libm to give you better portability from your Java code, even if you have to bundle the GNU libm shared library for your AIX version. – Colm Smyth Feb 24 '12 at 01:12
  • Thanks. That could be a solution. But it is strange thant IBM doesn't provide users with a loadable shared mode libm.a, like they do for libc.a – Chen Nam Sit Feb 29 '12 at 08:46
  • For MATH lib on aix, use the GCC version for AIX: libmpc.q(shr.o) or libmpc.so.2. They are both shared mode libraries. – Chen Nam Sit Mar 12 '12 at 08:50