FreeBSD/contrib/binutils/bfd/elf.c
/* Set up an ELF internal section header for a section.  */
Set up an ELF internal section header for a section.
Set up an ELF internal section header for a section .
static void
elf_fake_sections (bfd *abfd, asection *asect, void *failedptrarg)
{
  const struct elf_backend_data *bed = get_elf_backend_data (abfd);
  bfd_boolean *failedptr = failedptrarg;
  Elf_Internal_Shdr *this_hdr;
  unsigned int sh_type;
  if (*failedptr)
    {
      return;
    }
  this_hdr = &elf_section_data (asect)->this_hdr;
  this_hdr->sh_name = (unsigned int) _bfd_elf_strtab_add (elf_shstrtab (abfd),
							  asect->name, FALSE);
  if (this_hdr->sh_name == (unsigned int) -1)
    {
      *failedptr = TRUE;
      return;
    }
  if ((asect->flags & SEC_ALLOC) != 0
      || asect->user_set_vma)
    this_hdr->sh_addr = asect->vma;
  else
    this_hdr->sh_addr = 0;
  this_hdr->sh_offset = 0;
  this_hdr->sh_size = asect->size;
  this_hdr->sh_link = 0;
  this_hdr->sh_addralign = 1 << asect->alignment_power;
  this_hdr->bfd_section = asect;
  this_hdr->contents = NULL;
  if (this_hdr->sh_type == SHT_NULL)
    {
      if ((asect->flags & SEC_GROUP) != 0)
	this_hdr->sh_type = SHT_GROUP;
      else if ((asect->flags & SEC_ALLOC) != 0
	       && (((asect->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
		   || (asect->flags & SEC_NEVER_LOAD) != 0))
	this_hdr->sh_type = SHT_NOBITS;
      else
	this_hdr->sh_type = SHT_PROGBITS;
    }
  switch (this_hdr->sh_type)
    {
    default:
      break;
    case SHT_STRTAB:
    case SHT_INIT_ARRAY:
    case SHT_FINI_ARRAY:
    case SHT_PREINIT_ARRAY:
    case SHT_NOTE:
    case SHT_NOBITS:
    case SHT_PROGBITS:
      break;
    case SHT_HASH:
      this_hdr->sh_entsize = bed->s->sizeof_hash_entry;
      break;
    case SHT_DYNSYM:
      this_hdr->sh_entsize = bed->s->sizeof_sym;
      break;
    case SHT_DYNAMIC:
      this_hdr->sh_entsize = bed->s->sizeof_dyn;
      break;
    case SHT_RELA:
      if (get_elf_backend_data (abfd)->may_use_rela_p)
	this_hdr->sh_entsize = bed->s->sizeof_rela;
      break;
     case SHT_REL:
      if (get_elf_backend_data (abfd)->may_use_rel_p)
	this_hdr->sh_entsize = bed->s->sizeof_rel;
      break;
     case SHT_GNU_versym:
      this_hdr->sh_entsize = sizeof (Elf_External_Versym);
      break;
     case SHT_GNU_verdef:
      this_hdr->sh_entsize = 0;
      if (this_hdr->sh_info == 0)
	this_hdr->sh_info = elf_tdata (abfd)->cverdefs;
      else
	BFD_ASSERT (elf_tdata (abfd)->cverdefs == 0
		    || this_hdr->sh_info == elf_tdata (abfd)->cverdefs);
      break;
    case SHT_GNU_verneed:
      this_hdr->sh_entsize = 0;
      if (this_hdr->sh_info == 0)
	this_hdr->sh_info = elf_tdata (abfd)->cverrefs;
      else
	BFD_ASSERT (elf_tdata (abfd)->cverrefs == 0
		    || this_hdr->sh_info == elf_tdata (abfd)->cverrefs);
      break;
    case SHT_GROUP:
      this_hdr->sh_entsize = GRP_ENTRY_SIZE;
      break;
    case SHT_GNU_HASH:
      this_hdr->sh_entsize = bed->s->arch_size == 64 ? 0 : 4;
      break;
    }
  if ((asect->flags & SEC_ALLOC) != 0)
    this_hdr->sh_flags |= SHF_ALLOC;
  if ((asect->flags & SEC_READONLY) == 0)
    this_hdr->sh_flags |= SHF_WRITE;
  if ((asect->flags & SEC_CODE) != 0)
    this_hdr->sh_flags |= SHF_EXECINSTR;
  if ((asect->flags & SEC_MERGE) != 0)
    {
      this_hdr->sh_flags |= SHF_MERGE;
      this_hdr->sh_entsize = asect->entsize;
      if ((asect->flags & SEC_STRINGS) != 0)
	this_hdr->sh_flags |= SHF_STRINGS;
    }
  if ((asect->flags & SEC_GROUP) == 0 && elf_group_name (asect) != NULL)
    this_hdr->sh_flags |= SHF_GROUP;
  if ((asect->flags & SEC_THREAD_LOCAL) != 0)
    {
      this_hdr->sh_flags |= SHF_TLS;
      if (asect->size == 0
	  && (asect->flags & SEC_HAS_CONTENTS) == 0)
	{
	  struct bfd_link_order *o = asect->map_tail.link_order;
	  this_hdr->sh_size = 0;
	  if (o != NULL)
	    {
	      this_hdr->sh_size = o->offset + o->size;
	      if (this_hdr->sh_size != 0)
		this_hdr->sh_type = SHT_NOBITS;
	    }
	}
    }
  sh_type = this_hdr->sh_type;
  if (bed->elf_backend_fake_sections
      && !(*bed->elf_backend_fake_sections) (abfd, this_hdr, asect))
    *failedptr = TRUE;
  if (sh_type == SHT_NOBITS && asect->size != 0)
    {
      this_hdr->sh_type = sh_type;
    }
  if ((asect->flags & SEC_RELOC) != 0
      && !_bfd_elf_init_reloc_shdr (abfd,
				    &elf_section_data (asect)->rel_hdr,
				    asect,
				    asect->use_rela_p))
    *failedptr = TRUE;
}
static void elf_fake_sections ( bfd * abfd , asection * asect , void * failedptrarg ) { const struct elf_backend_data * bed = get_elf_backend_data ( abfd ) ; bfd_boolean * failedptr = failedptrarg ; Elf_Internal_Shdr * this_hdr ; unsigned int sh_type ; if ( * failedptr ) { return ; } this_hdr = & elf_section_data ( asect ) -> this_hdr ; this_hdr -> sh_name = ( unsigned int ) _bfd_elf_strtab_add ( elf_shstrtab ( abfd ) , asect -> name , FALSE ) ; if ( this_hdr -> sh_name == ( unsigned int ) -1 ) { * failedptr = TRUE ; return ; } if ( ( asect -> flags & SEC_ALLOC ) != 0 || asect -> user_set_vma ) this_hdr -> sh_addr = asect -> vma ; else this_hdr -> sh_addr = 0 ; this_hdr -> sh_offset = 0 ; this_hdr -> sh_size = asect -> size ; this_hdr -> sh_link = 0 ; this_hdr -> sh_addralign = 1 << asect -> alignment_power ; this_hdr -> bfd_section = asect ; this_hdr -> contents = NULL ; if ( this_hdr -> sh_type == SHT_NULL ) { if ( ( asect -> flags & SEC_GROUP ) != 0 ) this_hdr -> sh_type = SHT_GROUP ; else if ( ( asect -> flags & SEC_ALLOC ) != 0 && ( ( ( asect -> flags & ( SEC_LOAD | SEC_HAS_CONTENTS ) ) == 0 ) || ( asect -> flags & SEC_NEVER_LOAD ) != 0 ) ) this_hdr -> sh_type = SHT_NOBITS ; else this_hdr -> sh_type = SHT_PROGBITS ; } switch ( this_hdr -> sh_type ) { default : break ; case SHT_STRTAB : case SHT_INIT_ARRAY : case SHT_FINI_ARRAY : case SHT_PREINIT_ARRAY : case SHT_NOTE : case SHT_NOBITS : case SHT_PROGBITS : break ; case SHT_HASH : this_hdr -> sh_entsize = bed -> s -> sizeof_hash_entry ; break ; case SHT_DYNSYM : this_hdr -> sh_entsize = bed -> s -> sizeof_sym ; break ; case SHT_DYNAMIC : this_hdr -> sh_entsize = bed -> s -> sizeof_dyn ; break ; case SHT_RELA : if ( get_elf_backend_data ( abfd ) -> may_use_rela_p ) this_hdr -> sh_entsize = bed -> s -> sizeof_rela ; break ; case SHT_REL : if ( get_elf_backend_data ( abfd ) -> may_use_rel_p ) this_hdr -> sh_entsize = bed -> s -> sizeof_rel ; break ; case SHT_GNU_versym : this_hdr -> sh_entsize = sizeof ( Elf_External_Versym ) ; break ; case SHT_GNU_verdef : this_hdr -> sh_entsize = 0 ; if ( this_hdr -> sh_info == 0 ) this_hdr -> sh_info = elf_tdata ( abfd ) -> cverdefs ; else BFD_ASSERT ( elf_tdata ( abfd ) -> cverdefs == 0 || this_hdr -> sh_info == elf_tdata ( abfd ) -> cverdefs ) ; break ; case SHT_GNU_verneed : this_hdr -> sh_entsize = 0 ; if ( this_hdr -> sh_info == 0 ) this_hdr -> sh_info = elf_tdata ( abfd ) -> cverrefs ; else BFD_ASSERT ( elf_tdata ( abfd ) -> cverrefs == 0 || this_hdr -> sh_info == elf_tdata ( abfd ) -> cverrefs ) ; break ; case SHT_GROUP : this_hdr -> sh_entsize = GRP_ENTRY_SIZE ; break ; case SHT_GNU_HASH : this_hdr -> sh_entsize = bed -> s -> arch_size == 64 ? 0 : 4 ; break ; } if ( ( asect -> flags & SEC_ALLOC ) != 0 ) this_hdr -> sh_flags |= SHF_ALLOC ; if ( ( asect -> flags & SEC_READONLY ) == 0 ) this_hdr -> sh_flags |= SHF_WRITE ; if ( ( asect -> flags & SEC_CODE ) != 0 ) this_hdr -> sh_flags |= SHF_EXECINSTR ; if ( ( asect -> flags & SEC_MERGE ) != 0 ) { this_hdr -> sh_flags |= SHF_MERGE ; this_hdr -> sh_entsize = asect -> entsize ; if ( ( asect -> flags & SEC_STRINGS ) != 0 ) this_hdr -> sh_flags |= SHF_STRINGS ; } if ( ( asect -> flags & SEC_GROUP ) == 0 && elf_group_name ( asect ) != NULL ) this_hdr -> sh_flags |= SHF_GROUP ; if ( ( asect -> flags & SEC_THREAD_LOCAL ) != 0 ) { this_hdr -> sh_flags |= SHF_TLS ; if ( asect -> size == 0 && ( asect -> flags & SEC_HAS_CONTENTS ) == 0 ) { struct bfd_link_order * o = asect -> map_tail . link_order ; this_hdr -> sh_size = 0 ; if ( o != NULL ) { this_hdr -> sh_size = o -> offset + o -> size ; if ( this_hdr -> sh_size != 0 ) this_hdr -> sh_type = SHT_NOBITS ; } } } sh_type = this_hdr -> sh_type ; if ( bed -> elf_backend_fake_sections && ! ( * bed -> elf_backend_fake_sections ) ( abfd , this_hdr , asect ) ) * failedptr = TRUE ; if ( sh_type == SHT_NOBITS && asect -> size != 0 ) { this_hdr -> sh_type = sh_type ; } if ( ( asect -> flags & SEC_RELOC ) != 0 && ! _bfd_elf_init_reloc_shdr ( abfd , & elf_section_data ( asect ) -> rel_hdr , asect , asect -> use_rela_p ) ) * failedptr = TRUE ; }
Set up an ELF internal section header for a section.
Set up an ELF internal section header for a section .
/* We already failed; just get out of the bfd_map_over_sections
	 loop.  */ /* Don't clear sh_flags. Assembler may set additional bits.  */ /* The sh_entsize and sh_info fields may have been set already by
     copy_private_section_data.  */ /* If the section type is unspecified, we set it based on
     asect->flags.  */ /* objcopy or strip will copy over sh_info, but may not set
	 cverdefs.  The linker will set cverdefs, but sh_info will be
	 zero.  */ /* objcopy or strip will copy over sh_info, but may not set
	 cverrefs.  The linker will set cverrefs, but sh_info will be
	 zero.  */ /* Check for processor-specific section types.  */ /* Don't change the header type from NOBITS if we are being
	 called for objcopy --only-keep-debug.  */ /* If the section has relocs, set up a section header for the
     SHT_REL[A] section.  If two relocation sections are required for
     this section, it is up to the processor-specific back-end to
     create the other.  */