This is the mail archive of the 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 v2] Fix several mix up between octets and bytes in ELF program headers

On Tue, Dec 17, 2019 at 09:45:32PM +0100, Christian Eggers wrote:
Overall this is looking good, and I think your decision to make the
internal units for p_vaddr, p_paddr and sh_addr octets has worked out

But it looks like you have missed a few places that need an octet per
byte factor.  eg. elf.c search for filehdr_vaddr.  Symbol values for
an address are in bytes, at least internally.  There's another one at
around line 7190 of elf.c where we have a comparison of an expression
involving p_vaddr and a section vma.  That one raises the question of
what to do with alignment.  Presumably, section->alignment_power stays
in bytes since it is most often used with section->vma.  So that's
another thing that needs converting if used to align p_vaddr/p_paddr.

Also elfcode.h bfd_from_remote_memory uses p_vaddr without converting
to bytes.

Also search for phdr_lma in elf.c.  IS_CONTAINED_BY_LMA needs a fix
too, and this in elf.c "map->p_paddr = matching_lma->lma" and the
alignment a little later.

You also need to correct code in bfd_elf_final_link using sh_addr when
setting up DT_REL/DT_RELA.  There's a comparison between sh_addr and

The following in elf32-rx.c where octets per byte is always one (and
thus the file needs no change) is bogus, please remove, and the change
to elf64-ia64-vms.c too:

> > --- a/bfd/elf32-rx.c
> > +++ b/bfd/elf32-rx.c
> > @@ -26,6 +26,9 @@
> >  #include "libiberty.h"
> >  #include "elf32-rx.h"
> >
> > +/* All users of this file have bfd_octets_per_byte (abfd, sec) == 1.  */
> > +#define OCTETS_PER_BYTE(ABFD, SEC) 1
> > +
> >  #define RX_OPCODE_BIG_ENDIAN 0
> >
> >  /* This is a meta-target that's used only with objcopy, to avoid the
> > @@ -3306,7 +3309,10 @@ rx_elf_object_p (bfd * abfd)
> >  	      && phdr[i].p_vaddr <= bsec->vma
> >  	      && bsec->vma <= phdr[i].p_vaddr + (phdr[i].p_filesz - 1))

If you're worrying about about the units of p_vaddr and p_paddr in
this file by introducing OCTETS_PER_BYTE, then the above two lines
need a conversion too, and other places in the file.

> >  	    {
> > -	      bsec->lma = phdr[i].p_paddr + (bsec->vma - phdr[i].p_vaddr);
> > +	      bsec->lma = (phdr[i].p_paddr / OCTETS_PER_BYTE (abfd, bsec)
> > +			   + (bsec->vma
> > +			      - (phdr[i].p_vaddr
> > +				 / OCTETS_PER_BYTE (abfd, bsec))));
> >  	    }
> >  	  bsec = bsec->next;
> >  	}

I'm also wondering about relocations, symbols and dynamic tags with
address values.  Does r_offset specify bytes or octets in the ELF
file?  If octets, then do we convert in elf_swap_reloca_in/out making
internal r_offset in bytes which should be most convenient since it is
often used with section vma?  How about r_addend and st_value?
Anyway, those can be left for a later patch if necessary.

Alan Modra
Australia Development Lab, IBM

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