Blame SOURCES/8173941-pr3326.patch

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