SHARED libraries on AIX

SHARED libraries on AIX

Post by Bernhard Reitinge » Wed, 12 Dec 2001 19:11:58



Hello !

In our development team, we are currently stucked. We are using
shared libraries with java, and do have problems by using
either gcc or xl[cC] compiler. Our application crashes as soon
as we call some functions out of the shared library with
the following message:

----------
SIGILL 4 (*) illegal instruction (not reset when caught)
    si_signo [4]: SIGILL: (*) illegal instruction (not reset when caught)
    si_errno [0]: Error 0
    si_code [30]: ILL_ILLOPC [addr: 0x0]

        stackpointer=2ff21b38
----------

As we do not want to debug the whole big application, we have written a
"hello world" example to simulate the process.
And surprisingly, we had the same situation. The small application
crashes with a similar message ("illegal instruction").

It seems, that AIX's shared library has problems with some std C++
calls (e.g. "cout"). Without a std C++ call, the application
works well. We tested this by commenting out the "cout" call.

As I have read some similar postings, I suppose that something
mysterious is going on when calling any std C++ library.

I have attached my small test program, which is a java application
using a native C++ shared library.

Here are some useful system information:

Processor type: PowerPC_POWER3
AIX OS version: 4.3.3.0
xl[cC] version: 5.0.2.0
Java version  : J2RE 1.3.0 IBM build

I hope receiving some very useful information in order to continue
supporting the AIX platform for our software.

Best regards and thanks in advance,
Bernhard Reitinger

ps: solutions can also go directly to my mail address !
___________________________________________________________________
Bernhard Reitinger, Software Engineer
Hyperwave Research & Development

___________________________________________________________________

Here the small "hello shared AIX world" code:

native.C
--------

#include "TestWrapper.h"
#include <iostream.h>

void Java_TestWrapper_test(JNIEnv *, jobject) {
  cout << "hello world";

Quote:}

TestWrapper.h (generated!)
--------------------------

/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class TestWrapper */

#ifndef _Included_TestWrapper
#define _Included_TestWrapper
#ifdef __cplusplus
extern "C" {
#endif
/*
 * Class:     TestWrapper
 * Method:    test
 * Signature: ()V
 */
JNIEXPORT void JNICALL Java_TestWrapper_test
  (JNIEnv *, jobject);

#ifdef __cplusplus

Quote:}

#endif
#endif

TestWrapper.java
----------------

class TestWrapper {
  public native void test();

Quote:}

TestShared.java
---------------

import java.lang.*;

class TestShared {

  public static void main(String[] args) {
    Runtime.getRuntime().load("/tmp/shared/libtst.so");
    TestWrapper w = new TestWrapper();
    w.test();
  }

Quote:}

Makefile
--------

all: native lib java

native: native.C
        xlC -I/usr/local/java/include -c native.C

lib: native.o
        ld -G -bnoentry -bexpall -o libtst.so native.o

java:
        javac TestWrapper.java
        javac TestShared.java

 
 
 

SHARED libraries on AIX

Post by A. Bolmarci » Thu, 13 Dec 2001 01:20:42



> Hello !

> In our development team, we are currently stucked. We are using
> shared libraries with java, and do have problems by using
> either gcc or xl[cC] compiler. Our application crashes as soon
> as we call some functions out of the shared library with
> the following message:

> ----------
> SIGILL 4 (*) illegal instruction (not reset when caught)
>     si_signo [4]: SIGILL: (*) illegal instruction (not reset when caught)
>     si_errno [0]: Error 0
>     si_code [30]: ILL_ILLOPC [addr: 0x0]

>         stackpointer=2ff21b38
> ----------

