[lldb] Run the LLDB test suite under MTE on capable Apple HW (#185780)

This PR adds support for running the LLDB test suite under MTE. It's
enabled by default on capable hardware when asserts are enabled. It
relies on a launcher (#185921) which launches the process with the
appropriate posix_spawn attribute. One thing worth noting here is that
child processes inherit the MTE property, so binaries launched by the
test suite in this mode also run under MTE.

Besides the logic to detect the default and thread through the launcher,
I also had to make a small change to LLVM LIT's `ToolSubst` class to
support an optional launcher for the shell tests.
This commit is contained in:
Jonas Devlieghere 2026-03-12 09:24:15 -07:00 committed by GitHub
parent e6e0e2b57e
commit 643969e780
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 43 additions and 1 deletions

View File

@ -163,6 +163,27 @@ if (LLDB_ENABLE_LIBEDIT)
set(CMAKE_EXTRA_INCLUDE_FILES)
endif()
if (APPLE)
set(default_enable_mte OFF)
execute_process(
COMMAND sysctl -n hw.optional.arm.FEAT_MTE4
OUTPUT_VARIABLE SYSCTL_OUTPUT
ERROR_QUIET
RESULT_VARIABLE SYSCTL_RESULT
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(SYSCTL_RESULT EQUAL 0)
set(default_enable_mte ON)
endif()
option(LLDB_ENABLE_MTE "Run the LLDB test suite with MTE enabled." ${default_enable_mte})
if (LLDB_ENABLE_MTE)
message(STATUS "Running the LLDB test suite with MTE")
endif()
endif()
if (LLDB_ENABLE_PYTHON)
if(CMAKE_SYSTEM_NAME MATCHES "Windows")
set(default_embed_python_home ON)

View File

@ -42,6 +42,7 @@ config.has_libcxx = @LLDB_HAS_LIBCXX@
config.libcxx_libs_dir = "@LIBCXX_LIBRARY_DIR@"
config.libcxx_include_dir = "@LIBCXX_GENERATED_INCLUDE_DIR@"
config.libcxx_include_target_dir = "@LIBCXX_GENERATED_INCLUDE_TARGET_DIR@"
config.lldb_launcher = "@LLDB_LAUNCHER@"
# The API tests use their own module caches.
config.lldb_module_cache = os.path.join("@LLDB_TEST_MODULE_CACHE_LLDB@", "lldb-api")
config.clang_module_cache = os.path.join("@LLDB_TEST_MODULE_CACHE_CLANG@", "lldb-api")

View File

@ -55,6 +55,10 @@ class LLDBTest(TestFormat):
# python exe as the first parameter of the command.
cmd = [executable] + self.dotest_cmd + [testPath, "-p", testFile]
launcher = getattr(test.config, "lldb_launcher", None)
if launcher:
cmd = [launcher] + cmd
if isLuaTest:
cmd.extend(["--env", "LUA_EXECUTABLE=%s" % test.config.lua_executable])
cmd.extend(["--env", "LLDB_LUA_CPATH=%s" % test.config.lldb_lua_cpath])

View File

@ -132,6 +132,11 @@ if(TARGET lldb-framework)
add_lldb_test_dependency(lldb-framework)
endif()
if(TARGET darwin-mte-launcher)
add_lldb_test_dependency(darwin-mte-launcher)
set(LLDB_LAUNCHER ${LLVM_RUNTIME_OUTPUT_INTDIR}/darwin-mte-launcher${CMAKE_EXECUTABLE_SUFFIX})
endif()
if (LLDB_CAN_USE_LLDB_RPC_SERVER)
add_lldb_test_dependency(lldb-rpc-generate-sources)
endif()

View File

@ -118,24 +118,28 @@ def use_lldb_substitutions(config):
build_script_args.append("--sysroot={0}".format(config.cmake_sysroot))
lldb_init = _get_lldb_init_path(config)
launcher = getattr(config, "lldb_launcher", None)
primary_tools = [
ToolSubst(
"%lldb",
command=FindTool("lldb"),
extra_args=get_lldb_args(config),
launcher=launcher,
unresolved="fatal",
),
ToolSubst(
"%lldb-init",
command=FindTool("lldb"),
extra_args=["-S", lldb_init],
launcher=launcher,
unresolved="fatal",
),
ToolSubst(
"%lldb-noinit",
command=FindTool("lldb"),
extra_args=["--no-lldbinit"],
launcher=launcher,
unresolved="fatal",
),
ToolSubst(

View File

@ -35,6 +35,7 @@ config.lldb_system_debugserver = @LLDB_USE_SYSTEM_DEBUGSERVER@
config.llvm_use_sanitizer = "@LLVM_USE_SANITIZER@"
config.lldb_has_lldbrpc = @LLDB_BUILD_LLDBRPC@
config.have_dia_sdk = @LLVM_ENABLE_DIA_SDK@
config.lldb_launcher = "@LLDB_LAUNCHER@"
# The shell tests use their own module caches.
config.lldb_module_cache = os.path.join("@LLDB_TEST_MODULE_CACHE_LLDB@", "lldb-shell")
config.clang_module_cache = os.path.join("@LLDB_TEST_MODULE_CACHE_CLANG@", "lldb-shell")

View File

@ -20,7 +20,9 @@ endif()
if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
add_lldb_tool_subdirectory(darwin-debug)
add_lldb_tool_subdirectory(darwin-mte-launcher)
if (LLDB_ENABLE_MTE)
add_lldb_tool_subdirectory(darwin-mte-launcher)
endif()
if(NOT LLDB_USE_SYSTEM_DEBUGSERVER)
add_lldb_tool_subdirectory(debugserver)
endif()

View File

@ -44,6 +44,7 @@ class ToolSubst(object):
verbatim=False,
unresolved="warn",
extra_args=None,
launcher=None,
):
"""Construct a ToolSubst.
@ -79,6 +80,7 @@ class ToolSubst(object):
"""
self.unresolved = unresolved
self.extra_args = extra_args
self.launcher = launcher
self.key = key
self.command = command if command is not None else FindTool(key)
self.was_resolved = False
@ -120,6 +122,8 @@ class ToolSubst(object):
if command_str:
if self.extra_args:
command_str = " ".join([command_str] + self.extra_args)
if self.launcher:
command_str = self.launcher + " " + command_str
else:
if self.unresolved == "warn":
# Warn, but still provide a substitution.