Blame SOURCES/8173941-pr3326.patch

e24496
# HG changeset patch
e24496
# User ysuenaga
e24496
# Date 1487123491 18000
e24496
#      Tue Feb 14 20:51:31 2017 -0500
e24496
# Node ID 15922b2f31db4857ec84efdf533c41b19e68030b
e24496
# Parent  652fe741b8f2bfdacba66d772cc89fe7ec6dea66
e24496
8173941, PR3326: SA does not work if executable is DSO
e24496
Reviewed-by: aph, dsamersoff
e24496
e24496
diff --git a/agent/src/os/linux/elfmacros.h b/agent/src/os/linux/elfmacros.h
e24496
--- openjdk/hotspot/agent/src/os/linux/elfmacros.h
e24496
+++ openjdk/hotspot/agent/src/os/linux/elfmacros.h
e24496
@@ -33,6 +33,7 @@
e24496
 #define ELF_NHDR        Elf64_Nhdr
e24496
 #define ELF_DYN         Elf64_Dyn
e24496
 #define ELF_ADDR        Elf64_Addr
e24496
+#define ELF_AUXV        Elf64_auxv_t
e24496
 
e24496
 #define ELF_ST_TYPE     ELF64_ST_TYPE
e24496
 
e24496
@@ -45,6 +46,7 @@
e24496
 #define ELF_NHDR        Elf32_Nhdr
e24496
 #define ELF_DYN         Elf32_Dyn
e24496
 #define ELF_ADDR        Elf32_Addr
e24496
+#define ELF_AUXV        Elf32_auxv_t
e24496
 
e24496
 #define ELF_ST_TYPE     ELF32_ST_TYPE
e24496
 
e24496
diff --git a/agent/src/os/linux/ps_core.c b/agent/src/os/linux/ps_core.c
e24496
--- openjdk/hotspot/agent/src/os/linux/ps_core.c
e24496
+++ openjdk/hotspot/agent/src/os/linux/ps_core.c
e24496
@@ -642,6 +642,18 @@
e24496
         if (core_handle_prstatus(ph, descdata, notep->n_descsz) != true) {
e24496
           return false;
e24496
         }
e24496
+      } else if (notep->n_type == NT_AUXV) {
e24496
+        // Get first segment from entry point
e24496
+        ELF_AUXV *auxv = (ELF_AUXV *)descdata;
e24496
+        while (auxv->a_type != AT_NULL) {
e24496
+          if (auxv->a_type == AT_ENTRY) {
e24496
+            // Set entry point address to address of dynamic section.
e24496
+            // We will adjust it in read_exec_segments().
e24496
+            ph->core->dynamic_addr = auxv->a_un.a_val;
e24496
+            break;
e24496
+          }
e24496
+          auxv++;
e24496
+        }
e24496
       }
e24496
       p = descdata + ROUNDUP(notep->n_descsz, 4);
e24496
    }
e24496
@@ -826,7 +838,13 @@
e24496
 
e24496
          // from PT_DYNAMIC we want to read address of first link_map addr
e24496
          case PT_DYNAMIC: {
e24496
-            ph->core->dynamic_addr = exec_php->p_vaddr;
e24496
+            if (exec_ehdr->e_type == ET_EXEC) {
e24496
+                ph->core->dynamic_addr = exec_php->p_vaddr;
e24496
+            } else { // ET_DYN
e24496
+                // dynamic_addr has entry point of executable.
e24496
+                // Thus we should substract it.
e24496
+                ph->core->dynamic_addr += exec_php->p_vaddr - exec_ehdr->e_entry;
e24496
+            }
e24496
             print_debug("address of _DYNAMIC is 0x%lx\n", ph->core->dynamic_addr);
e24496
             break;
e24496
          }
e24496
@@ -1024,8 +1042,9 @@
e24496
     goto err;
e24496
   }
e24496
 
e24496
-  if (read_elf_header(ph->core->exec_fd, &exec_ehdr) != true || exec_ehdr.e_type != ET_EXEC) {
e24496
-    print_debug("executable file is not a valid ELF ET_EXEC file\n");
e24496
+  if (read_elf_header(ph->core->exec_fd, &exec_ehdr) != true ||
e24496
+      ((exec_ehdr.e_type != ET_EXEC) && (exec_ehdr.e_type != ET_DYN))) {
e24496
+    print_debug("executable file is not a valid ELF file\n");
e24496
     goto err;
e24496
   }
e24496