|
Jan Kratochvil |
89365c2 |
http://sourceware.org/ml/gdb-patches/2011-02/msg00630.html
|
|
Jan Kratochvil |
89365c2 |
Subject: [patch] [i386] Fix {,un}prelinked libraries for attach/core-load
|
|
Jan Kratochvil |
89365c2 |
|
|
Jan Kratochvil |
89365c2 |
Hi,
|
|
Jan Kratochvil |
89365c2 |
|
|
Jan Kratochvil |
89365c2 |
please see comments in the patch. The adjusted testcase FAILs on i386.
|
|
Jan Kratochvil |
89365c2 |
|
|
Jan Kratochvil |
89365c2 |
"Prelink", March 4, 2004 - by Jakub Jelinek:
|
|
Jan Kratochvil |
89365c2 |
http://people.redhat.com/jakub/prelink.pdf
|
|
Jan Kratochvil |
89365c2 |
primarily section 7 - REL to RELA conversion
|
|
Jan Kratochvil |
89365c2 |
|
|
Jan Kratochvil |
89365c2 |
An example of unprelinked -> prelinked library change:
|
|
Jan Kratochvil |
89365c2 |
Program Headers:
|
|
Jan Kratochvil |
89365c2 |
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
|
|
Jan Kratochvil |
89365c2 |
- LOAD 0x000000 0x00000000 0x00000000 0x00538 0x00538 R E 0x1000
|
|
Jan Kratochvil |
89365c2 |
- LOAD 0x000538 0x00001538 0x00001538 0x00100 0x00110 RW 0x1000
|
|
Jan Kratochvil |
89365c2 |
- DYNAMIC 0x000550 0x00001550 0x00001550 0x000c8 0x000c8 RW 0x4
|
|
Jan Kratochvil |
89365c2 |
- NOTE 0x0000f4 0x000000f4 0x000000f4 0x00024 0x00024 R 0x4
|
|
Jan Kratochvil |
89365c2 |
- GNU_EH_FRAME 0x0004e8 0x000004e8 0x000004e8 0x00014 0x00014 R 0x4
|
|
Jan Kratochvil |
89365c2 |
+ LOAD 0x000000 0x411b3000 0x411b3000 0x00558 0x00558 R E 0x1000
|
|
Jan Kratochvil |
89365c2 |
+ LOAD 0x000558 0x411b4558 0x411b4558 0x00100 0x00110 RW 0x1000
|
|
Jan Kratochvil |
89365c2 |
+ DYNAMIC 0x000570 0x411b4570 0x411b4570 0x000c8 0x000c8 RW 0x4
|
|
Jan Kratochvil |
89365c2 |
+ NOTE 0x0000f4 0x411b30f4 0x411b30f4 0x00024 0x00024 R 0x4
|
|
Jan Kratochvil |
89365c2 |
+ GNU_EH_FRAME 0x000508 0x411b3508 0x411b3508 0x00014 0x00014 R 0x4
|
|
Jan Kratochvil |
89365c2 |
GNU_STACK 0x000000 0x00000000 0x00000000 0x00000 0x00000 RW 0x4
|
|
Jan Kratochvil |
89365c2 |
|
|
Jan Kratochvil |
89365c2 |
So far GDB expected all such displacements will be always PAGE_SIZE aligned.
|
|
Jan Kratochvil |
89365c2 |
This applies for example for re-prelinking of an already prelinked file.
|
|
Jan Kratochvil |
89365c2 |
But it does not apply for prelinking of an unprelinked file or unprelinking of
|
|
Jan Kratochvil |
89365c2 |
a prelinked file, there can be arbitrary displacement.
|
|
Jan Kratochvil |
89365c2 |
|
|
Jan Kratochvil |
89365c2 |
It affects i386 (=i686, prelink doc reports also ARM and MIPS) which uses REL.
|
|
Jan Kratochvil |
89365c2 |
x86_64 always uses RELA, therefore I have not noticed it so far. i386 still
|
|
Jan Kratochvil |
89365c2 |
has to be supported.
|
|
Jan Kratochvil |
89365c2 |
|
|
Jan Kratochvil |
89365c2 |
This affects both attachment to a PID and core file loads.
|
|
Jan Kratochvil |
89365c2 |
|
|
Jan Kratochvil |
89365c2 |
This applies in real world if you transfer a core file between hosts and try to
|
|
Jan Kratochvil |
89365c2 |
backtrace them, libraries of both hosts may differ whether they are / are not
|
|
Jan Kratochvil |
89365c2 |
prelinked.
|
|
Jan Kratochvil |
89365c2 |
|
|
Jan Kratochvil |
89365c2 |
I could implement some (displacement-forgiving and prelink-modifications
|
|
Jan Kratochvil |
89365c2 |
forgiving) comparison of both DYNAMIC segments found. But I do not think it is
|
|
Jan Kratochvil |
89365c2 |
useful, if the DYNAMIC address from linkmap vs. bfd do not match it is still a
|
|
Jan Kratochvil |
89365c2 |
better chance to try a displacement to make them match. Keeping the file
|
|
Jan Kratochvil |
89365c2 |
relocation cannot work anyway when the DYNAMIC address is verified as wrong.
|
|
Jan Kratochvil |
89365c2 |
|
|
Jan Kratochvil |
89365c2 |
No regressions on {x86_64,x86_64-m32,i686}-fedora15-linux-gnu.
|
|
Jan Kratochvil |
89365c2 |
|
|
Jan Kratochvil |
89365c2 |
Mostly do you agree the DYNAMIC content does not have to be verifed?
|
|
Jan Kratochvil |
89365c2 |
Do you have any comments on the in-code long comments?
|
|
Jan Kratochvil |
89365c2 |
|
|
Jan Kratochvil |
89365c2 |
|
|
Jan Kratochvil |
89365c2 |
Thanks,
|
|
Jan Kratochvil |
89365c2 |
Jan
|
|
Jan Kratochvil |
89365c2 |
|
|
Jan Kratochvil |
89365c2 |
|
|
Jan Kratochvil |
89365c2 |
gdb/
|
|
Jan Kratochvil |
89365c2 |
2011-02-22 Jan Kratochvil <jan.kratochvil@redhat.com>
|
|
Jan Kratochvil |
89365c2 |
|
|
Jan Kratochvil |
89365c2 |
Fix libraries displacement if they change whether they were prelinked.
|
|
Jan Kratochvil |
89365c2 |
* solib-svr4.c (LM_ADDR_CHECK): Set L_ADDR even if the DYNAMIC pointer
|
|
Jan Kratochvil |
89365c2 |
does not match. Comment why.
|
|
Jan Kratochvil |
89365c2 |
|
|
Jan Kratochvil |
89365c2 |
gdb/testsuite/
|
|
Jan Kratochvil |
89365c2 |
2011-02-22 Jan Kratochvil <jan.kratochvil@redhat.com>
|
|
Jan Kratochvil |
89365c2 |
|
|
Jan Kratochvil |
89365c2 |
* gdb.base/break-interp-lib.c (v, vptr): New variables.
|
|
Jan Kratochvil |
89365c2 |
* gdb.base/break-interp.exp (test_attach): New comment.
|
|
Jan Kratochvil |
89365c2 |
|
|
Jan Kratochvil |
89365c2 |
--- a/gdb/solib-svr4.c
|
|
Jan Kratochvil |
89365c2 |
+++ b/gdb/solib-svr4.c
|
|
Jan Kratochvil |
89365c2 |
@@ -237,11 +237,11 @@ LM_ADDR_CHECK (struct so_list *so, bfd *abfd)
|
|
Jan Kratochvil |
89365c2 |
|
|
Jan Kratochvil |
89365c2 |
Even on PPC it must be zero-aligned at least for MINPAGESIZE. */
|
|
Jan Kratochvil |
89365c2 |
|
|
Jan Kratochvil |
89365c2 |
+ l_addr = l_dynaddr - dynaddr;
|
|
Jan Kratochvil |
89365c2 |
+
|
|
Jan Kratochvil |
89365c2 |
if ((l_addr & (minpagesize - 1)) == 0
|
|
Jan Kratochvil |
89365c2 |
&& (l_addr & align) == ((l_dynaddr - dynaddr) & align))
|
|
Jan Kratochvil |
89365c2 |
{
|
|
Jan Kratochvil |
89365c2 |
- l_addr = l_dynaddr - dynaddr;
|
|
Jan Kratochvil |
89365c2 |
-
|
|
Jan Kratochvil |
89365c2 |
if (info_verbose)
|
|
Jan Kratochvil |
89365c2 |
printf_unfiltered (_("Using PIC (Position Independent Code) "
|
|
Jan Kratochvil |
89365c2 |
"prelink displacement %s for \"%s\".\n"),
|
|
Jan Kratochvil |
89365c2 |
@@ -249,9 +249,20 @@ LM_ADDR_CHECK (struct so_list *so, bfd *abfd)
|
|
Jan Kratochvil |
89365c2 |
so->so_name);
|
|
Jan Kratochvil |
89365c2 |
}
|
|
Jan Kratochvil |
89365c2 |
else
|
|
Jan Kratochvil |
89365c2 |
- warning (_(".dynamic section for \"%s\" "
|
|
Jan Kratochvil |
89365c2 |
- "is not at the expected address "
|
|
Jan Kratochvil |
89365c2 |
- "(wrong library or version mismatch?)"), so->so_name);
|
|
Jan Kratochvil |
89365c2 |
+ {
|
|
Jan Kratochvil |
89365c2 |
+ /* There is no way to verify the library file matches. prelink
|
|
Jan Kratochvil |
89365c2 |
+ can during prelinking of an unprelinked file (or unprelinking
|
|
Jan Kratochvil |
89365c2 |
+ of a prelinked file) shift the DYNAMIC segment by arbitrary
|
|
Jan Kratochvil |
89365c2 |
+ offset without any page size alignment. There is no way to
|
|
Jan Kratochvil |
89365c2 |
+ find out the ELF header and/or Program Headers for a limited
|
|
Jan Kratochvil |
89365c2 |
+ verification if it they match. One could do a verification
|
|
Jan Kratochvil |
89365c2 |
+ of the DYNAMIC segment. Still the found address is the best
|
|
Jan Kratochvil |
89365c2 |
+ one GDB could find. */
|
|
Jan Kratochvil |
89365c2 |
+
|
|
Jan Kratochvil |
89365c2 |
+ warning (_(".dynamic section for \"%s\" "
|
|
Jan Kratochvil |
89365c2 |
+ "is not at the expected address "
|
|
Jan Kratochvil |
89365c2 |
+ "(wrong library or version mismatch?)"), so->so_name);
|
|
Jan Kratochvil |
89365c2 |
+ }
|
|
Jan Kratochvil |
89365c2 |
}
|
|
Jan Kratochvil |
89365c2 |
|
|
Jan Kratochvil |
89365c2 |
set_addr:
|
|
Jan Kratochvil |
89365c2 |
--- a/gdb/testsuite/gdb.base/break-interp-lib.c
|
|
Jan Kratochvil |
89365c2 |
+++ b/gdb/testsuite/gdb.base/break-interp-lib.c
|
|
Jan Kratochvil |
89365c2 |
@@ -20,6 +20,10 @@
|
|
Jan Kratochvil |
89365c2 |
#include <assert.h>
|
|
Jan Kratochvil |
89365c2 |
#include <stdio.h>
|
|
Jan Kratochvil |
89365c2 |
|
|
Jan Kratochvil |
89365c2 |
+/* Force REL->RELA conversion on i386, see "Prelink", March 4, 2004. */
|
|
Jan Kratochvil |
89365c2 |
+volatile int v[2];
|
|
Jan Kratochvil |
89365c2 |
+volatile int *vptr = &v[1];
|
|
Jan Kratochvil |
89365c2 |
+
|
|
Jan Kratochvil |
89365c2 |
void
|
|
Jan Kratochvil |
89365c2 |
libfunc (const char *action)
|
|
Jan Kratochvil |
89365c2 |
{
|
|
Jan Kratochvil |
89365c2 |
--- a/gdb/testsuite/gdb.base/break-interp.exp
|
|
Jan Kratochvil |
89365c2 |
+++ b/gdb/testsuite/gdb.base/break-interp.exp
|
|
Jan Kratochvil |
89365c2 |
@@ -352,6 +352,14 @@ proc test_attach {file displacement {relink_args ""}} {
|
|
Jan Kratochvil |
89365c2 |
# test simplicity, we merged this test and the test above by not
|
|
Jan Kratochvil |
89365c2 |
# restoring $INTERP after $EXEC prelink. $INTERP gets restored
|
|
Jan Kratochvil |
89365c2 |
# later below.
|
|
Jan Kratochvil |
89365c2 |
+ #
|
|
Jan Kratochvil |
89365c2 |
+ # `(wrong library or version mismatch?)' messages are printed for
|
|
Jan Kratochvil |
89365c2 |
+ # $binfile_lib on platforms converting REL->RELA relocations by
|
|
Jan Kratochvil |
89365c2 |
+ # prelink (such as on i386). There is no reliable way to verify
|
|
Jan Kratochvil |
89365c2 |
+ # the library file matches the running library in such case but
|
|
Jan Kratochvil |
89365c2 |
+ # GDB at least attempts to set the right displacement. We test
|
|
Jan Kratochvil |
89365c2 |
+ # `libfunc' is present in the backtrace and therefore the
|
|
Jan Kratochvil |
89365c2 |
+ # displacement has been guessed right.
|
|
Jan Kratochvil |
89365c2 |
|
|
Jan Kratochvil |
89365c2 |
if [prelink$relink $relink_args [file tail $exec]] {
|
|
Jan Kratochvil |
89365c2 |
# /proc/PID/exe cannot be loaded as it is "EXECNAME (deleted)".
|
|
Jan Kratochvil |
89365c2 |
|