This is the mail archive of the binutils@sources.redhat.com 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: bfd/elf.c : bfd_seek to 0 valid ?


> on ARM, I'm seeing that in
> 
> bfd/elf.c :
> _bfd_elf_set_section_contents
> 
> Sometimes, the section content is written to seek position 0 :
> 
> boolean
> _bfd_elf_set_section_contents (abfd, section, location, offset, count)
>       bfd *abfd;
>       sec_ptr section;
>       PTR location;
>       file_ptr offset;
>       bfd_size_type count;
> {
>    Elf_Internal_Shdr *hdr;
>    bfd_signed_vma pos;
> 
>    if (! abfd->output_has_begun
>        && ! (_bfd_elf_compute_section_file_positions
> 	    (abfd, (struct bfd_link_info *) NULL)))
>      return false;
> 
>    hdr = &elf_section_data (section)->this_hdr;
>    pos = hdr->sh_offset + offset;               /* pos is sometimes 0 (!) */
> 
>    if (bfd_seek (abfd, pos, SEEK_SET) != 0
>        || bfd_bwrite (location, count, abfd) != count)
>      return false;
> 
>    return true;
> }
> 
> This could explain the fact that section '.rel.dyn' disappears...
> (It is section .rel.dyn that is written to fileposition 0;
> this section is needed in the program so that variables in the .got
> are updated)
> 
> (see <http://sources.redhat.com/ml/binutils/2002-11/msg00139.html>)
> 
> Is this a valid value for 'pos', or would this indicate a problem somewhere else ?

Well, since pos is calculated to be hdr->sh_offset + offset, and since it 
seams reasonable for offset to be zero, the question has to be (assuming 
offset can't be negative!) is it legitimate for hdr->sh_offset to zero.

My guess is that the answer to that question should normally be 'no', and 
the reason for it being so is that the section hasn't been mapped into the 
output bfd.

R.


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