Commits

Anonymous committed 42d0665

avoid dealing with relocations in gimli_trace sections

Noted that the string pointers were NULL on Solaris, presumably
due to missing relocation handling. For now, continue to ignore
that problem by switching to a collection of strings directly
contained in the section.

  • Participants
  • Parent commits 1fe45e6

Comments (0)

Files changed (3)

 /* Usage: GIMLI_DECLARE_TRACE_MODULE("mymodule")
  * You may omit the .so or .dylib suffix */
 #define GIMLI_DECLARE_TRACER_MODULE(name) \
-  static const char * GIMLI_TRACER_SECTION \
-    GIMLI_PASTE1(gimli_tracer_module_name_,__LINE__) = name
+  static const char GIMLI_TRACER_SECTION \
+    GIMLI_PASTE1(gimli_tracer_module_name_,__LINE__)[] = name
 
 #ifdef __cplusplus
 }
   struct gimli_section_data *s;
   gimli_hash_t names;
   char *name;
-  char **nameptr, **end;
+  char *end;
   int res = 1;
 
   if (!file) {
     return 1;
   }
 
-  if (debug) {
-    printf("[ %s has %s section with %d entries]\n",
-        via->objname, GIMLI_TRACE_SECTION_NAME,
-        (int)(s->size / sizeof(void*)));
-  }
-
-  // This section holds a sequence of pointers to strings that we need
+  // This section holds a sequence of strings that we need
   // to read in, unique and load
 
   names = gimli_hash_new(NULL);
-  nameptr = (char**)s->data;
-  end = (char**)(s->data + s->size);
-  while (nameptr < end) {
-    gimli_addr_t addr = via->base_addr + (gimli_addr_t)*nameptr;
-    name = gimli_read_string(the_proc, addr);
-    if (!name) {
-      printf("[ %s failed to read name from %s offset %d addr " PTRFMT "]\n",
-          via->objname, GIMLI_TRACE_SECTION_NAME,
-          (int)(((uint8_t*)nameptr - s->data) / sizeof(void*)),
-          addr);
-    } else {
-      if (gimli_hash_insert(names, name, name)) {
-        if (!load_module_for_file_named(via, name, 1)) {
-          res = 0;
-        }
+  name = (char*)s->data;
+  end = name + s->size;
+  while (name < end) {
+    if (gimli_hash_insert(names, name, name)) {
+      if (!load_module_for_file_named(via, name, 1)) {
+        res = 0;
       }
     }
-    nameptr++;
+    name += strlen(name) + 1;
+    // Deal with padding/alignment
+    while (name < end && *name == 0) {
+      name++;
+    }
   }
 
   gimli_hash_destroy(names);
 
 // For manually verifying the behavior
 GIMLI_DECLARE_TRACER_MODULE("invalid_lol");
+GIMLI_DECLARE_TRACER_MODULE("and_another_weee");
 
 typedef int wedgie_t;
 enum wedgie_enum {