Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
model-checker : ignore differences in data segment of binary due to .plt section
authorMarion Guthmuller <marion.guthmuller@loria.fr>
Sat, 6 Oct 2012 18:14:09 +0000 (20:14 +0200)
committerMarion Guthmuller <marion.guthmuller@loria.fr>
Sat, 6 Oct 2012 18:38:48 +0000 (20:38 +0200)
src/mc/mc_checkpoint.c
src/mc/mc_compare.c
src/mc/mc_liveness.c
src/mc/mc_private.h
src/mc/test/heap_comparison.c

index 411747a..81235b1 100644 (file)
@@ -15,7 +15,8 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_checkpoint, mc,
                                 "Logging specific to mc_checkpoint");
 
 void *start_text_libsimgrid;
-void *start_plt, *end_plt;
+void *start_plt_libsimgrid, *end_plt_libsimgrid;
+void *start_plt_binary, *end_plt_binary;
 char *libsimgrid_path;
 void *start_data_libsimgrid;
 void *start_text_binary;
@@ -168,7 +169,7 @@ void MC_free_snapshot(mc_snapshot_t snapshot)
 }
 
 
-void get_plt_section(){
+void get_libsimgrid_plt_section(){
 
   FILE *fp;
   char *line = NULL;            /* Temporal storage for each line that is readed */
@@ -209,9 +210,66 @@ void get_plt_section(){
     if(i>=5){
       if(strcmp(lfields[1], ".plt") == 0){
         size = strtoul(lfields[2], NULL, 16);
-        offset = strtoul(lfields[4], NULL, 16);
-        start_plt = (char *)start_text_libsimgrid + offset;
-        end_plt = (char *)start_plt + size;
+        offset = strtoul(lfields[5], NULL, 16);
+        start_plt_libsimgrid = (char *)start_text_libsimgrid + offset;
+        end_plt_libsimgrid = (char *)start_plt_libsimgrid + size;
+        plt_not_found = 0;
+      }
+    }
+    
+    
+  }
+
+  free(command);
+  free(line);
+  pclose(fp);
+
+}
+
+void get_binary_plt_section(){
+
+  FILE *fp;
+  char *line = NULL;            /* Temporal storage for each line that is readed */
+  ssize_t read;                 /* Number of bytes readed */
+  size_t n = 0;                 /* Amount of bytes to read by getline */
+
+  char *lfields[7];
+  int i, plt_not_found = 1;
+  unsigned long int size, offset;
+
+  char *command = bprintf( "objdump --section-headers %s", xbt_binary_name);
+
+  fp = popen(command, "r");
+
+  if(fp == NULL)
+    perror("popen failed");
+
+  while ((read = getline(&line, &n, fp)) != -1 && plt_not_found == 1) {
+
+    if(n == 0)
+      continue;
+
+    /* Wipeout the new line character */
+    line[read - 1] = '\0';
+
+    lfields[0] = strtok(line, " ");
+
+    if(lfields[0] == NULL)
+      continue;
+
+    if(strcmp(lfields[0], "Sections:") == 0 || strcmp(lfields[0], "Idx") == 0 || strcmp(lfields[0], basename(xbt_binary_name)) == 0)
+      continue;
+
+    for (i = 1; i < 7 && lfields[i - 1] != NULL; i++) {
+      lfields[i] = strtok(NULL, " ");
+    }
+
+    if(i>=5){
+      if(strcmp(lfields[1], ".plt") == 0){
+        size = strtoul(lfields[2], NULL, 16);
+        offset = strtoul(lfields[5], NULL, 16);
+        start_plt_binary = (char *)start_text_binary + offset;
+        end_plt_binary = (char *)start_plt_binary + size;
         plt_not_found = 0;
       }
     }
index 2601939..1cbca27 100644 (file)
@@ -43,11 +43,20 @@ static size_t ignore(void *address){
 static int data_program_region_compare(void *d1, void *d2, size_t size){
   int distance = 0;
   size_t i = 0;
+  int pointer_align;
+  void *addr_pointed1 = NULL, *addr_pointed2 = NULL;
   
   for(i=0; i<size; i++){
     if(memcmp(((char *)d1) + i, ((char *)d2) + i, 1) != 0){
-      XBT_DEBUG("Different byte (offset=%zu) (%p - %p) in data program region", i, (char *)d1 + i, (char *)d2 + i);
-      distance++;
+      pointer_align = (i / sizeof(void*)) * sizeof(void*);
+      addr_pointed1 = *((void **)((char *)d1 + pointer_align));
+      addr_pointed2 = *((void **)((char *)d2 + pointer_align));
+      if((addr_pointed1 > start_plt_binary && addr_pointed1 < end_plt_binary) || (addr_pointed2 > start_plt_binary && addr_pointed2 < end_plt_binary)){
+        continue;
+      }else{
+        XBT_DEBUG("Different byte (offset=%zu) (%p - %p) in data program region", i, (char *)d1 + i, (char *)d2 + i);
+        distance++;
+      }
     }
   }
   
@@ -71,7 +80,7 @@ static int data_libsimgrid_region_compare(void *d1, void *d2, size_t size){
       pointer_align = (i / sizeof(void*)) * sizeof(void*);
       addr_pointed1 = *((void **)((char *)d1 + pointer_align));
       addr_pointed2 = *((void **)((char *)d2 + pointer_align));
-      if((addr_pointed1 > start_plt && addr_pointed1 < end_plt) || (addr_pointed2 > start_plt && addr_pointed2 < end_plt)){
+      if((addr_pointed1 > start_plt_libsimgrid && addr_pointed1 < end_plt_libsimgrid) || (addr_pointed2 > start_plt_libsimgrid && addr_pointed2 < end_plt_libsimgrid)){
         continue;
       }else{
         XBT_DEBUG("Different byte (offset=%zu) (%p - %p) in data libsimgrid region", i, (char *)d1 + i, (char *)d2 + i);
index aa5bd8b..d111368 100644 (file)
@@ -266,8 +266,9 @@ void MC_ddfs_init(void){
 
   MC_UNSET_RAW_MEM; 
 
-  /* Get .plt section (start and end addresses) for data libsimgrid comparison */
-  get_plt_section();
+  /* Get .plt section (start and end addresses) for data libsimgrid and data program comparison */
+  get_libsimgrid_plt_section();
+  get_binary_plt_section();
 
   unsigned int cursor = 0;
   xbt_state_t state;
index c84a1af..caff24d 100644 (file)
@@ -189,7 +189,8 @@ typedef struct s_memory_map {
 
 memory_map_t get_memory_map(void);
 void free_memory_map(memory_map_t map);
-void get_plt_section(void);
+void get_libsimgrid_plt_section(void);
+void get_binary_plt_section(void);
 
 extern void *start_data_libsimgrid;
 
@@ -214,8 +215,10 @@ extern xbt_fifo_t mc_stack_liveness;
 extern mc_snapshot_t initial_snapshot_liveness;
 extern xbt_automaton_t _mc_property_automaton;
 extern int compare;
-extern void *start_plt;
-extern void *end_plt;
+extern void *start_plt_libsimgrid;
+extern void *end_plt_libsimgrid;
+extern void *start_plt_binary;
+extern void *end_plt_binary;
 
 typedef struct s_mc_pair{
   mc_snapshot_t system_state;
index 60e2222..48d343d 100644 (file)
@@ -236,8 +236,9 @@ void MC_test_heap_comparison(){
 
   MC_UNSET_RAW_MEM;
 
-  /* Get .plt section (start and end addresses) for data libsimgrid comparison */
-  get_plt_section();
+  /* Get .plt section (start and end addresses) for data libsimgrid and data program comparison */
+  get_libsimgrid_plt_section();
+  get_binary_plt_section();
 
   test1();