Today I learned that MemorySanitizer somehow cannot work in my environment:

  • Host OS: OS X 10.11.3
  • VirtualBox 5.0.14
  • Guest OS: Ubuntu 14.04.4
  • Clang 3.7.1

Use the very first example from MemorySantizer documentation:

// umr.cc
#include <stdio.h>

int main(int argc, char** argv) {
  int* a = new int[10];
  a[5] = 0;
  if (a[argc])
    printf("xx\n");
  return 0;
}

Compile it with MemorySanitizer enabled:

$ clang -fsanitize=memory -fno-omit-frame-pointer -g -O2 umr.cc

When running the generated executable:

$ ./a.out
FATAL: Code below application range: 0x55ac465bef50 < 0x600000000000. Non-PIE build?
FATAL: MemorySanitizer can not mmap the shadow memory.
FATAL: Make sure to compile with -fPIE and to link with -pie.
FATAL: Disabling ASLR is known to cause this error.
FATAL: If running under GDB, try 'set disable-randomization off'.
==31789==Process memory map follows:
  0x55ac46558000-0x55ac465e2000 /home/patrick/src/clang/umr/a.out
  0x55ac467e1000-0x55ac467e2000 /home/patrick/src/clang/umr/a.out
  0x55ac467e2000-0x55ac467e3000 /home/patrick/src/clang/umr/a.out
  0x55ac467e3000-0x55ac48bfa000 
  ...

Tweaking with -fPIE or system ASLR setting does not help. That's probably a bug. Sigh.