[lldb] When LLDB_ENABLE_MTE is ON always run the driver with MTE (#186322)

When LLDB_ENABLE_MTE is set to ON, we should always run the driver with
MTE by signing with the checked-allocations entitlement.
This commit is contained in:
Jonas Devlieghere
2026-03-16 11:11:58 -07:00
committed by GitHub
parent 769ffa0133
commit c5e5d5b282
4 changed files with 37 additions and 2 deletions

View File

@@ -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}"

View File

@@ -25,6 +25,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 +50,7 @@
#include <cstdlib>
#include <memory>
#include <optional>
#include <stdlib.h>
#include <string>
using namespace lldb;
@@ -289,6 +291,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(

View File

@@ -9,11 +9,23 @@ 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 we're building with assertions and LLDB_ENABLE_MTE is set to ON,
# build the driver to always run under MTE.
if (LLDB_ENABLE_MTE AND LLVM_ENABLE_ASSERTIONS)
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 +42,8 @@ add_lldb_tool(lldb
Driver.cpp
Platform.cpp
${ENTITLEMENTS}
LINK_COMPONENTS
Option
Support

View File

@@ -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>