FreeBSD/contrib/binutils/bfd/elf.c
/* Compute the file positions we are going to put the sections at, and
   otherwise prepare to begin writing out the ELF file.  If LINK_INFO
   is not NULL, this is being called by the ELF backend linker.  */
Compute the file positions we are going to put the sections at, and
otherwise prepare to begin writing out the ELF file.  If LINK_INFO
is not NULL, this is being called by the ELF backend linker.
Compute the file positions we are going to put the sections at and otherwise prepare to begin writing out the ELF file . If LINK_INFO is not NULL this is being called by the ELF backend linker .
bfd_boolean
_bfd_elf_compute_section_file_positions (bfd *abfd,
					 struct bfd_link_info *link_info)
{
  const struct elf_backend_data *bed = get_elf_backend_data (abfd);
  bfd_boolean failed;
  struct bfd_strtab_hash *strtab = NULL;
  Elf_Internal_Shdr *shstrtab_hdr;
  if (abfd->output_has_begun)
    return TRUE;
  if (bed->elf_backend_begin_write_processing)
    (*bed->elf_backend_begin_write_processing) (abfd, link_info);
  if (! prep_headers (abfd))
    return FALSE;
  if (bed->elf_backend_post_process_headers)
    (*bed->elf_backend_post_process_headers) (abfd, link_info);
  failed = FALSE;
  bfd_map_over_sections (abfd, elf_fake_sections, &failed);
  if (failed)
    return FALSE;
  if (!assign_section_numbers (abfd, link_info))
    return FALSE;
  if (link_info == NULL && bfd_get_symcount (abfd) > 0)
    {
      int relocatable_p = ! (abfd->flags & (EXEC_P | DYNAMIC));
      if (! swap_out_syms (abfd, &strtab, relocatable_p))
	return FALSE;
    }
  if (link_info == NULL)
    {
      bfd_map_over_sections (abfd, bfd_elf_set_group_contents, &failed);
      if (failed)
	return FALSE;
    }
  shstrtab_hdr = &elf_tdata (abfd)->shstrtab_hdr;
  shstrtab_hdr->sh_type = SHT_STRTAB;
  shstrtab_hdr->sh_flags = 0;
  shstrtab_hdr->sh_addr = 0;
  shstrtab_hdr->sh_size = _bfd_elf_strtab_size (elf_shstrtab (abfd));
  shstrtab_hdr->sh_entsize = 0;
  shstrtab_hdr->sh_link = 0;
  shstrtab_hdr->sh_info = 0;
  shstrtab_hdr->sh_addralign = 1;
  if (!assign_file_positions_except_relocs (abfd, link_info))
    return FALSE;
  if (link_info == NULL && bfd_get_symcount (abfd) > 0)
    {
      file_ptr off;
      Elf_Internal_Shdr *hdr;
      off = elf_tdata (abfd)->next_file_pos;
      hdr = &elf_tdata (abfd)->symtab_hdr;
      off = _bfd_elf_assign_file_position_for_section (hdr, off, TRUE);
      hdr = &elf_tdata (abfd)->symtab_shndx_hdr;
      if (hdr->sh_size != 0)
	off = _bfd_elf_assign_file_position_for_section (hdr, off, TRUE);
      hdr = &elf_tdata (abfd)->strtab_hdr;
      off = _bfd_elf_assign_file_position_for_section (hdr, off, TRUE);
      elf_tdata (abfd)->next_file_pos = off;
      if (bfd_seek (abfd, hdr->sh_offset, SEEK_SET) != 0
	  || ! _bfd_stringtab_emit (abfd, strtab))
	return FALSE;
      _bfd_stringtab_free (strtab);
    }
  abfd->output_has_begun = TRUE;
  return TRUE;
}
bfd_boolean _bfd_elf_compute_section_file_positions ( bfd * abfd , struct bfd_link_info * link_info ) { const struct elf_backend_data * bed = get_elf_backend_data ( abfd ) ; bfd_boolean failed ; struct bfd_strtab_hash * strtab = NULL ; Elf_Internal_Shdr * shstrtab_hdr ; if ( abfd -> output_has_begun ) return TRUE ; if ( bed -> elf_backend_begin_write_processing ) ( * bed -> elf_backend_begin_write_processing ) ( abfd , link_info ) ; if ( ! prep_headers ( abfd ) ) return FALSE ; if ( bed -> elf_backend_post_process_headers ) ( * bed -> elf_backend_post_process_headers ) ( abfd , link_info ) ; failed = FALSE ; bfd_map_over_sections ( abfd , elf_fake_sections , & failed ) ; if ( failed ) return FALSE ; if ( ! assign_section_numbers ( abfd , link_info ) ) return FALSE ; if ( link_info == NULL && bfd_get_symcount ( abfd ) > 0 ) { int relocatable_p = ! ( abfd -> flags & ( EXEC_P | DYNAMIC ) ) ; if ( ! swap_out_syms ( abfd , & strtab , relocatable_p ) ) return FALSE ; } if ( link_info == NULL ) { bfd_map_over_sections ( abfd , bfd_elf_set_group_contents , & failed ) ; if ( failed ) return FALSE ; } shstrtab_hdr = & elf_tdata ( abfd ) -> shstrtab_hdr ; shstrtab_hdr -> sh_type = SHT_STRTAB ; shstrtab_hdr -> sh_flags = 0 ; shstrtab_hdr -> sh_addr = 0 ; shstrtab_hdr -> sh_size = _bfd_elf_strtab_size ( elf_shstrtab ( abfd ) ) ; shstrtab_hdr -> sh_entsize = 0 ; shstrtab_hdr -> sh_link = 0 ; shstrtab_hdr -> sh_info = 0 ; shstrtab_hdr -> sh_addralign = 1 ; if ( ! assign_file_positions_except_relocs ( abfd , link_info ) ) return FALSE ; if ( link_info == NULL && bfd_get_symcount ( abfd ) > 0 ) { file_ptr off ; Elf_Internal_Shdr * hdr ; off = elf_tdata ( abfd ) -> next_file_pos ; hdr = & elf_tdata ( abfd ) -> symtab_hdr ; off = _bfd_elf_assign_file_position_for_section ( hdr , off , TRUE ) ; hdr = & elf_tdata ( abfd ) -> symtab_shndx_hdr ; if ( hdr -> sh_size != 0 ) off = _bfd_elf_assign_file_position_for_section ( hdr , off , TRUE ) ; hdr = & elf_tdata ( abfd ) -> strtab_hdr ; off = _bfd_elf_assign_file_position_for_section ( hdr , off , TRUE ) ; elf_tdata ( abfd ) -> next_file_pos = off ; if ( bfd_seek ( abfd , hdr -> sh_offset , SEEK_SET ) != 0 || ! _bfd_stringtab_emit ( abfd , strtab ) ) return FALSE ; _bfd_stringtab_free ( strtab ) ; } abfd -> output_has_begun = TRUE ; return TRUE ; }
Compute the file positions we are going to put the sections at, and
otherwise prepare to begin writing out the ELF file.
Compute the file positions we are going to put the sections at and otherwise prepare to begin writing out the ELF file .
/* Do any elf backend specific processing first.  */ /* Post process the headers if necessary.  */ /* The backend linker builds symbol table information itself.  */ /* Non-zero if doing a relocatable link.  */ /* sh_name was set in prep_headers.  */ /* sh_offset is set in assign_file_positions_except_relocs.  */ /* Now that we know where the .strtab section goes, write it
	 out.  */