IBM J9 JVM 1.6中的某些更改(超过1.5)会导致我们遇到的链接错误,从而导致运行时异常。具体来说,我们使用JNI加载一个共享库,该库包含以下代码的对象文件:
extern _edata;
extern _etext;
extern _end;
这些是内存子系统中使用的地址,应该由链接器提供。然而,当我们编译共享库时,AIX链接器并没有链接它们(但是,如果您生成可执行文件,它会正确链接)。
JNI错误消息:
java.lang.UnsatisfiedLinkError: oas-jni (rtld: 0712-001 Symbol _edata was referenced
from module /usr/IBM/blackbird/lib/liboas-jni.so(), but a runtime definition of the symbol was not found.
rtld: 0712-001 Symbol _etext was referenced from module /usr/IBM/blackbird/lib/liboas-jni.so(), but a runtime definition of the symbol was not found.
rtld: 0712-001 Symbol _end was referenced from module /usr/IBM/blackbird/lib/liboas-jni.so(), but a runtime definition of the symbol was not found.
rtld: 0712-002 fatal error: ex)
at java.lang.ClassLoader.loadLibraryWithPath(ClassLoader.java:1035)
at java.lang.ClassLoader.loadLibraryWithClassLoader(ClassLoader.java:999)
at java.lang.System.loadLibrary(System.java:507)
at com.integrasolv.owl.oas.OAS_Init.<clinit>(OAS_Init.java:16)
at java.lang.J9VMInternals.initializeImpl(Native Method)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:201)
at com.integrasolv.owl.oas.OAS_Agent.<clinit>(OAS_Agent.java:87)
at java.lang.J9VMInternals.initializeImpl(Native Method)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:201)
at blackbird.testclient.TestClient.initOwlProcesses(TestClient.java:120)
at blackbird.testclient.TestClient.main(TestClient.java:75)
Exception in thread "main" java.lang.UnsatisfiedLinkError: com/integrasolv/owl/oas/OAS_Agent.setEnv(Ljava/lang/String;Ljava/lang/String;)V
at blackbird.testclient.TestClient.initOwlProcesses(TestClient.java:120)
at blackbird.testclient.TestClient.main(TestClient.java:75)
裸骨测试文件:
// test.c
#include <stdio.h>
#include <stdlib.h>
extern char _etext, _edata, _end;
int runtest() {
printf("First address past:n");
printf(" program text (etext) %10pn", &_etext);
printf(" initialized data (edata) %10pn", &_edata);
printf(" uninitialized data (end) %10pn", &_end);
exit(EXIT_SUCCESS);
}
编译对象文件而不链接
$ gcc -c test.c
从test.o创建共享库
$ gcc -shared -Wl,-G -o libtest.a test.c
请注意,-G包含链接器的-berok选项,忽略错误。否则,我们将在此处看到_etext、_edata和_end的一些未定义符号错误
从共享库转储符号表
$ dump -Tv libtest.a
libtest.a:
***Loader Section***
***Loader Symbol Table Information***
[Index] Value Scn IMEX Sclass Type IMPid Name
[0] 0x200006e4 .data RW SECdef [noIMid] __rtinit
[1] 0x00000000 undef IMP DS EXTref libgcc_s.a(shr.o) __cxa_finalize
[2] 0x00000000 undef IMP DS EXTref libc.a(shr.o) exit
[3] 0x00000000 undef IMP DS EXTref libc.a(shr.o) printf
[4] 0x00000000 undef IMP DS EXTref libc.a(shr.o) strtod
[5] 0x00000000 undef IMP DS EXTref libc.a(shr.o) __fd_select
[6] 0x00000000 undef IMP DS EXTref libc.a(shr.o) puts
[7] 0x00000000 undef IMP DS EXTref libc.a(shr.o) __strtollmax
[8] 0x200006d0 .data EXP RW Ldef [noIMid] __dso_handle
[9] 0x20000750 .data EXP DS Ldef [noIMid] __init_aix_libgcc_cxa_atexit
[10] 0x20000780 .data EXP DS Ldef [noIMid] runtest
[11] 0x00000000 undef IMP PR EXTref .. _etext
[12] 0x00000000 undef IMP PR EXTref .. _edata
[13] 0x00000000 undef IMP PR EXTref .. _end
nm输出:
$ nm libtest.a|grep _e
_edata U -
_edata d 536872908 4
_end U -
_end d 536872916 4
_etext U -
_etext d 536872900 4
我不完全清楚这里发生了什么。在linux上,这很好用。在GNU/Linux 上的相同测试上输出nm命令
0000000000201040 D _edata
0000000000201048 B _end
000000000000082d T _etext
主程序(例如/usr/java*/jre/bin/java)应该导出这些符号(链接选项-Wl,-bE:esyms.sym
#! .
_etext
_edata
_end
您可以检查您的java是否导出这些符号:
dump -Tv -X32_64 /usr/java*/jre/bin/java | grep _etext