address sanitizer won't work with bash on wind

2019-02-21 21:33发布

问题:

Currently running llvm, clang, clang-format, and clang-modernize on Ubuntu Bash on Windows. I would like to use the set of sanitize tools released by google including address, memory, and thread sanitize. None of the fsanitize options seem to work.

Here is the code sample for ASAN:

#include <stdlib.h>
int main() {
  char *x = (char *)malloc(10 * sizeof(char *));
  free(x);
  return x[5];// purposely accessing deallocated memory
}

Here is the clang call in bash on windows:

$clang++-3.5 -fsanitize=address -o1 -fno-omit-frame-pointer -g main.cpp -o main
$./main

Results

==70==Sanitizer CHECK failed: build/buildd/llvm-toolchain-snapshot-3.5/projects/compiler-rt/lib/sanitizer_common/sanitizer_procmaps_linux.cc:211 ((IsOneOf(*current_, 's', 'p'))) != (0)(0,0)

I'd love suggestions on how to get it working or if I'm missing part of the tool-chain or something.

Failing that I suppose I will dual-boot Ubuntu or Debian, because clang for windows is missing simple features like std:out support, though ideally I'd like to be able to compile both for Windows targets and Linux targets. I'd like to avoid dual-booting though as Ubuntu can't mount windows storage spaces, but they appear to be served to Ubuntu bash on windows quite well.

回答1:

Taking a quick peek at the source code - MemoryMappingLayout::Next - https://llvm.org/svn/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_procmaps_linux.cc - it appears the issue is that bash on ubuntu on windows support for the /proc filesystem is incomplete.

The code that fails is looking at /proc/self/maps - which actually - appears to be about right.

But I've found other stuff (e.g. networking ) in /proc completely broken on bashonwindowsonunix - so I'm pretty sure that part is a work in progress.