[PATCH] D96120: [scudo] Port scudo sanitizer to Windows

Martin Storsjö via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 26 14:52:15 PST 2021


mstorsjo added a comment.

In D96120#2590587 <https://reviews.llvm.org/D96120#2590587>, @russell.gallop wrote:

> Hi @mstorsjo. Thanks for the suggestions. I tried running up an mingw environment with msys but had trouble getting it working (running into cmake issues). Would you be able to help?

Yeah, building things in that environment is a bit challenging.

> Yes, building and linking a program with -fsanitize=scudo is the simple way to build a simple program. The support for this is in clang/lib/Driver/ToolChains/MSVC.cpp. Would this require support in clang/lib/Driver/ToolChains/MinGW.cpp?

Yes, it would need something similar - I tried whipping something together, which after some tweaks seems to work:

  diff --git a/clang/lib/Driver/ToolChains/MinGW.cpp b/clang/lib/Driver/ToolChains/MinGW.cpp
  index f6cead412236..aab141377204 100644
  --- a/clang/lib/Driver/ToolChains/MinGW.cpp
  +++ b/clang/lib/Driver/ToolChains/MinGW.cpp
  @@ -260,6 +260,14 @@ void tools::MinGW::Linker::ConstructJob(Compilation &C, const JobAction &JA,
           }
         }
   
  +      if (Sanitize.needsScudoRt()) {
  +        for (const auto &Lib : {"scudo", "scudo_cxx"}) {
  +          CmdArgs.push_back(TC.getCompilerRTArgString(Args, Lib));
  +        }
  +        CmdArgs.push_back("--require-defined");
  +        CmdArgs.push_back(Args.MakeArgString("malloc"));
  +      }
  +
         AddLibGCC(Args, CmdArgs);
   
         if (Args.hasArg(options::OPT_pg))
  @@ -492,6 +500,7 @@ SanitizerMask toolchains::MinGW::getSupportedSanitizers() const {
     Res |= SanitizerKind::PointerCompare;
     Res |= SanitizerKind::PointerSubtract;
     Res |= SanitizerKind::Vptr;
  +  Res |= SanitizerKind::Scudo;
     return Res;
   }

Feel free to squash that into your patch (which saves me a bit of effort) :-)

(First I had placed this later in the function, after the asan bits, but in that case, it ended up linking against the normal malloc function instead of the one from scudo - the libraries that provide malloc end up added via the `AddLibGCC()` call.

> I think the best way to test is to run the scudo LIT tests with (e.g.) "ninja check-scudo". These build and run some simple test programs and check that problems are detected.

I didn't try this right now (I primarily cross compile so running tests for the runtimes is a bit challenging), but I did test building the double-free.cpp test with `-fsanitize=scudo`, and it seems to work as it should for all three cases it tests, so with that it seems to be at least roughly working, so I think that's good enough to include the clang driver bits in ToolChains/MinGW.cpp.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D96120/new/

https://reviews.llvm.org/D96120



More information about the llvm-commits mailing list