The C++ runtime is not being initialized.  In your small example (that
I've snipped from this followup), instead of building the shared object
file using the command

   ld -G -bnoentry -bexpall -o libtst.so native.o

use

   makeC++SharedLib -p 0 -o libtst.so native.o

The makeC++SharedLib command is part of C++ for AIX. It knows what has
to be done so the C++ runtime is initialized when the shared object
is loaded.  The makeC++SharedLib command should be used to build all
shared object files that include C++ object files.

 
 
 

SHARED libraries on AIX

Post by Gary R. Hoo » Fri, 14 Dec 2001 00:32:04



> The C++ runtime is not being initialized.

The C++ runtime isn't even being _referenced_.

Quote:> In your small example (that
> I've snipped from this followup), instead of building the shared object
> file using the command

>    ld -G -bnoentry -bexpall -o libtst.so native.o

> use

>    makeC++SharedLib -p 0 -o libtst.so native.o

A) C++-based shared modules are built with the above command, or
with xlC -qmkshrobj (VAC++ 5.x).  This is a requirement.

B) Using -G allows the linker to mark certain imported symbols as
resolved at runtime (i.e. those symbols that aren't found at link
time).  But the application must be built to enable runtime resolution,
and Java is most certainly _not_ enabled for that.  Therefore, using
-G for a module to be used by Java is probably not going to work.

C) On AIX, you always, _always link against known system libraries.
Our system libs contain both static and dynamic object code, and you're
going to need the static pieces linked into your executable module.
In the above example, you're missing libC, libc, and others.  The
suggestion solves this problem because the makeC++SharedLib command,
under the covers, properly includes -lC -lc -lm etc on the final
link command.

D) According to the ld documentation, -bexpall only exports symbols
that don't begin with an underscore.  This may not be adequate,
and therefore xlC -qmkshrobj may be preferred (it builds its own
export list for you).

--
Gary R. Hook / AIX PartnerWorld for Developers / These opinions are MINE
________________________________________________________________________

 
 
 

1. FORTRAN common in AIX shared library not shared at runtime (0/1)

We got following problem in accessing a FORTRAN Common within a
shared library.

The task is to put an FORTRAN common in a shared library and access
this common from:

a) routines which resides inside the shared library
b) routines statically linked to an executable which uses the shared
   library at runtime

At link time of the shared library we use the -bE: -bM:SRE and
-bnoentry flags. The export list used with the -bE: flag contains
the FORTRAN common to be shared. The problem at runtime is, it seems
as if the FORTRAN common is not shared between the routines in the
shared library and the routines in the executable.

I add an (already shortened) example which demonstrates the problem.
The example exists of:
                                              source        location
--------------------------------------------------------------------
FORTRAN common SLCOM                          sl_common.inc       SL
FORTRAN routine SL_BLOCKDATA initial. SLCOM   sl_blockdata.f      SL
FORTRAN routine PRINT_COM printing SLCOM      print_com.f         SL
C global variables STRING, STRUKTUR           sl_globals.h        SL
C routine print_glob printing C globals       print_glob.c        SL
FORTRAN routine PRINT_COM_LOC printing SLCOM  print_com_loc.f    EXE
C routine print_glob_loc printing C globals   print_glob_loc.c   EXE
C main() routine                              main.c             EXE

The main() routine just prints the contents of the FORTRAN common
and C globals via the corresponding shared library and "local"
print_XXX() routines. The resulting output demonstrates, that the C
globals are shared and the FORTRAN common is duplicated (watch the
printed memory addresses).

Has anybody else experienced this problem and solved it? We are
running AIX 4.1 on an IBM RS600 40S system.

Thanx Guenter.

P.S. Source code of the mentioned example is attached. You only have
to save all files in one directory and call make.

2. space on floppy disk

3. Will strip(debug shared library) == nodebug shared library ?

4. Processing one line at the time in a script...

5. Help with building shared libraries with dependencies on other shared libraries

6. Remote x client via SLIP

7. Question: Inclusion of shared libraries during linking of shared libraries

8. X-Win connectivity

9. Shared library loading shared library.

10. Need a Shared Library Guru: beyond simple shared library question

11. When is a shared library not a shared library?

12. Shared Libraries lose under AIX 3.1/X11R5

13. runtime error 0509-151, shared libraries, AIX 4.3, etc.