[lldb][ObjectFileELF] Set ModuleSpec file offset and size
In Android API level 23 and above, dynamic loader is able to load .so file directly from APK. https://android.googlesource.com/platform/bionic/+/master/ android-changes-for-ndk-developers.md# opening-shared-libraries-directly-from-an-apk ObjectFileELF::GetModuleSpecifications will load a .so file, which is page aligned and uncompressed, directly from a zip file. However it does not set the .so file offset and size to the ModuleSpec. Also crc32 calculation uses more data than the .so file size. Set the .so file offset and size to the ModuleSpec, and set the size to MapFileData length argument. For normal file, file_offset should be zero, and length should be the size of the file. Differential Revision: https://reviews.llvm.org/D152757
This commit is contained in:
committed by
Kazuki Sakamoto
parent
ebc757d3b6
commit
b0b9605a54
@@ -555,6 +555,14 @@ size_t ObjectFileELF::GetModuleSpecifications(
|
||||
if (header.Parse(data, &header_offset)) {
|
||||
if (data_sp) {
|
||||
ModuleSpec spec(file);
|
||||
// In Android API level 23 and above, bionic dynamic linker is able to
|
||||
// load .so file directly from zip file. In that case, .so file is
|
||||
// page aligned and uncompressed, and this module spec should retain the
|
||||
// .so file offset and file size to pass through the information from
|
||||
// lldb-server to LLDB. For normal file, file_offset should be 0,
|
||||
// length should be the size of the file.
|
||||
spec.SetObjectOffset(file_offset);
|
||||
spec.SetObjectSize(length);
|
||||
|
||||
const uint32_t sub_type = subTypeFromElfHeader(header);
|
||||
spec.GetArchitecture().SetArchitecture(
|
||||
@@ -586,8 +594,12 @@ size_t ObjectFileELF::GetModuleSpecifications(
|
||||
__FUNCTION__, file.GetPath().c_str());
|
||||
}
|
||||
|
||||
// When ELF file does not contain GNU build ID, the later code will
|
||||
// calculate CRC32 with this data_sp file_offset and length. It is
|
||||
// important for Android zip .so file, which is a slice of a file,
|
||||
// to not access the outside of the file slice range.
|
||||
if (data_sp->GetByteSize() < length)
|
||||
data_sp = MapFileData(file, -1, file_offset);
|
||||
data_sp = MapFileData(file, length, file_offset);
|
||||
if (data_sp)
|
||||
data.SetData(data_sp);
|
||||
// In case there is header extension in the section #0, the header we
|
||||
|
||||
Reference in New Issue
Block a user