[Lldb-commits] [lldb] [lldb] When LLDB_ENABLE_MTE is ON always run the driver with MTE (PR #186322)
via lldb-commits
lldb-commits at lists.llvm.org
Thu Mar 12 23:22:37 PDT 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-lldb
Author: Jonas Devlieghere (JDevlieghere)
<details>
<summary>Changes</summary>
When LLDB_ENABLE_MTE is set to ON, we should always run the driver with MTE by signing with the checked-allocations entitlement.
---
Full diff: https://github.com/llvm/llvm-project/pull/186322.diff
4 Files Affected:
- (modified) lldb/include/lldb/Host/Config.h.cmake (+2)
- (modified) lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp (+10)
- (modified) lldb/tools/driver/CMakeLists.txt (+14-2)
- (added) lldb/tools/driver/lldb-mte-entitlements.plist (+10)
``````````diff
diff --git a/lldb/include/lldb/Host/Config.h.cmake b/lldb/include/lldb/Host/Config.h.cmake
index f165d99830d8d..06ab9b9a7775c 100644
--- a/lldb/include/lldb/Host/Config.h.cmake
+++ b/lldb/include/lldb/Host/Config.h.cmake
@@ -51,6 +51,8 @@
#cmakedefine01 LLDB_ENABLE_TREESITTER
+#cmakedefine01 LLDB_ENABLE_MTE
+
#cmakedefine LLDB_PYTHON_HOME R"(${LLDB_PYTHON_HOME})"
#define LLDB_INSTALL_LIBDIR_BASENAME "${LLDB_INSTALL_LIBDIR_BASENAME}"
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
index de8be43aa35fd..42f6f0748f82a 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -1,3 +1,4 @@
+
//===-- ScriptInterpreterPython.cpp ---------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
@@ -25,6 +26,7 @@
#include "lldb/Core/PluginManager.h"
#include "lldb/Core/ThreadedCommunication.h"
#include "lldb/DataFormatters/TypeSummary.h"
+#include "lldb/Host/Config.h"
#include "lldb/Host/FileSystem.h"
#include "lldb/Host/HostInfo.h"
#include "lldb/Host/Pipe.h"
@@ -49,6 +51,7 @@
#include <cstdlib>
#include <memory>
#include <optional>
+#include <stdlib.h>
#include <string>
using namespace lldb;
@@ -289,6 +292,13 @@ llvm::StringRef ScriptInterpreterPython::GetPluginDescriptionStatic() {
}
void ScriptInterpreterPython::Initialize() {
+#if LLDB_ENABLE_MTE
+ // Python's allocator (pymalloc) is not aware of Memory Tagging Extension
+ // (MTE) and crashes.
+ // https://bugs.python.org/issue43593
+ setenv("PYTHONMALLOC", "malloc", /*overwrite=*/true);
+#endif
+
HostInfo::SetSharedLibraryDirectoryHelper(
ScriptInterpreterPython::SharedLibraryDirectoryHelper);
PluginManager::RegisterPlugin(
diff --git a/lldb/tools/driver/CMakeLists.txt b/lldb/tools/driver/CMakeLists.txt
index 7043f648518d6..0500d01e9df34 100644
--- a/lldb/tools/driver/CMakeLists.txt
+++ b/lldb/tools/driver/CMakeLists.txt
@@ -9,11 +9,21 @@ if(APPLE)
)
# Inline info plist in binary (use target_link_options for this as soon as CMake 3.13 is available)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-sectcreate,__TEXT,__info_plist,${CMAKE_CURRENT_BINARY_DIR}/lldb-Info.plist")
+
+ if(LLDB_CODESIGN_IDENTITY)
+ set(LLVM_CODESIGNING_IDENTITY ${LLDB_CODESIGN_IDENTITY})
+ elseif(NOT LLVM_CODESIGNING_IDENTITY)
+ set(LLVM_CODESIGNING_IDENTITY "-")
+ endif()
+
+ if (LLDB_ENABLE_MTE)
+ set(ENTITLEMENTS ENTITLEMENTS ${CMAKE_CURRENT_SOURCE_DIR}/lldb-mte-entitlements.plist)
+ endif()
endif()
if (UNIX AND "${CMAKE_SYSTEM_NAME}" MATCHES "AIX")
- remove_definitions("-D_XOPEN_SOURCE=700")
- add_definitions("-D_ALL_SOURCE")
+ remove_definitions("-D_XOPEN_SOURCE=700")
+ add_definitions("-D_ALL_SOURCE")
endif()
set(LLDB_DRIVER_LINK_LIBS
@@ -30,6 +40,8 @@ add_lldb_tool(lldb
Driver.cpp
Platform.cpp
+ ${ENTITLEMENTS}
+
LINK_COMPONENTS
Option
Support
diff --git a/lldb/tools/driver/lldb-mte-entitlements.plist b/lldb/tools/driver/lldb-mte-entitlements.plist
new file mode 100644
index 0000000000000..7ab4dd621bd53
--- /dev/null
+++ b/lldb/tools/driver/lldb-mte-entitlements.plist
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>com.apple.developer.hardened-process</key>
+ <true/>
+ <key>com.apple.developer.hardened-process.checked-allocations</key>
+ <true/>
+</dict>
+</plist>
``````````
</details>
https://github.com/llvm/llvm-project/pull/186322
More information about the lldb-commits
mailing list