https://github.com/da-viper updated https://github.com/llvm/llvm-project/pull/177964
>From 4078f31e7a801ac2e8b1cc9cea66dbdf1223800b Mon Sep 17 00:00:00 2001 From: Ebuka Ezike <[email protected]> Date: Wed, 21 Jan 2026 15:23:09 +0000 Subject: [PATCH 1/3] [lldb] Support UBSan decorator on other platforms the ubsan decorator previously assumes the platform is macos. macos has an extra underscore in symbols names. the new check matches the minimum occurence. support both static and dynamic symbols remove dead code --- .../Python/lldbsuite/test/configuration.py | 12 ++++++ .../Python/lldbsuite/test/decorators.py | 38 +++++-------------- lldb/packages/Python/lldbsuite/test/dotest.py | 3 ++ 3 files changed, 25 insertions(+), 28 deletions(-) diff --git a/lldb/packages/Python/lldbsuite/test/configuration.py b/lldb/packages/Python/lldbsuite/test/configuration.py index c2c46b94454a5..f96fd31b17a37 100644 --- a/lldb/packages/Python/lldbsuite/test/configuration.py +++ b/lldb/packages/Python/lldbsuite/test/configuration.py @@ -12,6 +12,7 @@ # Third-party modules +from typing import Optional import unittest # LLDB Modules @@ -61,6 +62,9 @@ # Path to the FileCheck testing tool. Not optional. filecheck = None +# Path to the nm tool. +nm: Optional[str] = None + # Path to the yaml2obj tool. Not optional. yaml2obj = None @@ -171,6 +175,14 @@ def get_filecheck_path(): return filecheck +def get_nm_path(): + """ + Get the path to the nm tool. + """ + if nm and os.path.lexists(nm): + return nm + + def get_yaml2obj_path(): """ Get the path to the yaml2obj tool. diff --git a/lldb/packages/Python/lldbsuite/test/decorators.py b/lldb/packages/Python/lldbsuite/test/decorators.py index ac4a899fbbb8e..6acd2f3979810 100644 --- a/lldb/packages/Python/lldbsuite/test/decorators.py +++ b/lldb/packages/Python/lldbsuite/test/decorators.py @@ -1046,36 +1046,18 @@ def is_compiler_clang_with_ubsan(): outputf, ): return "Compiler cannot compile with -fsanitize=undefined" + if not outputf.path: + return "Cannot create Temp file path." + + nm_bin = configuration.get_nm_path() + if not nm_bin: + return "No llvm-nm or nm binary." # Check that we actually see ubsan instrumentation in the binary. - cmd = "nm %s" % outputf.path - with os.popen(cmd) as nm_output: - if "___ubsan_handle_divrem_overflow" not in nm_output.read(): - return "Division by zero instrumentation is missing" - - # Find the ubsan dylib. - # FIXME: This check should go away once compiler-rt gains support for __ubsan_on_report. - cmd = ( - "%s -fsanitize=undefined -x c - -o - -### 2>&1" - % lldbplatformutil.getCompiler() - ) - with os.popen(cmd) as cc_output: - driver_jobs = cc_output.read() - m = re.search(r'"([^"]+libclang_rt.ubsan_osx_dynamic.dylib)"', driver_jobs) - if not m: - return "Could not find the ubsan dylib used by the driver" - ubsan_dylib = m.group(1) - - # Check that the ubsan dylib has special monitor hooks. - cmd = "nm -gU %s" % ubsan_dylib - with os.popen(cmd) as nm_output: - syms = nm_output.read() - if "___ubsan_on_report" not in syms: - return "Missing ___ubsan_on_report" - if "___ubsan_get_current_report_data" not in syms: - return "Missing ___ubsan_get_current_report_data" - - # OK, this dylib + compiler works for us. + nm_output = subprocess.check_output([nm_bin, outputf.path], text=True) + if "__ubsan_handle_divrem_overflow" not in nm_output: + return "Division by zero instrumentation is missing" + return None return skipTestIfFn(is_compiler_clang_with_ubsan)(func) diff --git a/lldb/packages/Python/lldbsuite/test/dotest.py b/lldb/packages/Python/lldbsuite/test/dotest.py index 84490d86c7e7f..533be0a065e3a 100644 --- a/lldb/packages/Python/lldbsuite/test/dotest.py +++ b/lldb/packages/Python/lldbsuite/test/dotest.py @@ -280,6 +280,9 @@ def parseOptionsAndInitTestdirs(): configuration.llvm_tools_dir = args.llvm_tools_dir configuration.filecheck = shutil.which("FileCheck", path=args.llvm_tools_dir) configuration.yaml2obj = shutil.which("yaml2obj", path=args.llvm_tools_dir) + configuration.nm = shutil.which( + "llvm-nm", path=args.llvm_tools_dir + ) or shutil.which("nm", path=args.llvm_tools_dir) if not configuration.get_filecheck_path(): logging.warning("No valid FileCheck executable; some tests may fail...") >From 36890ebb3922ba3b334664a872bb84fbf7ec2988 Mon Sep 17 00:00:00 2001 From: Ebuka Ezike <[email protected]> Date: Mon, 26 Jan 2026 12:25:12 +0000 Subject: [PATCH 2/3] fix ubsan test case --- lldb/source/Target/InstrumentationRuntimeStopInfo.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lldb/source/Target/InstrumentationRuntimeStopInfo.cpp b/lldb/source/Target/InstrumentationRuntimeStopInfo.cpp index aef895def7939..4be6c5119e07b 100644 --- a/lldb/source/Target/InstrumentationRuntimeStopInfo.cpp +++ b/lldb/source/Target/InstrumentationRuntimeStopInfo.cpp @@ -53,8 +53,7 @@ InstrumentationRuntimeStopInfo::GetSuggestedStackFrameIndex( // case we somehow ended up looking at an infinite recursion. constexpr size_t max_stack_depth = 128; - // Start at parent frame. - size_t stack_idx = 1; + size_t stack_idx = 0; StackFrameSP most_relevant_frame_sp = thread_sp->GetStackFrameAtIndex(stack_idx); >From 6cee63008256fd2db59af1d00717d93018645dec Mon Sep 17 00:00:00 2001 From: Ebuka Ezike <[email protected]> Date: Tue, 27 Jan 2026 14:22:32 +0000 Subject: [PATCH 3/3] [lldb] add review changes. --- lldb/source/Target/InstrumentationRuntimeStopInfo.cpp | 3 ++- lldb/test/API/functionalities/ubsan/basic/TestUbsanBasic.py | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lldb/source/Target/InstrumentationRuntimeStopInfo.cpp b/lldb/source/Target/InstrumentationRuntimeStopInfo.cpp index 4be6c5119e07b..aef895def7939 100644 --- a/lldb/source/Target/InstrumentationRuntimeStopInfo.cpp +++ b/lldb/source/Target/InstrumentationRuntimeStopInfo.cpp @@ -53,7 +53,8 @@ InstrumentationRuntimeStopInfo::GetSuggestedStackFrameIndex( // case we somehow ended up looking at an infinite recursion. constexpr size_t max_stack_depth = 128; - size_t stack_idx = 0; + // Start at parent frame. + size_t stack_idx = 1; StackFrameSP most_relevant_frame_sp = thread_sp->GetStackFrameAtIndex(stack_idx); diff --git a/lldb/test/API/functionalities/ubsan/basic/TestUbsanBasic.py b/lldb/test/API/functionalities/ubsan/basic/TestUbsanBasic.py index 9e9ea2114196e..41c1651530c62 100644 --- a/lldb/test/API/functionalities/ubsan/basic/TestUbsanBasic.py +++ b/lldb/test/API/functionalities/ubsan/basic/TestUbsanBasic.py @@ -13,6 +13,7 @@ class UbsanBasicTestCase(TestBase): @skipUnlessUndefinedBehaviorSanitizer @no_debug_info_test + @skipUnlessDarwin # FIXME: update this test to work on other platforms def test(self): self.build() self.ubsan_tests() _______________________________________________ lldb-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
