[cfe-dev] Windows ASan linker errors

Matt Galloway via cfe-dev cfe-dev at lists.llvm.org
Mon May 4 12:22:29 PDT 2020


Hi,

I have recently been trying to get ASan working on a large app building on
Windows. However I'm running into linker errors which seem very strange to
me. This is all working fine on macOS for the same codebase. I've broken it
down to two minimal test cases showing the problem and I present them here
to see if I can get some help on figuring out what's wrong.

First up, using clang-cl.exe:
C:\toolchain\LLVM9.0.1\bin\clang-cl.exe --version
clang version 9.0.1
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\toolchain\LLVM9.0.1\bin

Then this is the first test case:
> cat broken_asan.cpp
#include <regex>
void foo() { std::regex pattern(R"(.*foo.*)"); }
int main(int argc, char** argv) {}

If I compile and link like this:
> C:\toolchain\LLVM9.0.1\bin\clang-cl.exe /c /MD -Xclang -fsanitize=address
.\broken_asan.cpp /Fobroken_asan.obj
> C:\toolchain\LLVM9.0.1\bin\lld-link.exe broken_asan.obj
/LIBPATH:C:\toolchain\LLVM9.0.1\lib\clang\9.0.1\lib\windows
clang_rt.asan_dynamic-x86_64.lib
clang_rt.asan_dynamic_runtime_thunk-x86_64.lib

Then I get the following link error:
lld-link: error: undefined symbol: public: static class std::locale::id
std::collate<char>::id
>>> referenced by broken_asan.obj:(__unnamed_1)

The second test case looks like this:
> cat broken_asan.cpp
struct Foo {
  static constexpr auto seq = std::integer_sequence<int>();
};
void bar() { (void)Foo::seq.size(); }
int main(int argc, char** argv) {}

And then with the same compile & link commands I get the following link
error:
lld-link: error: undefined symbol: public: static struct
std::integer_sequence<int> const Foo::seq
>>> referenced by broken_asan.obj:(__unnamed_1)

Both of these test cases will work absolutely fine without the "-Xclang
-fsanitize=address" on the compile command.

I'm quite baffled. Does this look like user error on my part somehow, or is
this a bug in ASan implementation on Windows?

Kind regards,
Matt Galloway
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20200504/39b71d16/attachment.html>


More information about the cfe-dev mailing list