From: Jan Kratochvil Date: Mon, 11 Oct 2010 08:50:33 +0000 (+0000) Subject: gdb/ X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=43b8e24199217e03e0101bf02914573d9aefa60b;p=binutils-gdb.git gdb/ Fix attaching to re-prelinked executables on ppc64. * solib-svr4.c (svr4_exec_displacement): New variable plt2_asect, initialize it, try to adjust FILESZ field by it. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 7341c924c3c..5f3b2595905 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2010-10-11 Jan Kratochvil + + Fix attaching to re-prelinked executables on ppc64. + * solib-svr4.c (svr4_exec_displacement): New variable plt2_asect, + initialize it, try to adjust FILESZ field by it. + 2010-10-08 Daniel Jacobowitz * tracepoint.c (merge_uploaded_trace_state_variables): Only print diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c index 9ad67fb50b0..db2136090fd 100644 --- a/gdb/solib-svr4.c +++ b/gdb/solib-svr4.c @@ -1844,6 +1844,7 @@ svr4_exec_displacement (CORE_ADDR *displacementp) Elf32_External_Phdr *phdr2p; gdb_byte *buf_vaddr_p, *buf_paddr_p; CORE_ADDR vaddr, paddr; + asection *plt2_asect; phdrp = &((Elf32_External_Phdr *) buf)[i]; buf_vaddr_p = (gdb_byte *) &phdrp->p_vaddr; @@ -1869,6 +1870,34 @@ svr4_exec_displacement (CORE_ADDR *displacementp) if (memcmp (phdrp, phdr2p, sizeof (*phdrp)) == 0) continue; + /* prelink can convert .plt SHT_NOBITS to SHT_PROGBITS. */ + plt2_asect = bfd_get_section_by_name (exec_bfd, ".plt"); + if (plt2_asect) + { + int content2; + gdb_byte *buf_filesz_p = (gdb_byte *) &phdrp->p_filesz; + CORE_ADDR filesz; + + content2 = (bfd_get_section_flags (exec_bfd, plt2_asect) + & SEC_HAS_CONTENTS) != 0; + + filesz = extract_unsigned_integer (buf_filesz_p, 4, + byte_order); + + /* PLT2_ASECT is from on-disk file (exec_bfd) while + FILESZ is from the in-memory image. */ + if (content2) + filesz += bfd_get_section_size (plt2_asect); + else + filesz -= bfd_get_section_size (plt2_asect); + + store_unsigned_integer (buf_filesz_p, 4, byte_order, + filesz); + + if (memcmp (phdrp, phdr2p, sizeof (*phdrp)) == 0) + continue; + } + ok = 0; break; } @@ -1921,6 +1950,7 @@ svr4_exec_displacement (CORE_ADDR *displacementp) Elf64_External_Phdr *phdr2p; gdb_byte *buf_vaddr_p, *buf_paddr_p; CORE_ADDR vaddr, paddr; + asection *plt2_asect; phdrp = &((Elf64_External_Phdr *) buf)[i]; buf_vaddr_p = (gdb_byte *) &phdrp->p_vaddr; @@ -1946,6 +1976,34 @@ svr4_exec_displacement (CORE_ADDR *displacementp) if (memcmp (phdrp, phdr2p, sizeof (*phdrp)) == 0) continue; + /* prelink can convert .plt SHT_NOBITS to SHT_PROGBITS. */ + plt2_asect = bfd_get_section_by_name (exec_bfd, ".plt"); + if (plt2_asect) + { + int content2; + gdb_byte *buf_filesz_p = (gdb_byte *) &phdrp->p_filesz; + CORE_ADDR filesz; + + content2 = (bfd_get_section_flags (exec_bfd, plt2_asect) + & SEC_HAS_CONTENTS) != 0; + + filesz = extract_unsigned_integer (buf_filesz_p, 8, + byte_order); + + /* PLT2_ASECT is from on-disk file (exec_bfd) while + FILESZ is from the in-memory image. */ + if (content2) + filesz += bfd_get_section_size (plt2_asect); + else + filesz -= bfd_get_section_size (plt2_asect); + + store_unsigned_integer (buf_filesz_p, 8, byte_order, + filesz); + + if (memcmp (phdrp, phdr2p, sizeof (*phdrp)) == 0) + continue; + } + ok = 0; break; }