From 0283589814e341df59ca48e497ff6671fbcb5955 Mon Sep 17 00:00:00 2001 From: Jan Kratochvil Date: Sun, 17 Apr 2011 19:17:10 +0000 Subject: [PATCH] gdb/ Fix libraries displacement if they change whether they were prelinked. * solib-svr4.c (LM_ADDR_CHECK): Set L_ADDR even if the DYNAMIC pointer does not match. Comment why. gdb/testsuite/ * gdb.base/break-interp-lib.c (v, vptr): New variables. * gdb.base/break-interp.exp (test_attach): New comment. --- gdb/ChangeLog | 6 ++++++ gdb/solib-svr4.c | 21 ++++++++++++++++----- gdb/testsuite/ChangeLog | 5 +++++ gdb/testsuite/gdb.base/break-interp-lib.c | 4 ++++ gdb/testsuite/gdb.base/break-interp.exp | 8 ++++++++ 5 files changed, 39 insertions(+), 5 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 9a862b129c..2be27b53c4 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2011-04-17 Jan Kratochvil + + Fix libraries displacement if they change whether they were prelinked. + * solib-svr4.c (LM_ADDR_CHECK): Set L_ADDR even if the DYNAMIC pointer + does not match. Comment why. + 2011-04-17 Jan Kratochvil * corelow.c: Include wrapper.h. diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c index 78c6b1c3ee..b632dd0de3 100644 --- a/gdb/solib-svr4.c +++ b/gdb/solib-svr4.c @@ -237,11 +237,11 @@ LM_ADDR_CHECK (struct so_list *so, bfd *abfd) Even on PPC it must be zero-aligned at least for MINPAGESIZE. */ + l_addr = l_dynaddr - dynaddr; + if ((l_addr & (minpagesize - 1)) == 0 && (l_addr & align) == ((l_dynaddr - dynaddr) & align)) { - l_addr = l_dynaddr - dynaddr; - if (info_verbose) printf_unfiltered (_("Using PIC (Position Independent Code) " "prelink displacement %s for \"%s\".\n"), @@ -249,9 +249,20 @@ LM_ADDR_CHECK (struct so_list *so, bfd *abfd) so->so_name); } else - warning (_(".dynamic section for \"%s\" " - "is not at the expected address " - "(wrong library or version mismatch?)"), so->so_name); + { + /* There is no way to verify the library file matches. prelink + can during prelinking of an unprelinked file (or unprelinking + of a prelinked file) shift the DYNAMIC segment by arbitrary + offset without any page size alignment. There is no way to + find out the ELF header and/or Program Headers for a limited + verification if it they match. One could do a verification + of the DYNAMIC segment. Still the found address is the best + one GDB could find. */ + + warning (_(".dynamic section for \"%s\" " + "is not at the expected address " + "(wrong library or version mismatch?)"), so->so_name); + } } set_addr: diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 6a0d0976d5..dc66c842db 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2011-04-17 Jan Kratochvil + + * gdb.base/break-interp-lib.c (v, vptr): New variables. + * gdb.base/break-interp.exp (test_attach): New comment. + 2011-04-17 Jan Kratochvil * gdb.threads/gcore-thread.exp ($core0file): New variable. diff --git a/gdb/testsuite/gdb.base/break-interp-lib.c b/gdb/testsuite/gdb.base/break-interp-lib.c index 50c5aad8bd..aea27a6ddb 100644 --- a/gdb/testsuite/gdb.base/break-interp-lib.c +++ b/gdb/testsuite/gdb.base/break-interp-lib.c @@ -20,6 +20,10 @@ #include #include +/* Force REL->RELA conversion on i386, see "Prelink", March 4, 2004. */ +volatile int v[2]; +volatile int *vptr = &v[1]; + void libfunc (const char *action) { diff --git a/gdb/testsuite/gdb.base/break-interp.exp b/gdb/testsuite/gdb.base/break-interp.exp index fe79cae553..08a65cd36e 100644 --- a/gdb/testsuite/gdb.base/break-interp.exp +++ b/gdb/testsuite/gdb.base/break-interp.exp @@ -352,6 +352,14 @@ proc test_attach {file displacement {relink_args ""}} { # test simplicity, we merged this test and the test above by not # restoring $INTERP after $EXEC prelink. $INTERP gets restored # later below. + # + # `(wrong library or version mismatch?)' messages are printed for + # $binfile_lib on platforms converting REL->RELA relocations by + # prelink (such as on i386). There is no reliable way to verify + # the library file matches the running library in such case but + # GDB at least attempts to set the right displacement. We test + # `libfunc' is present in the backtrace and therefore the + # displacement has been guessed right. if [prelink$relink $relink_args [file tail $exec]] { # /proc/PID/exe cannot be loaded as it is "EXECNAME (deleted)". -- 2.34.1