gdb 5.0: solib.c: LM_ADDR is treated as a memory address (fwd)

Jim Blandy jimb@zwingli.cygnus.com
Fri Jun 23 09:25:00 GMT 2000


Thanks for the patch!  This looks good in principle (although I might
munge the details a bit).  However, I'm about to leave on vacation
until July 10.  I'll mark this for my attention when I get back.


"Maciej W. Rozycki" <macro@ds2.pg.gda.pl> writes:

> 
> ---------- Forwarded message ----------
> Message-ID: <Pine.GSO.3.96.1000619192945.10348T-100000@delta.ds2.pg.gda.pl>
> Date: Mon, 19 Jun 2000 19:43:06 +0200 (MET DST)
> From: "Maciej W. Rozycki" <macro@ds2.pg.gda.pl>
> To: bug-gdb@gnu.org
> Subject: gdb 5.0: solib.c: LM_ADDR is treated as a memory address
> 
> Hi,
> 
>  It seems that ELF shared library functions treat LM_ADDR (the base
> address) as a memory address.  According to the ELF ABI, the base address,
> despite its name, is not a memory address but a difference between the
> link-time address and the load address.  Therefore it cannot be treated as
> the shared object's start address, as this assumption fails whenever its
> link-time address is non-zero.  Due to this bogus assumptions I've
> observed such nonsense as a shared library starting at about 0xc0000000
> and ending at about 0x20000000 (in an output of `info sharedlibrary) in
> user level on a MIPS!
> 
>  The following patch fixes the problem for me.  It makes LM_ADDR be
> treated according to the ABI (and reality) and also makes shared object's
> start be calculated similarly to the way its end is.
> 
>   Maciej
> 
> -- 
> +  Maciej W. Rozycki, Technical University of Gdansk, Poland   +
> +--------------------------------------------------------------+
> +        e-mail: macro@ds2.pg.gda.pl, PGP key available        +
> 
> diff -u --recursive --new-file gdb-5.0.macro/gdb/solib.c gdb-5.0/gdb/solib.c
> --- gdb-5.0.macro/gdb/solib.c	Wed Apr  5 20:40:22 2000
> +++ gdb-5.0/gdb/solib.c	Sat Jun 17 13:10:40 2000
> @@ -169,6 +171,7 @@
>         are initialized when we actually add it to our symbol tables.  */
>  
>      bfd *abfd;
> +    CORE_ADDR lmstart;		/* lower addr bound of mapped object */
>      CORE_ADDR lmend;		/* upper addr bound of mapped object */
>      char symbols_loaded;	/* flag: symbols read in yet? */
>      char from_tty;		/* flag: print msgs? */
> @@ -367,6 +370,7 @@
>           object's file by the base address to which the object was actually
>           mapped. */
>        p->addr += LM_ADDR (so);
> +      so->lmstart = min (p->addr, so->lmstart);
>        p->endaddr += LM_ADDR (so);
>        so->lmend = max (p->endaddr, so->lmend);
>        if (STREQ (p->the_bfd_section->name, ".text"))
> @@ -1092,6 +1096,7 @@
>  	= (struct so_list *) xmalloc (sizeof (struct so_list));
>        struct cleanup *old_chain = make_cleanup (free, new);
>        memset (new, 0, sizeof (*new));
> +      new->lmstart = -1;
>  
>        new->lmaddr = lm;
>        read_memory (lm, (char *) &(new->lm), sizeof (struct link_map));
> @@ -1505,7 +1510,7 @@
>  	    }
>  
>  	  printf_unfiltered ("%-*s", addr_width,
> -		      local_hex_string_custom ((unsigned long) LM_ADDR (so),
> +		      local_hex_string_custom ((unsigned long) so->lmstart,
>  					       addr_fmt));
>  	  printf_unfiltered ("%-*s", addr_width,
>  			 local_hex_string_custom ((unsigned long) so->lmend,
> @@ -1552,7 +1557,7 @@
>  
>    for (so = so_list_head; so; so = so->next)
>      {
> -      if (LM_ADDR (so) <= address && address < so->lmend)
> +      if (so->lmstart <= address && address < so->lmend)
>  	return (so->so_name);
>      }
>  
> 
> 
> 


More information about the Gdb-patches mailing list