FreeBSD/contrib/binutils/bfd/elflink.c
/* Create some sections which will be filled in with dynamic linking
   information.  ABFD is an input file which requires dynamic sections
   to be created.  The dynamic sections take up virtual memory space
   when the final executable is run, so we need to create them before
   addresses are assigned to the output sections.  We work out the
   actual contents and size of these sections later.  */
Create some sections which will be filled in with dynamic linking
information.  ABFD is an input file which requires dynamic sections
to be created.  The dynamic sections take up virtual memory space
when the final executable is run, so we need to create them before
addresses are assigned to the output sections.  We work out the
actual contents and size of these sections later.
Create some sections which will be filled in with dynamic linking information . ABFD is an input file which requires dynamic sections to be created . The dynamic sections take up virtual memory space when the final executable is run so we need to create them before addresses are assigned to the output sections . We work out the actual contents and size of these sections later .
bfd_boolean
_bfd_elf_link_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
{
  flagword flags;
  register asection *s;
  const struct elf_backend_data *bed;
  if (! is_elf_hash_table (info->hash))
    return FALSE;
  if (elf_hash_table (info)->dynamic_sections_created)
    return TRUE;
  if (!_bfd_elf_link_create_dynstrtab (abfd, info))
    return FALSE;
  abfd = elf_hash_table (info)->dynobj;
  bed = get_elf_backend_data (abfd);
  flags = bed->dynamic_sec_flags;
  if (info->executable)
    {
      s = bfd_make_section_with_flags (abfd, ".interp",
				       flags | SEC_READONLY);
      if (s == NULL)
	return FALSE;
    }
  s = bfd_make_section_with_flags (abfd, ".gnu.version_d",
				   flags | SEC_READONLY);
  if (s == NULL
      || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
    return FALSE;
  s = bfd_make_section_with_flags (abfd, ".gnu.version",
				   flags | SEC_READONLY);
  if (s == NULL
      || ! bfd_set_section_alignment (abfd, s, 1))
    return FALSE;
  s = bfd_make_section_with_flags (abfd, ".gnu.version_r",
				   flags | SEC_READONLY);
  if (s == NULL
      || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
    return FALSE;
  s = bfd_make_section_with_flags (abfd, ".dynsym",
				   flags | SEC_READONLY);
  if (s == NULL
      || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
    return FALSE;
  s = bfd_make_section_with_flags (abfd, ".dynstr",
				   flags | SEC_READONLY);
  if (s == NULL)
    return FALSE;
  s = bfd_make_section_with_flags (abfd, ".dynamic", flags);
  if (s == NULL
      || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
    return FALSE;
  if (!_bfd_elf_define_linkage_sym (abfd, info, s, "_DYNAMIC"))
    return FALSE;
  if (info->emit_hash)
    {
      s = bfd_make_section_with_flags (abfd, ".hash", flags | SEC_READONLY);
      if (s == NULL
	  || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
	return FALSE;
      elf_section_data (s)->this_hdr.sh_entsize = bed->s->sizeof_hash_entry;
    }
  if (info->emit_gnu_hash)
    {
      s = bfd_make_section_with_flags (abfd, ".gnu.hash",
				       flags | SEC_READONLY);
      if (s == NULL
	  || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
	return FALSE;
      if (bed->s->arch_size == 64)
	elf_section_data (s)->this_hdr.sh_entsize = 0;
      else
	elf_section_data (s)->this_hdr.sh_entsize = 4;
    }
  if (! (*bed->elf_backend_create_dynamic_sections) (abfd, info))
    return FALSE;
  elf_hash_table (info)->dynamic_sections_created = TRUE;
  return TRUE;
}
bfd_boolean _bfd_elf_link_create_dynamic_sections ( bfd * abfd , struct bfd_link_info * info ) { flagword flags ; register asection * s ; const struct elf_backend_data * bed ; if ( ! is_elf_hash_table ( info -> hash ) ) return FALSE ; if ( elf_hash_table ( info ) -> dynamic_sections_created ) return TRUE ; if ( ! _bfd_elf_link_create_dynstrtab ( abfd , info ) ) return FALSE ; abfd = elf_hash_table ( info ) -> dynobj ; bed = get_elf_backend_data ( abfd ) ; flags = bed -> dynamic_sec_flags ; if ( info -> executable ) { s = bfd_make_section_with_flags ( abfd , " " , flags | SEC_READONLY ) ; if ( s == NULL ) return FALSE ; } s = bfd_make_section_with_flags ( abfd , " " , flags | SEC_READONLY ) ; if ( s == NULL || ! bfd_set_section_alignment ( abfd , s , bed -> s -> log_file_align ) ) return FALSE ; s = bfd_make_section_with_flags ( abfd , " " , flags | SEC_READONLY ) ; if ( s == NULL || ! bfd_set_section_alignment ( abfd , s , 1 ) ) return FALSE ; s = bfd_make_section_with_flags ( abfd , " " , flags | SEC_READONLY ) ; if ( s == NULL || ! bfd_set_section_alignment ( abfd , s , bed -> s -> log_file_align ) ) return FALSE ; s = bfd_make_section_with_flags ( abfd , " " , flags | SEC_READONLY ) ; if ( s == NULL || ! bfd_set_section_alignment ( abfd , s , bed -> s -> log_file_align ) ) return FALSE ; s = bfd_make_section_with_flags ( abfd , " " , flags | SEC_READONLY ) ; if ( s == NULL ) return FALSE ; s = bfd_make_section_with_flags ( abfd , " " , flags ) ; if ( s == NULL || ! bfd_set_section_alignment ( abfd , s , bed -> s -> log_file_align ) ) return FALSE ; if ( ! _bfd_elf_define_linkage_sym ( abfd , info , s , " " ) ) return FALSE ; if ( info -> emit_hash ) { s = bfd_make_section_with_flags ( abfd , " " , flags | SEC_READONLY ) ; if ( s == NULL || ! bfd_set_section_alignment ( abfd , s , bed -> s -> log_file_align ) ) return FALSE ; elf_section_data ( s ) -> this_hdr . sh_entsize = bed -> s -> sizeof_hash_entry ; } if ( info -> emit_gnu_hash ) { s = bfd_make_section_with_flags ( abfd , " " , flags | SEC_READONLY ) ; if ( s == NULL || ! bfd_set_section_alignment ( abfd , s , bed -> s -> log_file_align ) ) return FALSE ; if ( bed -> s -> arch_size == 64 ) elf_section_data ( s ) -> this_hdr . sh_entsize = 0 ; else elf_section_data ( s ) -> this_hdr . sh_entsize = 4 ; } if ( ! ( * bed -> elf_backend_create_dynamic_sections ) ( abfd , info ) ) return FALSE ; elf_hash_table ( info ) -> dynamic_sections_created = TRUE ; return TRUE ; }
Create some sections which will be filled in with dynamic linking
information.
Create some sections which will be filled in with dynamic linking information .
/* A dynamically linked executable has a .interp section, but a
     shared library does not.  */ /* Create sections to hold version informations.  These are removed
     if they are not needed.  */ /* The special symbol _DYNAMIC is always set to the start of the
     .dynamic section.  We could set _DYNAMIC in a linker script, but we
     only want to define it if we are, in fact, creating a .dynamic
     section.  We don't want to define it if there is no .dynamic
     section, since on some ELF platforms the start up code examines it
     to decide how to initialize the process.  */ /* For 64-bit ELF, .gnu.hash is a non-uniform entity size section:
	 4 32-bit words followed by variable count of 64-bit words, then
	 variable count of 32-bit words.  */ /* Let the backend create the rest of the sections.  This lets the
     backend set the right flags.  The backend will normally create
     the .got and .plt sections.  */