(Originally posted to -developers, but this seems to be more of an
-internals issue so reposting here. Slightly modifying for clarity.)
I'm trying to use JNI to load a library. However, I seem to have a
situation where System.loadLibrary() --- which I assume is calling
dlopen() behind the scenes --- is incorrectly applying relocations in
shared libraries. Here's some sample code:
---snip---
struct foo { int first, second };
struct foo Foo = {1, 2};
int* FooPtr[] = { &Foo.first, &Foo.second };
JNIEXPORT jint JNICALL Java_com_cowlark_CTest1
(JNIEnv* jenv, jclass clazz)
{
return *FooPtr[0];
}
JNIEXPORT jint JNICALL Java_com_cowlark_CTest2
(JNIEnv* jenv, jclass clazz)
{
return *FooPtr[1];
}
---snip---
When I run this, I'd expect CTest1() and CTest2() to return 1 and 2
respectively (and that's what I get if I plug it into a test harness on
the host). What I actually *get* is 1 and 1.
The linker produces (and I've verified manually that this is correct!)
the following relocation data for FooPtr:
00000000 00005102 R_ARM_ABS32 00000000 Foo
00000004 00005102 R_ARM_ABS32 00000000 Foo
This means 'add the address of Foo to the thing at offset 0 in the
.data.rel section' (twice). (FooPtr is at offset 0.) Since before
relocation the FooPtr array contains the offset from Foo of the
resulting address, that is, 0 and 4 respectively, once the relocation is
complete FooPtr will contain Foo+0 and Foo+4.
What I actually end up with if Foo+0 and Foo+0. That is, it appears to
be incorrectly discarding the offset.
I'm building this with the CodeSourcery arm-none-linux-gnueabi toolchain
using the custom .xsc file as described here:
http://honeypod.blogspot.com/2007/12/shared-library-hello-world-for-android.html
The linker command I'm using is:
arm-none-linux-gnueabi-ld -g -Os -fPIC --dynamic-linker
/system/bin/linker -nostdlib -rpath /system/lib -shared
-Tarmelf_linux_eabi.xsc -o obj/libFnord.so ...o files here...
Am I missing anything, or is there something wrong with dlopen()? I
can't *imagine* that if there were, someone wouldn't have stumbled over
it by now...
--
David Given
[EMAIL PROTECTED]
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Android Internals" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/android-internals?hl=en
-~----------~----~----~----~------~----~------~--~---