From patchwork Tue Nov 5 01:49:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 21810 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id BC41FBDB1C for ; Tue, 5 Nov 2024 01:50:00 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 019F3653EA; Tue, 5 Nov 2024 02:49:59 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="jlcYLLUX"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id BAE74653E1 for ; Tue, 5 Nov 2024 02:49:57 +0100 (CET) Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 825E87FE; Tue, 5 Nov 2024 02:49:50 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1730771390; bh=hEHwB4Y0gWKIHiwMbuvuyIqKPvV/Ukmub82lOi18xDo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jlcYLLUX4s6kyGzU468/HiS3inNE3FVsPUntnPKXqgxuFrqz2ZJyhw6mKi0xkD4yN owWtQ5m1fFWBQ4gnK+SWlTjzPrIScoHV2Z//QVgfWTpjHTSHJgiZpSin/XaPEuCwHa ZmxuidsUNB3WKt5C+VlwD8/eSKaXtq56hc+TxGGI= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Cc: Tomi Valkeinen Subject: [PATCH 1/2] test: py: Replace environment array with environment object Date: Tue, 5 Nov 2024 03:49:48 +0200 Message-ID: <20241105014949.32244-2-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241105014949.32244-1-laurent.pinchart@ideasonboard.com> References: <20241105014949.32244-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The environment for pyunittests is stored in an array. Meson provides an environment object, which makes handling of multi-value environment variables easier and increases code clarity. Switch to using the environment object. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- test/py/meson.build | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/test/py/meson.build b/test/py/meson.build index 0b679d31ff34..481bb481c110 100644 --- a/test/py/meson.build +++ b/test/py/meson.build @@ -13,15 +13,19 @@ if asan_runtime_missing subdir_done() endif +py_env = environment() + pymod = import('python') py3 = pymod.find_installation('python3') pypathdir = meson.project_build_root() / 'src' / 'py' -py_env = ['PYTHONPATH=' + pypathdir] +py_env.append('PYTHONPATH', pypathdir) if asan_enabled + py_env.append('LD_PRELOAD', asan_runtime) + # Disable leak detection as the Python interpreter is full of leaks. - py_env += ['LD_PRELOAD=' + asan_runtime, 'ASAN_OPTIONS=detect_leaks=0'] + py_env.append('ASAN_OPTIONS', 'detect_leaks=0') endif test('pyunittests', From patchwork Tue Nov 5 01:49:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 21811 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 7E408C32BB for ; Tue, 5 Nov 2024 01:50:02 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B614B653EE; Tue, 5 Nov 2024 02:50:01 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="bfd8QYtF"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 18C95653E1 for ; Tue, 5 Nov 2024 02:49:59 +0100 (CET) Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id D02827FE; Tue, 5 Nov 2024 02:49:51 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1730771392; bh=XqnxBXkQ0UUU3mLxrCJvi3emBttUyPiMmbLzvFM/0FY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bfd8QYtFOvczHhERbhYP/w/iRLAgExPfYT4EzqKVTshAQWMNac+4HVysvYUwkHuUC UMm54nbfIfe5IUx0mfSvC4fqrSQZHSPektQOqrcksAXj7qCCXEJLiLCV4YOQFViEVD t5ZemuWdqxwXVLqPb9Ly4B6jkZpr1z8GCy87ZrYs= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Cc: Tomi Valkeinen Subject: [PATCH 2/2] test: py: LD_PRELOAD the C++ standard library when using ASan Date: Tue, 5 Nov 2024 03:49:49 +0200 Message-ID: <20241105014949.32244-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241105014949.32244-1-laurent.pinchart@ideasonboard.com> References: <20241105014949.32244-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" When the ASan runtime is linked using --as-needed, its dependency on the C++ standard library is stripped. This results to a failure to properly handled exceptions when a C++ dynamically loaded .so is used, as in the Python unit tests that load the libcamera Python module: AddressSanitizer: CHECK failed: asan_interceptors.cpp:335 "((__interception::real___cxa_throw)) != (0)" (0x0, 0x0) (tid=32679) #0 0x7fa2f32e6c19 in CheckUnwind /var/tmp/portage/sys-devel/gcc-13.3.1_p20241025/work/gcc-13-20241025/libsanitizer/asan/asan_rtl.cpp:69 #1 0x7fa2f330c9fd in __sanitizer::CheckFailed(char const*, int, char const*, unsigned long long, unsigned long long) /var/tmp/portage/sys-devel/gcc-13.3.1_p20241025/work/gcc-13-20241025/libsanitizer/sanitizer_common/sanitizer_termination.cpp:86 #2 0x7fa2f3247824 in __interceptor___cxa_throw /var/tmp/portage/sys-devel/gcc-13.3.1_p20241025/work/gcc-13-20241025/libsanitizer/asan/asan_interceptors.cpp:335 #3 0x7fa2f3247824 in __interceptor___cxa_throw /var/tmp/portage/sys-devel/gcc-13.3.1_p20241025/work/gcc-13-20241025/libsanitizer/asan/asan_interceptors.cpp:334 #4 0x7fa2efb6da8b in operator() ../../src/py/libcamera/py_main.cpp:157 [...] The issue has been reported in [1] and so far remains unfixed. Work around it by preloading the C++ standard library. [1] https://github.com/google/sanitizers/issues/934 Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- meson.build | 3 +++ test/py/meson.build | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/meson.build b/meson.build index 63e45465da9c..e3052260f13e 100644 --- a/meson.build +++ b/meson.build @@ -112,6 +112,8 @@ common_arguments = [ c_arguments = [] cpp_arguments = [] +cxx_stdlib = 'libstdc++' + if cc.get_id() == 'clang' if cc.version().version_compare('<9') error('clang version is too old, libcamera requires 9.0 or newer') @@ -137,6 +139,7 @@ if cc.get_id() == 'clang' cpp_arguments += [ '-stdlib=libc++', ] + cxx_stdlib = 'libc++' endif cpp_arguments += [ diff --git a/test/py/meson.build b/test/py/meson.build index 481bb481c110..b922e8578c29 100644 --- a/test/py/meson.build +++ b/test/py/meson.build @@ -24,6 +24,12 @@ py_env.append('PYTHONPATH', pypathdir) if asan_enabled py_env.append('LD_PRELOAD', asan_runtime) + # Preload the C++ standard library to work around a bug in ASan when + # dynamically loading C++ .so modules. + stdlib = run_command(cxx, '-print-file-name=' + cxx_stdlib + '.so', + check : true).stdout().strip() + py_env.append('LD_PRELOAD', stdlib) + # Disable leak detection as the Python interpreter is full of leaks. py_env.append('ASAN_OPTIONS', 'detect_leaks=0') endif