[Lldb-commits] [PATCH] D122856: [lldb] Refactor DataBuffer so we can map files as read-only

Jonas Devlieghere via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Thu Mar 31 18:09:30 PDT 2022


JDevlieghere created this revision.
JDevlieghere added reviewers: labath, jasonmolenda, clayborg.
Herald added subscribers: pmatos, asb, atanasyan, jrtc27, kbarton, sbc100, nemanjai, sdardis, emaste.
Herald added a project: All.
JDevlieghere requested review of this revision.
Herald added subscribers: MaskRay, aheejin.

Currently, all data buffers are assumed to be writable. This is a problem on macOS where it's not allowed to load unsigned binaries in memory as writable. To be more precise, `MAP_RESILIENT_CODESIGN` and `MAP_RESILIENT_MEDIA` need to be set for mapped (unsigned) binaries on our platform.

Binaries are loaded through `FileSystem::CreateDataBuffer` which returns a DataBufferLLVM. The latter is backed by a `llvm::WritableMemoryBuffer` because every DataBuffer is considered to be writable. In order to use a read-only `llvm::MemoryBuffer` I had to split `DataBuffer` into `DataBuffer` (read-only) and `WritableDataBuffer` (read-write).

Differentiating between read-only and read-write buffers worked out everywhere except for ObjectFileELF. The latter calls `GetSharedDataBuffer` on the `DataExtractor` and applies relocations in place. I understand the purpose of making this copy on write for just the affected pages, but I'm not sure how to make this work with the new approach:

- Copying the whole object file to the heap when we need to apply the relocations is probably too expensive.
- We could try to re-map the file but then we'd need to (1) know that it's a DataBufferLLVM and (2) have a way to remap the whole file a writable.

I've ifdef'd out the code to show where the issue is.

rdar://74890607


https://reviews.llvm.org/D122856

Files:
  lldb/include/lldb/Core/ValueObject.h
  lldb/include/lldb/Host/FileSystem.h
  lldb/include/lldb/Symbol/CompactUnwindInfo.h
  lldb/include/lldb/Target/ProcessStructReader.h
  lldb/include/lldb/Target/RegisterCheckpoint.h
  lldb/include/lldb/Target/RegisterContext.h
  lldb/include/lldb/Target/RegisterContextUnwind.h
  lldb/include/lldb/Utility/DataBuffer.h
  lldb/include/lldb/Utility/DataBufferHeap.h
  lldb/include/lldb/Utility/DataBufferLLVM.h
  lldb/include/lldb/lldb-forward.h
  lldb/source/Commands/CommandObjectMemory.cpp
  lldb/source/Core/SourceManager.cpp
  lldb/source/Core/ValueObject.cpp
  lldb/source/DataFormatters/StringPrinter.cpp
  lldb/source/Expression/IRExecutionUnit.cpp
  lldb/source/Host/common/FileSystem.cpp
  lldb/source/Host/common/Host.cpp
  lldb/source/Plugins/ABI/ARM/ABISysV_arm.cpp
  lldb/source/Plugins/ABI/Mips/ABISysV_mips.cpp
  lldb/source/Plugins/ABI/Mips/ABISysV_mips64.cpp
  lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc.cpp
  lldb/source/Plugins/ABI/X86/ABISysV_x86_64.cpp
  lldb/source/Plugins/ABI/X86/ABIWindows_x86_64.cpp
  lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
  lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
  lldb/source/Plugins/Language/CPlusPlus/LibCxxVector.cpp
  lldb/source/Plugins/Language/ObjC/CF.cpp
  lldb/source/Plugins/Language/ObjC/NSDictionary.cpp
  lldb/source/Plugins/Language/ObjC/NSSet.cpp
  lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp
  lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp
  lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
  lldb/source/Plugins/ObjectFile/wasm/ObjectFileWasm.cpp
  lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
  lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm.cpp
  lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm.h
  lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm64.cpp
  lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm64.h
  lldb/source/Plugins/Process/Utility/RegisterContextDarwin_i386.cpp
  lldb/source/Plugins/Process/Utility/RegisterContextDarwin_i386.h
  lldb/source/Plugins/Process/Utility/RegisterContextDarwin_x86_64.cpp
  lldb/source/Plugins/Process/Utility/RegisterContextDarwin_x86_64.h
  lldb/source/Plugins/Process/Utility/RegisterContextDummy.cpp
  lldb/source/Plugins/Process/Utility/RegisterContextDummy.h
  lldb/source/Plugins/Process/Utility/RegisterContextHistory.cpp
  lldb/source/Plugins/Process/Utility/RegisterContextHistory.h
  lldb/source/Plugins/Process/Utility/RegisterContextMemory.cpp
  lldb/source/Plugins/Process/Utility/RegisterContextMemory.h
  lldb/source/Plugins/Process/Utility/RegisterContextThreadMemory.cpp
  lldb/source/Plugins/Process/Utility/RegisterContextThreadMemory.h
  lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_arm.cpp
  lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_arm.h
  lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_arm64.cpp
  lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_arm64.h
  lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_mips64.cpp
  lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_mips64.h
  lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_powerpc.cpp
  lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_powerpc.h
  lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_s390x.cpp
  lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_s390x.h
  lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_x86_64.cpp
  lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_x86_64.h
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.h
  lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
  lldb/source/Plugins/Process/minidump/RegisterContextMinidump_x86_32.cpp
  lldb/source/Plugins/Process/minidump/RegisterContextMinidump_x86_64.cpp
  lldb/source/Target/Platform.cpp
  lldb/source/Target/RegisterContextUnwind.cpp
  lldb/source/Utility/DataBufferHeap.cpp
  lldb/source/Utility/DataBufferLLVM.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D122856.419593.patch
Type: text/x-patch
Size: 62485 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20220401/c01ae2ec/attachment-0001.bin>


More information about the lldb-commits mailing list