lundi 27 août 2018

Shadow memory and fPie error when running code with thread sanitizer?

The following code sample is compiled with the subsequent command line input

#include <pthread.h>
#include <stdio.h>
#include <string>
#include <map>

typedef std::map<std::string, std::string> map_t;

void *threadfunc(void *p) {
  map_t& m = *(map_t*)p;
  m["foo"] = "bar";
  return 0;
}

int main() {
  map_t m;
  pthread_t t;
  pthread_create(&t, 0, threadfunc, &m);
  printf("foo=%s\n", m["foo"].c_str());
  pthread_join(t, 0);
}

Command line input:

g++ thread.cpp -fsanitize=thread -fPIE -pie -lpie -g

It compiles fine, but when the code is run there are runtime errors.

FATAL: ThreadSanitizer can not mmap the shadow memory (something is mapped at 0x56167ae3b000 < 0x7cf000000000)
FATAL: Make sure to compile with -fPIE and to link with -pie.

I am running this with a version of g++ that has fSanitize so I am unsure about where the source of the problem is?

g++ (GCC) 4.8.5 20150623 (Red Hat 4.8.5-28)

Aucun commentaire:

Enregistrer un commentaire