gthparch/macsim

Trace Generator bug in creating traces for multi-threaded code

Closed this issue · 2 comments

I am trying to use Intel PIN and trace generator to generate traces for code that is multithreaded, however I get a segmentation fault.

Directions to reproduce:

  1. Sample code (from online source):
#include <pthread.h>
#include <stdio.h>
#include <string.h>

/* function to be run as a thread always must have the same signature:
   it has one void* parameter and returns void */
void *threadfunction(void *arg)
{
  printf("Hello, World!\n"); /*printf() is specified as thread-safe as of C11*/
  return 0;
}

int main(void)
{
  pthread_t thread;
  int createerror = pthread_create(&thread, NULL, threadfunction, NULL);
  int createerror2 = pthread_create(&thread, NULL, threadfunction, NULL);
  /*creates a new thread with default attributes and NULL passed as the argument to the start routine*/
  if (!createerror && !createerror2) /*check whether the thread creation was successful*/
    {
      pthread_join(thread, NULL); /*wait until the created thread terminates*/
      return 0;
    }
  fprintf("%s\n", strerror(createerror), stderr);
  return 1;
}
  1. Compile with gcc pthread_hello_world.c -o HelloWorld -l pthread -Wall

  2. Run make clean && make in ../tools/x86_trace_generator

  3. Run pin: pin -t obj-intel64/trace_generator.so -- ./HelloWorld

Output:

-> Thread[0->0] begins.
-> Trace Generation Starts at icount 0
-> Thread[1->0] begins.
-> Trace Generation Starts at icount 0
-> Thread[2->0] begins.
-> Trace Generation Starts at icount 0
C: Tool (or Pin) caused signal 11 at PC 0x7fb2984de6bb
Segmentation fault (core dumped)

When running with Intel's provided SimpleExample (inscount2_mt.so):

../tools/x86_trace_generator$ pin -t [Full PATH]/inscount2_mt.so -- ./HelloWorld 
Hello, World!
Hello, World!
Count[2] = 684
Count[1] = 7887
Count[0] = 182550
Number of threads ever exist = 3

for multi-threaded applications, please provide the number of threads with -thread knob. We added printf statements to print out this information.