Commit 00c30ce8 by Nicolas Capens Committed by Nicolas Capens

Avoid false-positive MSan error for thread_local

thread_local variables in shared libraries are initialized at load-time, but this is not observed by MemorySanitizer if the loader itself was not instrumented, leading to false-positive unitialized variable errors. Bug: b/155148722 Bug: b/157525646 Change-Id: Ib6b865a44678af83d94499d3764e5134607328c4 Signed-off-by: Nicolas Capens <capn@google.com># Please enter the commit message for your changes. Lines starting Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/49548Tested-by: 's avatarNicolas Capens <nicolascapens@google.com> Reviewed-by: 's avatarBen Clayton <bclayton@google.com> Kokoro-Result: kokoro <noreply+kokoro@google.com>
parent fadd9dfa
...@@ -572,10 +572,15 @@ static ::llvm::Function *createFunction(const char *name, ::llvm::Type *retTy, c ...@@ -572,10 +572,15 @@ static ::llvm::Function *createFunction(const char *name, ::llvm::Type *retTy, c
Nucleus::Nucleus() Nucleus::Nucleus()
{ {
#if !__has_feature(memory_sanitizer)
// thread_local variables in shared libraries are initialized at load-time,
// but this is not observed by MemorySanitizer if the loader itself was not
// instrumented, leading to false-positive unitialized variable errors.
ASSERT(jit == nullptr); ASSERT(jit == nullptr);
jit = new JITBuilder(Nucleus::getDefaultConfig());
ASSERT(Variable::unmaterializedVariables == nullptr); ASSERT(Variable::unmaterializedVariables == nullptr);
#endif
jit = new JITBuilder(Nucleus::getDefaultConfig());
Variable::unmaterializedVariables = new std::unordered_set<const Variable *>(); Variable::unmaterializedVariables = new std::unordered_set<const Variable *>();
} }
......
...@@ -903,7 +903,10 @@ Nucleus::Nucleus() ...@@ -903,7 +903,10 @@ Nucleus::Nucleus()
::routine = elfMemory; ::routine = elfMemory;
} }
#if defined(_WIN32) // TODO(b/157525646): Initialization of thread_local variables in shared libraries may not be supported on all platforms. #if !__has_feature(memory_sanitizer)
// thread_local variables in shared libraries are initialized at load-time,
// but this is not observed by MemorySanitizer if the loader itself was not
// instrumented, leading to false-positive unitialized variable errors.
ASSERT(Variable::unmaterializedVariables == nullptr); ASSERT(Variable::unmaterializedVariables == nullptr);
#endif #endif
Variable::unmaterializedVariables = new std::unordered_set<const Variable *>(); Variable::unmaterializedVariables = new std::unordered_set<const Variable *>();
......
...@@ -115,8 +115,8 @@ TEST_F(SwiftShaderVulkanTest, Version) ...@@ -115,8 +115,8 @@ TEST_F(SwiftShaderVulkanTest, Version)
driver.vkDestroyInstance(instance, nullptr); driver.vkDestroyInstance(instance, nullptr);
} }
/*
TEST_F(SwiftShaderVulkanTest, UnsupportedDeviceExtension) TEST_F(SwiftShaderVulkanTest, UnsupportedDeviceExtension_DISABLED)
{ {
Driver driver; Driver driver;
ASSERT_TRUE(driver.loadSwiftShader()); ASSERT_TRUE(driver.loadSwiftShader());
...@@ -186,9 +186,9 @@ TEST_F(SwiftShaderVulkanTest, UnsupportedDeviceExtension) ...@@ -186,9 +186,9 @@ TEST_F(SwiftShaderVulkanTest, UnsupportedDeviceExtension)
driver.vkDestroyDevice(device, nullptr); driver.vkDestroyDevice(device, nullptr);
} }
driver.vkDestroyInstance(instance, nullptr); driver.vkDestroyInstance(instance, nullptr);
} }
*/
std::vector<uint32_t> compileSpirv(const char *assembly) std::vector<uint32_t> compileSpirv(const char *assembly)
{ {
spvtools::SpirvTools core(SPV_ENV_VULKAN_1_0); spvtools::SpirvTools core(SPV_ENV_VULKAN_1_0);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment