Horatio Chien
2018-03-20 09:57:43 UTC
Hi all,
My native app is getting dlopen failure problem on Nexus 5P (updated to
8.1.0. 2018.03.05).
Previously, this native app is built with NDK r11c, NDK API level 21. It
runs well.
Now, I build it with NDK r16b, NDK API level 27, then I got the problem.
My native app works in this way:
com.example.MyTestHost is my native app.
libComponentTest.so is another shared library compiled by me. I use "adb
push" to copy this file into somewhere of the sdcard of my phone.
Both above items are compiled with NDK r16b, NDK API level 27, arm64-v8a.
In runtime, my app will copy libComponentTest.so into its app folder
(/data/data/com.example.MyTestHost).
And then, my app will try to load libComponentTest.so via dlopen().
// path is the absolute path of the copied libComponentTest.so, i.e.
/data/data/com.example.MyTestHost/files/libComponentTest.so.
*void* test_dll = dlopen( path.c_str(), RTLD_NOW | RTLD_GLOBAL );*
I used the following command to enable logging:
*setprop debug.ld.app.com.example.MyTestHost dlerror,dlopen,dlsym*
I got:
D linker :
dlopen(name="/data/user/0/com.example.MyTestHost/files/libComponentTest.so",
flags=0x102, extinfo=(null),
caller="/data/app/com.example.MyTestHost-jBAzGe6Sr2-0jtNt2FWaTA==/lib/arm64/libMyTestHost.so",
caller_ns=classloader-***@0x7f7be3b090) ...
E linker : "/data/data/com.example.MyTestHost/files/libComponentTest.so"
has invalid shdr offset/size: 151360128/2304
I checked the ELF header of libComponentTest.so. It shows:
ELF Header:
Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
Class: ELF64
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: DYN (Shared object file)
Machine: AArch64
Version: 0x1
Entry point address: 0x133610
Start of program headers: 64 (bytes into file)
* Start of section headers: 151360128 (bytes into file)*
Flags: 0x0
Size of this header: 64 (bytes)
Size of program headers: 56 (bytes)
Number of program headers: 7
* Size of section headers: 64 (bytes)*
* Number of section headers: 36*
Section header string table index: 33
The file size of libComponentTest.so is 151362432 bytes.
P.S. 151362432 is indeed equal to 151360128 + 2304. And 2304 = 64 * 36.
I also glanced over the source code of linker_phdr.cpp
<https://android.googlesource.com/platform/bionic/+/master/linker/linker_phdr.cpp>
.
I also checked the alignment size of the section header. It is 8 as
expected.
size_t alignSize = alignof(const ElfW(Shdr));
I don't understand why CheckFileRange() is failing.
It seems that 'file_offset_ or' 'file_size_' is not correct. How can I
debug/resolve this problem?
Thank you.
My native app is getting dlopen failure problem on Nexus 5P (updated to
8.1.0. 2018.03.05).
Previously, this native app is built with NDK r11c, NDK API level 21. It
runs well.
Now, I build it with NDK r16b, NDK API level 27, then I got the problem.
My native app works in this way:
com.example.MyTestHost is my native app.
libComponentTest.so is another shared library compiled by me. I use "adb
push" to copy this file into somewhere of the sdcard of my phone.
Both above items are compiled with NDK r16b, NDK API level 27, arm64-v8a.
In runtime, my app will copy libComponentTest.so into its app folder
(/data/data/com.example.MyTestHost).
And then, my app will try to load libComponentTest.so via dlopen().
// path is the absolute path of the copied libComponentTest.so, i.e.
/data/data/com.example.MyTestHost/files/libComponentTest.so.
*void* test_dll = dlopen( path.c_str(), RTLD_NOW | RTLD_GLOBAL );*
I used the following command to enable logging:
*setprop debug.ld.app.com.example.MyTestHost dlerror,dlopen,dlsym*
I got:
D linker :
dlopen(name="/data/user/0/com.example.MyTestHost/files/libComponentTest.so",
flags=0x102, extinfo=(null),
caller="/data/app/com.example.MyTestHost-jBAzGe6Sr2-0jtNt2FWaTA==/lib/arm64/libMyTestHost.so",
caller_ns=classloader-***@0x7f7be3b090) ...
E linker : "/data/data/com.example.MyTestHost/files/libComponentTest.so"
has invalid shdr offset/size: 151360128/2304
I checked the ELF header of libComponentTest.so. It shows:
ELF Header:
Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
Class: ELF64
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: DYN (Shared object file)
Machine: AArch64
Version: 0x1
Entry point address: 0x133610
Start of program headers: 64 (bytes into file)
* Start of section headers: 151360128 (bytes into file)*
Flags: 0x0
Size of this header: 64 (bytes)
Size of program headers: 56 (bytes)
Number of program headers: 7
* Size of section headers: 64 (bytes)*
* Number of section headers: 36*
Section header string table index: 33
The file size of libComponentTest.so is 151362432 bytes.
P.S. 151362432 is indeed equal to 151360128 + 2304. And 2304 = 64 * 36.
I also glanced over the source code of linker_phdr.cpp
<https://android.googlesource.com/platform/bionic/+/master/linker/linker_phdr.cpp>
.
I also checked the alignment size of the section header. It is 8 as
expected.
size_t alignSize = alignof(const ElfW(Shdr));
I don't understand why CheckFileRange() is failing.
It seems that 'file_offset_ or' 'file_size_' is not correct. How can I
debug/resolve this problem?
Thank you.
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+***@googlegroups.com.
To post to this group, send email to android-***@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/259ded7f-1621-4cc4-bad5-79da81c4cb94%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+***@googlegroups.com.
To post to this group, send email to android-***@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/259ded7f-1621-4cc4-bad5-79da81c4cb94%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.