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;
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;
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits