diff --git a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp --- a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp +++ b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp @@ -555,6 +555,14 @@ 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 @@ __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 diff --git a/lldb/unittests/ObjectFile/ELF/CMakeLists.txt b/lldb/unittests/ObjectFile/ELF/CMakeLists.txt --- a/lldb/unittests/ObjectFile/ELF/CMakeLists.txt +++ b/lldb/unittests/ObjectFile/ELF/CMakeLists.txt @@ -11,5 +11,7 @@ set(test_inputs early-section-headers.so + liboffset-test.so + offset-test.bin ) add_unittest_inputs(ObjectFileELFTests "${test_inputs}") diff --git a/lldb/unittests/ObjectFile/ELF/Inputs/liboffset-test.so b/lldb/unittests/ObjectFile/ELF/Inputs/liboffset-test.so new file mode 100644 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 GIT binary patch literal 0 Hc$@