[Lldb-commits] [PATCH] D118494: [lldb] Observe SG_READ_ONLY flag in MachO binaries
Dave Lee via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Fri Jan 28 10:28:54 PST 2022
kastiglione created this revision.
kastiglione added reviewers: aprantl, augusto2112.
kastiglione requested review of this revision.
Herald added projects: LLDB, LLVM.
Herald added subscribers: llvm-commits, lldb-commits.
Change `Section::GetPermissions()` to indicate non-writability when the Mach-O
segment has the `SG_READ_ONLY` flag.
MachO has a segment flag named `SG_READ_ONLY` which indicates that the segment
is semantically read-only, even if its permissions are marked writable.
Segments such as `__DATA_CONST` contain data that is semantically "const", but
needs to be writable for dyld to perform fixups (bindings or rebases).
The header documentation for `SG_READ_ONLY` states:
> This segment is made read-only after fixups.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D118494
Files:
lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
llvm/include/llvm/BinaryFormat/MachO.h
Index: llvm/include/llvm/BinaryFormat/MachO.h
===================================================================
--- llvm/include/llvm/BinaryFormat/MachO.h
+++ llvm/include/llvm/BinaryFormat/MachO.h
@@ -106,6 +106,7 @@
SG_FVMLIB = 0x2u,
SG_NORELOC = 0x4u,
SG_PROTECTED_VERSION_1 = 0x8u,
+ SG_READ_ONLY = 0x10u,
// Constant masks for the "flags" field in llvm::MachO::section and
// llvm::MachO::section_64
Index: lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
===================================================================
--- lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -1433,7 +1433,7 @@
uint32_t result = 0;
if (seg_cmd.initprot & VM_PROT_READ)
result |= ePermissionsReadable;
- if (seg_cmd.initprot & VM_PROT_WRITE)
+ if ((seg_cmd.initprot & VM_PROT_WRITE) && !(seg_cmd.flags & SG_READ_ONLY))
result |= ePermissionsWritable;
if (seg_cmd.initprot & VM_PROT_EXECUTE)
result |= ePermissionsExecutable;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D118494.404086.patch
Type: text/x-patch
Size: 1043 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20220128/0a9b5ef8/attachment.bin>
More information about the lldb-commits
mailing list