From f2a154858d0971110f50fae391f34a23b52d9d28 Mon Sep 17 00:00:00 2001 From: Alexis Hetu Date: Fri, 4 Dec 2020 14:07:24 -0500 Subject: [PATCH] Suppress memory leaks detected by LSAN MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In order to be able to land SwANGLE in Chromium, this cl adds suppressions for memory leaks detected by LSAN. Some of these should be fixed and some are intentional leaks of global variables. This cl should allow the linux_chromium_asan_rel_ng bot to pass while using SwANGLE and shouldn't break the win-libfuzzer-asan-rel bot. Bug: chromium:972686 Bug: angleproject:5377 Change-Id: I7e2336aba43fcfeb95716d6c0aa05caf855134aa Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2575200 Reviewed-by: Jamie Madill Commit-Queue: Alexis Hétu --- BUILD.gn | 4 +++ gni/angle.gni | 1 + src/common/angleutils.h | 10 ++++++ src/libANGLE/renderer/vulkan/RendererVk.cpp | 35 +++++++++++++++------ src/libGLESv2/global_state.cpp | 6 +++- 5 files changed, 46 insertions(+), 10 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index 9791f1aa4..c18c8c411 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -135,6 +135,10 @@ config("internal_config") { defines += [ "ANGLE_VULKAN_DISPLAY_MODE_HEADLESS" ] } } + + if (is_lsan) { + defines += [ "ANGLE_WITH_LSAN" ] + } } config("constructor_and_destructor_warnings") { diff --git a/gni/angle.gni b/gni/angle.gni index 3540819a4..351cd705f 100644 --- a/gni/angle.gni +++ b/gni/angle.gni @@ -36,6 +36,7 @@ if (angle_has_build) { is_ubsan = false is_tsan = false is_asan = false + is_lsan = false build_with_chromium = false dcheck_always_on = false angle_use_x11 = (is_linux || is_chromeos) && !is_ggp diff --git a/src/common/angleutils.h b/src/common/angleutils.h index fe8777eec..52450b05a 100644 --- a/src/common/angleutils.h +++ b/src/common/angleutils.h @@ -15,6 +15,10 @@ # include "absl/container/flat_hash_map.h" #endif // defined(ANGLE_USE_ABSEIL) +#if defined(ANGLE_WITH_LSAN) +# include +#endif // defined(ANGLE_WITH_LSAN) + #include #include #include @@ -296,6 +300,12 @@ inline bool IsLittleEndian() UNREACHABLE(); \ ANGLE_CHECK(context, false, "Unreachable Code.", GL_INVALID_OPERATION) +#if defined(ANGLE_WITH_LSAN) +# define ANGLE_SCOPED_DISABLE_LSAN() __lsan::ScopedDisabler lsanDisabler +#else +# define ANGLE_SCOPED_DISABLE_LSAN() +#endif + // The below inlining code lifted from V8. #if defined(__clang__) || (defined(__GNUC__) && defined(__has_attribute)) # define ANGLE_HAS_ATTRIBUTE_ALWAYS_INLINE (__has_attribute(always_inline)) diff --git a/src/libANGLE/renderer/vulkan/RendererVk.cpp b/src/libANGLE/renderer/vulkan/RendererVk.cpp index a6ea856db..857861886 100644 --- a/src/libANGLE/renderer/vulkan/RendererVk.cpp +++ b/src/libANGLE/renderer/vulkan/RendererVk.cpp @@ -616,11 +616,15 @@ angle::Result RendererVk::initialize(DisplayVk *displayVk, // Gather global layer properties. uint32_t instanceLayerCount = 0; - ANGLE_VK_TRY(displayVk, vkEnumerateInstanceLayerProperties(&instanceLayerCount, nullptr)); + { + ANGLE_SCOPED_DISABLE_LSAN(); + ANGLE_VK_TRY(displayVk, vkEnumerateInstanceLayerProperties(&instanceLayerCount, nullptr)); + } std::vector instanceLayerProps(instanceLayerCount); if (instanceLayerCount > 0) { + ANGLE_SCOPED_DISABLE_LSAN(); ANGLE_VK_TRY(displayVk, vkEnumerateInstanceLayerProperties(&instanceLayerCount, instanceLayerProps.data())); } @@ -642,12 +646,16 @@ angle::Result RendererVk::initialize(DisplayVk *displayVk, // Enumerate instance extensions that are provided by the vulkan // implementation and implicit layers. uint32_t instanceExtensionCount = 0; - ANGLE_VK_TRY(displayVk, - vkEnumerateInstanceExtensionProperties(nullptr, &instanceExtensionCount, nullptr)); + { + ANGLE_SCOPED_DISABLE_LSAN(); + ANGLE_VK_TRY(displayVk, vkEnumerateInstanceExtensionProperties( + nullptr, &instanceExtensionCount, nullptr)); + } std::vector instanceExtensionProps(instanceExtensionCount); if (instanceExtensionCount > 0) { + ANGLE_SCOPED_DISABLE_LSAN(); ANGLE_VK_TRY(displayVk, vkEnumerateInstanceExtensionProperties(nullptr, &instanceExtensionCount, instanceExtensionProps.data())); @@ -658,12 +666,18 @@ angle::Result RendererVk::initialize(DisplayVk *displayVk, { uint32_t previousExtensionCount = static_cast(instanceExtensionProps.size()); uint32_t instanceLayerExtensionCount = 0; - ANGLE_VK_TRY(displayVk, vkEnumerateInstanceExtensionProperties( - layerName, &instanceLayerExtensionCount, nullptr)); + { + ANGLE_SCOPED_DISABLE_LSAN(); + ANGLE_VK_TRY(displayVk, vkEnumerateInstanceExtensionProperties( + layerName, &instanceLayerExtensionCount, nullptr)); + } instanceExtensionProps.resize(previousExtensionCount + instanceLayerExtensionCount); - ANGLE_VK_TRY(displayVk, vkEnumerateInstanceExtensionProperties( - layerName, &instanceLayerExtensionCount, - instanceExtensionProps.data() + previousExtensionCount)); + { + ANGLE_SCOPED_DISABLE_LSAN(); + ANGLE_VK_TRY(displayVk, vkEnumerateInstanceExtensionProperties( + layerName, &instanceLayerExtensionCount, + instanceExtensionProps.data() + previousExtensionCount)); + } } vk::ExtensionNameList instanceExtensionNames; @@ -730,7 +744,10 @@ angle::Result RendererVk::initialize(DisplayVk *displayVk, else { uint32_t apiVersion = VK_API_VERSION_1_0; - ANGLE_VK_TRY(displayVk, enumerateInstanceVersion(&apiVersion)); + { + ANGLE_SCOPED_DISABLE_LSAN(); + ANGLE_VK_TRY(displayVk, enumerateInstanceVersion(&apiVersion)); + } if ((VK_VERSION_MAJOR(apiVersion) > 1) || (VK_VERSION_MINOR(apiVersion) >= 1)) { // This is the highest version of core Vulkan functionality that ANGLE uses. diff --git a/src/libGLESv2/global_state.cpp b/src/libGLESv2/global_state.cpp index 0ebebc41a..7fea90835 100644 --- a/src/libGLESv2/global_state.cpp +++ b/src/libGLESv2/global_state.cpp @@ -37,7 +37,11 @@ void SetContextToAndroidOpenGLTLSSlot(gl::Context *value) Thread *AllocateCurrentThread() { - gCurrentThread = new Thread(); + { + // Global thread intentionally leaked + ANGLE_SCOPED_DISABLE_LSAN(); + gCurrentThread = new Thread(); + } // Initialize fast TLS slot SetContextToAndroidOpenGLTLSSlot(nullptr);