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 ?


jeroen dobbelaere <jeroen.dobbelaere@acunia.com> writes:

> 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 ?

Note that bfd_seek() does not return the new position.  That is,
bfd_seek() is not similar to lseek().  Instead, bfd_seek() returns 0
on success and -1 on failure.  This is like fseek().

Ian


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