dawn::DynamicLib: Leak all DLLs on Windows ASan builds
Loading the same DLL more than once does not work on Windows ASan
builds. (I don't know if this is clang-only or all compilers, so I just
do it for all compilers.)
According to amaiorano:
> By never unloading DLLs, future loads will just increase process ref
> count for that DLL. I think the reason this fixes both issues:
>
> 1. DXC DLL is loaded the first time, then never unloaded, so future
> attempts to load it are no-ops (apart from ref count going up).
> 2. OpenGLES DLL is loaded the first time, which loads dependent DLLs
> like libc++, and never unloaded, so again, future attempts to load
> it are no-ops. Formerly, when OpenGLES DLL was unloaded, it would
> likely unload the libc++ DLL as well, which is why a future attempt
> to load resulted in an ASAN failure.
This issue can be reproduced dawn-try-win10-x64-intel-asan and
dawn-try-win10-x64-nvidia-asan, but using "Cq-Include-Trybots" doesn't
work ("the following builders are included but not defined in the LUCI
project"), so I've run them manually.
Fixed: 392929847
Bug: 347169607
Change-Id: I2c1181969693994b97d3a40bd76364307d2b1b43
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/223901
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Kai Ninomiya <kainino@chromium.org>
diff --git a/src/dawn/common/DynamicLib.cpp b/src/dawn/common/DynamicLib.cpp
index 9d47477..7d823db 100644
--- a/src/dawn/common/DynamicLib.cpp
+++ b/src/dawn/common/DynamicLib.cpp
@@ -90,7 +90,12 @@
}
#if DAWN_PLATFORM_IS(WINDOWS)
+#if !DAWN_ASAN_ENABLED()
+ // Freeing and reloading a DLL on Windows causes ASAN to detect ODR violations.
+ // https://github.com/google/sanitizers/issues/89
+ // In ASAN builds, we have to leak the DLL instead in case it gets loaded again later.
FreeLibrary(static_cast<HMODULE>(mHandle));
+#endif
#elif DAWN_PLATFORM_IS(POSIX)
dlclose(mHandle);
#else
diff --git a/src/dawn/native/Instance.cpp b/src/dawn/native/Instance.cpp
index 61fb5f4..01c75e9 100644
--- a/src/dawn/native/Instance.cpp
+++ b/src/dawn/native/Instance.cpp
@@ -458,16 +458,6 @@
std::vector<Ref<PhysicalDeviceBase>> discoveredPhysicalDevices;
for (wgpu::BackendType b : IterateBitSet(backendsToFind)) {
-#if DAWN_PLATFORM_IS(WINDOWS) && defined(__has_feature)
-#if __has_feature(address_sanitizer)
- if (b == wgpu::BackendType::OpenGLES) {
- // TODO(crbug.com/347169607): Loading libEGL.dll causes an odr-violation in libc++
- ConsumedErrorAndWarnOnce(
- DAWN_INTERNAL_ERROR("OpenGLES backend disabled on Windows ASAN"));
- continue;
- }
-#endif
-#endif
BackendConnection* backend = GetBackendConnection(b);
if (backend != nullptr) {