From c5865d03955db3f17e56bab69bb4edfc85c73fcb Mon Sep 17 00:00:00 2001 From: Jeffrey Song Date: Mon, 13 Jul 2026 08:03:53 -0700 Subject: [PATCH] Use configured thread libraries in MT runtime test Context: The direct ASan runtime regression linked with a hard-coded -pthread. Ubuntu 24.04 Clang also requires the configure-detected -latomic for std::atomic::is_lock_free(), so the new test failed to link in upstream CI. Changes: - Query CFG_LDLIBS_THREADS from the configured verilated.mk through Make. - Use the configured flags for both the ASan capability probe and the runtime test link. Evidence: - Red: PR #7927 Ubuntu 24.04 Clang dist-vlt-1 failed with undefined reference to __atomic_is_lock_free. - Green locally: t_verilated_mt_msg_lifetime passes all warn, finish, stop, and fatal modes; lint-py-pylint-tests, YAPF, py_compile, and git diff --check pass. - Linux/Clang green remains to be confirmed by the PR CI rerun. --- test_regress/t/t_verilated_mt_msg_lifetime.py | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/test_regress/t/t_verilated_mt_msg_lifetime.py b/test_regress/t/t_verilated_mt_msg_lifetime.py index be117d94d..0fe9e0bb2 100755 --- a/test_regress/t/t_verilated_mt_msg_lifetime.py +++ b/test_regress/t/t_verilated_mt_msg_lifetime.py @@ -20,10 +20,27 @@ exe = test.obj_dir + "/t_verilated_mt_msg_lifetime" probe_cpp = test.obj_dir + "/asan_probe.cpp" probe_exe = test.obj_dir + "/asan_probe" run_log = test.obj_dir + "/run.log" +thread_ldlibs_make = test.obj_dir + "/thread_ldlibs.mk" cxx_cmd = shlex.split(os.environ["CXX"]) +test.write_wholefile( + thread_ldlibs_make, "include " + os.environ["VERILATOR_ROOT"] + + "/include/verilated.mk\n\n.PHONY: print-thread-ldlibs\n" + "print-thread-ldlibs:\n\t@printf '%s\\n' '$(CFG_LDLIBS_THREADS)'\n") +thread_ldlibs_result = subprocess.run([ + *shlex.split(os.environ.get("MAKE", "make")), "-s", "-f", thread_ldlibs_make, + "print-thread-ldlibs" +], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + text=True, + check=False) +if thread_ldlibs_result.returncode: + test.error("Unable to read configured thread linker flags: " + thread_ldlibs_result.stderr) +thread_ldlibs = shlex.split(thread_ldlibs_result.stdout) + test.write_wholefile(probe_cpp, "int main() { return 0; }\n") -probe_cmd = cxx_cmd + ["-fsanitize=address", "-pthread", probe_cpp, "-o", probe_exe] +probe_cmd = cxx_cmd + ["-fsanitize=address", probe_cpp, "-o", probe_exe, *thread_ldlibs] if sys.platform == "darwin": probe_cmd.append("-Wl,-U,__Z18vlFlushSolverStatsv") probe = subprocess.run(probe_cmd, @@ -49,9 +66,9 @@ cmd = [ "t/t_verilated_mt_msg_lifetime.cpp", os.environ["VERILATOR_ROOT"] + "/include/verilated.cpp", os.environ["VERILATOR_ROOT"] + "/include/verilated_threads.cpp", - "-pthread", "-o", exe, + *thread_ldlibs, ] if sys.platform == "darwin": cmd.append("-Wl,-U,__Z18vlFlushSolverStatsv")