This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Re: bfd/elf.c : bfd_seek to 0 valid ?
- From: Ian Lance Taylor <ian at airs dot com>
- To: jeroen dobbelaere <jeroen dot dobbelaere at acunia dot com>
- Cc: binutils at sources dot redhat dot com
- Date: 07 Nov 2002 17:10:59 -0800
- Subject: Re: bfd/elf.c : bfd_seek to 0 valid ?
- References: <3DCA7BD2.8070506@acunia.com>
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