--- old/src/jdk.hotspot.agent/linux/native/libsaproc/ps_core.c 2020-08-02 16:10:34.804682894 +0900 +++ new/src/jdk.hotspot.agent/linux/native/libsaproc/ps_core.c 2020-08-02 16:10:34.724680288 +0900 @@ -351,7 +351,7 @@ case PT_LOAD: { if (core_php->p_filesz != 0) { if (add_map_info(ph, ph->core->core_fd, core_php->p_offset, - core_php->p_vaddr, core_php->p_filesz) == NULL) goto err; + core_php->p_vaddr, core_php->p_filesz, core_php->p_flags) == NULL) goto err; } break; } @@ -390,10 +390,20 @@ if (existing_map == NULL){ if (add_map_info(ph, lib_fd, lib_php->p_offset, - target_vaddr, lib_php->p_memsz) == NULL) { + target_vaddr, lib_php->p_memsz, lib_php->p_flags) == NULL) { goto err; } + } else if (lib_php->p_flags != existing_map->flags) { + // Access flags fot this memory region is different between the library + // and coredump. It might be caused by mprotect() call at runtime. + // We should respect to coredump. + continue; } else { + // Read only segments in ELF should not be any different from PT_LOAD segments + // in the coredump. + // And head of ELF header might be included in coredump (See JDK-7133122). + // Thus we need to replace PT_LOAD segments the library version. + // // Coredump stores value of p_memsz elf field // rounded up to page boundary. @@ -460,7 +470,7 @@ case PT_LOAD: { // add only non-writable segments of non-zero filesz if (!(exec_php->p_flags & PF_W) && exec_php->p_filesz != 0) { - if (add_map_info(ph, ph->core->exec_fd, exec_php->p_offset, exec_php->p_vaddr, exec_php->p_filesz) == NULL) goto err; + if (add_map_info(ph, ph->core->exec_fd, exec_php->p_offset, exec_php->p_vaddr, exec_php->p_filesz, exec_php->p_flags) == NULL) goto err; } break; }