United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-7152237 Linking with Java 7 libjvm.so on Linux reports unrecognized file format
JDK-7152237 : Linking with Java 7 libjvm.so on Linux reports unrecognized file format

Details
Type:
Bug
Submit Date:
2012-03-08
Status:
Closed
Updated Date:
2012-06-15
Project Name:
JDK
Resolved Date:
2012-06-15
Component:
hotspot
OS:
linux_suse_sles_10
Sub-Component:
build
CPU:
x86
Priority:
P3
Resolution:
Cannot Reproduce
Affected Versions:
7
Fixed Versions:

Related Reports

Sub Tasks

Description
FULL PRODUCT VERSION :
java version "1.7.0_02"
Java(TM) SE Runtime Environment (build 1.7.0_02-b13)
Java HotSpot(TM) 64-Bit Server VM (build 22.0-b10, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
Linux svla6058 2.6.16.60-0.21-smp #1 SMP Tue May 6 12:41:02 UTC 2008 x86_64 x86_64 x86_64 GNU/Linux


A DESCRIPTION OF THE PROBLEM :
Check file type - looks okay:
file /tc_work/dsd/testjdk7/jdk1.7.0_02/jre/lib/amd64/server/libjvm.so
/tc_work/dsd/testjdk7/jdk1.7.0_02/jre/lib/amd64/server/libjvm.so: ELF 64-bit LSB shared object, AMD x86-64, version 1 (SYSV), not stripped

Compile and link a simple test program:
g++ -fPIC -I/tc_work/dsd/testjdk7/jdk1.7.0_02/include -I/tc_work/dsd/testjdk7/jdk1.7.0_02/include/linux -c testjdk.c

g++ -L/tc_work/dsd/testjdk7/jdk1.7.0_02/jre/lib/amd64/server -ljvm testjdk.o -o testjdk
/tc_work/dsd/testjdk7/jdk1.7.0_02/jre/lib/amd64/server/libjvm.so: file not recognized: File format not recognized
collect2: ld returned 1 exit status

Seems like the libjvm.so and other shared libraries in the distributions are not really compatible with SLES10sp2.

Same program and test works fine with SLES11.


REGRESSION.  Last worked in version 6u29

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Attempt to link with libjvm.so on SLES10sp2.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
According to this it looks like Java 7 SLES10sp2 should be supported.
http://www.oracle.com/technetwork/java/javase/config-417990.html
ACTUAL -
jdk1.7.0_02/jre/lib/amd64/server/libjvm.so: file not recognized: File format not recognized

ERROR MESSAGES/STACK TRACES THAT OCCUR :
jdk1.7.0_02/jre/lib/amd64/server/libjvm.so: file not recognized: File format not recognized

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------

testjdk.c:

#include <jni.h>
#include <iostream>

int main(int argc, char *argv[])
{  
    char optionStr[] = "-Djava.class.path=./build/java"; //Path to the java source code

    JavaVM *jvm;
    JNIEnv *env;
    JavaVMInitArgs vm_args;
    JavaVMOption options[1];
    options[0].optionString = optionStr;
    vm_args.version = JNI_VERSION_1_2;
    vm_args.nOptions = 1;
    vm_args.options = options;
    vm_args.ignoreUnrecognized = 0;

    jint ret = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);
    std::cout << "JNI_CreateJavaVM returned " << ret << std::endl;

    return 0;
} 

Makefile:
MYJDK = /tc_work/dsd/testjdk7/jdk1.7.0_02

testjdk.o: testjdk.c
        g++ -fPIC -I$(MYJDK)/include -I$(MYJDK)/include/linux -c testjdk.c

testjdk: testjdk.o
        file $(MYJDK)/jre/lib/amd64/server/libjvm.so
        g++ -L$(MYJDK)/jre/lib/amd64/server -ljvm testjdk.o -o testjdk

run: testjdk
        export LD_LIBRARY_PATH=${MYJDK}/jre/lib/amd64/server; ./testjdk

clean:
        rm -fr testjdk testjdk.o


---------- END SOURCE ----------

                                    

Comments
EVALUATION

Initial evaluation started, looking for SLES10sp2 machine to verify issue on.
                                     
2012-03-09
EVALUATION

I was able to reproduce the problem as described on all of JDK7 releases (7, 7u2 and 7u4) and like the report says this works on 6u29.
                                     
2012-03-13
PUBLIC COMMENTS

If this works on SLES11 but not SLES10sp2 then that would indicate an issue with the OS or more likely with the version of the tools (g++ etc) used on each OS. It might also be related to SELInux.

If this works with 6u29 but not 7 then I think the most likely issue is the use of -fPIC as there have been some changes regarding how the VM is built. Can the submitter try compiling without using -fPIC?

Can the submitter also try gcc instead of g++ ?

For the record when I try the instructions given I get the following link error:

testjvm.o: In function `main':
testjvm.c:(.text+0x97): undefined reference to `JNI_CreateJavaVM'
collect2: ld returned 1 exit status
                                     
2012-03-14
EVALUATION

If this works on SLES11 but not SLES10sp2 then that would indicate an issue with the OS or more likely with the version of the tools (g++ etc) used on each OS. It might also be related to SELInux.

If this works with 6u29 but not 7 then I think the most likely issue is the use of -fPIC as there have been some changes regarding how the VM is built. Can the submitter try compiling without using -fPIC?

Can the submitter also try gcc instead of g++ ?

For the record when I try the instructions given I get the following link error:

testjvm.o: In function `main':
testjvm.c:(.text+0x97): undefined reference to `JNI_CreateJavaVM'
collect2: ld returned 1 exit status
                                     
2012-06-15



Hardware and Software, Engineered to Work Together