tberghammer created this revision. Map ELF files as writable so we can update the relocations in them
After this change ELF files will be mapped as private writable pages so we can cheaply update the relocations inside them without have to read them into memory and any modification we do in the memory will not be reflected in the on disk files. https://reviews.llvm.org/D30251 Files: include/lldb/Host/FileSpec.h source/Host/common/FileSpec.cpp source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
Index: source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp =================================================================== --- source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp +++ source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp @@ -386,7 +386,7 @@ lldb::offset_t file_offset, lldb::offset_t length) { if (!data_sp) { - data_sp = file->MemoryMapFileContentsIfLocal(file_offset, length); + data_sp = file->MemoryMapFileContentsIfLocal(file_offset, length, true); data_offset = 0; } @@ -396,7 +396,7 @@ if (ELFHeader::MagicBytesMatch(magic)) { // Update the data to contain the entire file if it doesn't already if (data_sp->GetByteSize() < length) { - data_sp = file->MemoryMapFileContentsIfLocal(file_offset, length); + data_sp = file->MemoryMapFileContentsIfLocal(file_offset, length, true); data_offset = 0; magic = data_sp->GetBytes(); } @@ -654,7 +654,8 @@ if (header.HasHeaderExtension() && section_header_end > data_sp->GetByteSize()) { data_sp = file.MemoryMapFileContentsIfLocal (file_offset, - section_header_end); + section_header_end, + true); data.SetData(data_sp); lldb::offset_t header_offset = data_offset; header.Parse(data, &header_offset); @@ -667,7 +668,8 @@ header.e_shoff + header.e_shnum * header.e_shentsize; if (section_header_end > data_sp->GetByteSize()) { data_sp = file.MemoryMapFileContentsIfLocal(file_offset, - section_header_end); + section_header_end, + true); data.SetData(data_sp); } @@ -712,7 +714,7 @@ header.e_phoff + header.e_phnum * header.e_phentsize; if (program_headers_end > data_sp->GetByteSize()) { data_sp = file.MemoryMapFileContentsIfLocal( - file_offset, program_headers_end); + file_offset, program_headers_end, true); data.SetData(data_sp); } ProgramHeaderColl program_headers; @@ -727,16 +729,19 @@ if (segment_data_end > data_sp->GetByteSize()) { data_sp = file.MemoryMapFileContentsIfLocal(file_offset, - segment_data_end); + segment_data_end, + true); data.SetData(data_sp); } core_notes_crc = CalculateELFNotesSegmentsCRC32(program_headers, data); } else { // Need to map entire file into memory to calculate the crc. data_sp = - file.MemoryMapFileContentsIfLocal(file_offset, SIZE_MAX); + file.MemoryMapFileContentsIfLocal(file_offset, + SIZE_MAX, + true); data.SetData(data_sp); gnu_debuglink_crc = calc_gnu_debuglink_crc32( data.GetDataStart(), data.GetByteSize()); Index: source/Host/common/FileSpec.cpp =================================================================== --- source/Host/common/FileSpec.cpp +++ source/Host/common/FileSpec.cpp @@ -837,23 +837,28 @@ // verified using the DataBuffer::GetByteSize() function. //------------------------------------------------------------------ DataBufferSP FileSpec::MemoryMapFileContents(off_t file_offset, - size_t file_size) const { + size_t file_size, + bool writeable) const { DataBufferSP data_sp; std::unique_ptr<DataBufferMemoryMap> mmap_data(new DataBufferMemoryMap()); if (mmap_data.get()) { const size_t mapped_length = - mmap_data->MemoryMapFromFileSpec(this, file_offset, file_size); + mmap_data->MemoryMapFromFileSpec(this, + file_offset, + file_size, + writeable); if (((file_size == SIZE_MAX) && (mapped_length > 0)) || (mapped_length >= file_size)) data_sp.reset(mmap_data.release()); } return data_sp; } DataBufferSP FileSpec::MemoryMapFileContentsIfLocal(off_t file_offset, - size_t file_size) const { + size_t file_size, + bool writeable) const { if (FileSystem::IsLocal(*this)) - return MemoryMapFileContents(file_offset, file_size); + return MemoryMapFileContents(file_offset, file_size, writeable); else return ReadFileContents(file_offset, file_size, NULL); } Index: include/lldb/Host/FileSpec.h =================================================================== --- include/lldb/Host/FileSpec.h +++ include/lldb/Host/FileSpec.h @@ -527,7 +527,8 @@ /// pointer must be checked prior to using it. //------------------------------------------------------------------ lldb::DataBufferSP MemoryMapFileContents(off_t offset = 0, - size_t length = SIZE_MAX) const; + size_t length = SIZE_MAX, + bool writeable = false) const; //------------------------------------------------------------------ /// Memory map part of, or the entire contents of, a file only if @@ -565,7 +566,8 @@ /// pointer must be checked prior to using it. //------------------------------------------------------------------ lldb::DataBufferSP MemoryMapFileContentsIfLocal(off_t file_offset, - size_t file_size) const; + size_t file_size, + bool writeable = false) const; //------------------------------------------------------------------ /// Read part of, or the entire contents of, a file into a heap based data
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits