From 9ba66937c8fc960e1472847c4939616389166f99 Mon Sep 17 00:00:00 2001 From: Geoffrey Thomas Date: Thu, 6 Nov 2025 15:10:30 -0500 Subject: [PATCH 1/2] Add an ASan build --- ci-targets.yaml | 1 + cpython-unix/build-main.py | 2 +- cpython-unix/build.py | 15 +++++++++------ 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/ci-targets.yaml b/ci-targets.yaml index 10a13206a..38468bec8 100644 --- a/ci-targets.yaml +++ b/ci-targets.yaml @@ -188,6 +188,7 @@ linux: - options: - freethreaded+debug - freethreaded+pgo+lto + - pgo+lto+asan minimum-python-version: "3.13" run: true diff --git a/cpython-unix/build-main.py b/cpython-unix/build-main.py index 366ec8cfa..23bce6ef5 100755 --- a/cpython-unix/build-main.py +++ b/cpython-unix/build-main.py @@ -43,7 +43,7 @@ def main(): # Construct possible options, we use a set here for canonical ordering options = set() - options.update({"debug", "noopt", "pgo", "lto", "pgo+lto"}) + options.update({"debug", "noopt", "pgo", "lto", "pgo+lto", "pgo+lto+asan"}) options.update({f"freethreaded+{option}" for option in options}) options.update({f"{option}+static" for option in options}) parser.add_argument( diff --git a/cpython-unix/build.py b/cpython-unix/build.py index 23d946024..fedddfc69 100755 --- a/cpython-unix/build.py +++ b/cpython-unix/build.py @@ -64,7 +64,7 @@ MACOS_ALLOW_FRAMEWORKS = {"CoreFoundation"} -def add_target_env(env, build_platform, target_triple, build_env): +def add_target_env(env, build_platform, target_triple, build_env, build_options): add_env_common(env) settings = get_target_settings(TARGETS_CONFIG, target_triple) @@ -93,6 +93,9 @@ def add_target_env(env, build_platform, target_triple, build_env): extra_target_cflags.append("--rtlib=compiler-rt") extra_target_ldflags.append("--rtlib=compiler-rt") + if "asan" in build_options: + extra_target_cflags.append("-fsanitize=address") + if build_platform.startswith("linux_"): machine = platform.machine() @@ -272,7 +275,7 @@ def simple_build( if "static" in build_options: env["STATIC"] = 1 - add_target_env(env, host_platform, target_triple, build_env) + add_target_env(env, host_platform, target_triple, build_env, build_options) # for OpenSSL, set the OPENSSL_TARGET environment variable if entry.startswith("openssl-"): @@ -379,7 +382,7 @@ def build_libedit( "LIBEDIT_VERSION": DOWNLOADS["libedit"]["version"], } - add_target_env(env, host_platform, target_triple, build_env) + add_target_env(env, host_platform, target_triple, build_env, build_options) build_env.run("build-libedit.sh", environment=env) build_env.get_tools_archive(dest_archive, "deps") @@ -440,7 +443,7 @@ def build_cpython_host( "PYTHON_VERSION": python_version, } - add_target_env(env, host_platform, target_triple, build_env) + add_target_env(env, host_platform, target_triple, build_env, build_options) # Set environment variables allowing convenient testing for Python # version ranges. @@ -837,7 +840,7 @@ def build_cpython( if "static" in parsed_build_options: env["CPYTHON_STATIC"] = "1" - add_target_env(env, host_platform, target_triple, build_env) + add_target_env(env, host_platform, target_triple, build_env, build_options) build_env.run("build-cpython.sh", environment=env) @@ -979,7 +982,7 @@ def main(): # Construct possible options options = set() - options.update({"debug", "noopt", "pgo", "lto", "pgo+lto"}) + options.update({"debug", "noopt", "pgo", "lto", "pgo+lto", "pgo+lto+asan"}) options.update({f"freethreaded+{option}" for option in options}) options.update({f"{option}+static" for option in options}) parser.add_argument( From 975a9d29813bd9959129917809fa9e6183d678b7 Mon Sep 17 00:00:00 2001 From: Geoffrey Thomas Date: Fri, 7 Nov 2025 12:43:23 -0500 Subject: [PATCH 2/2] Disable LeakSanitizer to get past ncurses --- cpython-unix/build.py | 1 + 1 file changed, 1 insertion(+) diff --git a/cpython-unix/build.py b/cpython-unix/build.py index fedddfc69..81bd354ba 100755 --- a/cpython-unix/build.py +++ b/cpython-unix/build.py @@ -95,6 +95,7 @@ def add_target_env(env, build_platform, target_triple, build_env, build_options) if "asan" in build_options: extra_target_cflags.append("-fsanitize=address") + env["ASAN_OPTIONS"] = "detect_leaks=0" if build_platform.startswith("linux_"): machine = platform.machine()