This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch] bfd/: bfd_elf_bfd_from_remote_memory 32bit &= 0xffffffff


On Thu, 11 Feb 2010 13:13:43 +0100, Andreas Schwab wrote:
> Jan Kratochvil <jan.kratochvil@redhat.com> writes:
> 
> > --- a/bfd/elfcode.h
> > +++ b/bfd/elfcode.h
> > @@ -1745,6 +1745,8 @@ NAME(_bfd_elf,bfd_from_remote_memory)
> >  	  if (!loadbase_set && (i_phdrs[i].p_offset & -i_phdrs[i].p_align) == 0)
> >  	    {
> >  	      loadbase = ehdr_vma - (i_phdrs[i].p_vaddr & -i_phdrs[i].p_align);
> > +	      if (ELFCLASS == ELFCLASS32)
> > +		loadbase &= 0xffffffff;
> 
> Some targets use signed addresses.

http://sourceware.org/ml/gdb-patches/2006-09/msg00197.html
# One caveat:
# if addresses are supposed to be sign extended, we should not print out
# 64-bit addresses for a 32-bit target just because they're sign
# extended.  This will show up on MIPS, which sign extends addresses.

Thanks for bringing up this larger issue.

As this representation is only internal to gdb (bfd) I chose rather to use
always the unsigned/zeroed format as it makes its internal handling in tools
IMO easier.  It does not (or at least does not have to) affect any inferior-
or user- visible behavior.  If someone casts CORE_ADDR -> LONGEST/ULONGEST
then CORE_ADDR should be extended the proper sign/unsigned way from its target
width (such as 32->64).

This patch is a prerequisite for PIE support on 64bit gdb -> 32bit inferior,
commented by Ulrich Weigand in:
http://sourceware.org/ml/gdb-patches/2010-01/msg00497.html

The full gdb patch (not yet posted) already does explicit handling of target
width on any CORE_ADDR in use as an address _displacement_ by ensuring
a compilation error otherwise:

+/* Wrap CORE_ADDR so that normal math operation are no longer valid on it.  Use
+   the set of functions around addr_add_offset to access it.  Direct access to
+   A is permitted for reading A and setting A to constant like zero or one.  */
+typedef struct
+  {
+    CORE_ADDR a;
+  }
+addr_offset_t;

There should be similar part done for all the CORE_ADDR operations to properly
respect target address width.  This is currently already broken anyway.
Therefore if we either always-zero-extend or target-wise-sign-extend CORE_ADDR
should not be a regression.  I do not intend to post such full CORE_ADDR fixup
(outside of the biarch-PIE functionality) in a near future, though.

It may be simpler if CORE_ADDR would be a C++ class with overriden operators.
But moving GDB over to C++ has been currently turned down.


Thanks,
Jan


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]