FreeBSD/contrib/binutils/bfd/elflink.c
/* Create dynamic sections when linking against a dynamic object.  */
Create dynamic sections when linking against a dynamic object.
Create dynamic sections when linking against a dynamic object .
bfd_boolean
_bfd_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
{
  flagword flags, pltflags;
  struct elf_link_hash_entry *h;
  asection *s;
  const struct elf_backend_data *bed = get_elf_backend_data (abfd);
  flags = bed->dynamic_sec_flags;
  pltflags = flags;
  if (bed->plt_not_loaded)
    pltflags &= ~ (SEC_CODE | SEC_LOAD | SEC_HAS_CONTENTS);
  else
    pltflags |= SEC_ALLOC | SEC_CODE | SEC_LOAD;
  if (bed->plt_readonly)
    pltflags |= SEC_READONLY;
  s = bfd_make_section_with_flags (abfd, ".plt", pltflags);
  if (s == NULL
      || ! bfd_set_section_alignment (abfd, s, bed->plt_alignment))
    return FALSE;
  if (bed->want_plt_sym)
    {
      h = _bfd_elf_define_linkage_sym (abfd, info, s,
				       "_PROCEDURE_LINKAGE_TABLE_");
      elf_hash_table (info)->hplt = h;
      if (h == NULL)
	return FALSE;
    }
  s = bfd_make_section_with_flags (abfd,
				   (bed->default_use_rela_p
				    ? ".rela.plt" : ".rel.plt"),
				   flags | SEC_READONLY);
  if (s == NULL
      || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
    return FALSE;
  if (! _bfd_elf_create_got_section (abfd, info))
    return FALSE;
  if (bed->want_dynbss)
    {
      s = bfd_make_section_with_flags (abfd, ".dynbss",
				       (SEC_ALLOC
					| SEC_LINKER_CREATED));
      if (s == NULL)
	return FALSE;
      if (! info->shared)
	{
	  s = bfd_make_section_with_flags (abfd,
					   (bed->default_use_rela_p
					    ? ".rela.bss" : ".rel.bss"),
					   flags | SEC_READONLY);
	  if (s == NULL
	      || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
	    return FALSE;
	}
    }
  return TRUE;
}
bfd_boolean _bfd_elf_create_dynamic_sections ( bfd * abfd , struct bfd_link_info * info ) { flagword flags , pltflags ; struct elf_link_hash_entry * h ; asection * s ; const struct elf_backend_data * bed = get_elf_backend_data ( abfd ) ; flags = bed -> dynamic_sec_flags ; pltflags = flags ; if ( bed -> plt_not_loaded ) pltflags &= ~ ( SEC_CODE | SEC_LOAD | SEC_HAS_CONTENTS ) ; else pltflags |= SEC_ALLOC | SEC_CODE | SEC_LOAD ; if ( bed -> plt_readonly ) pltflags |= SEC_READONLY ; s = bfd_make_section_with_flags ( abfd , " " , pltflags ) ; if ( s == NULL || ! bfd_set_section_alignment ( abfd , s , bed -> plt_alignment ) ) return FALSE ; if ( bed -> want_plt_sym ) { h = _bfd_elf_define_linkage_sym ( abfd , info , s , " " ) ; elf_hash_table ( info ) -> hplt = h ; if ( h == NULL ) return FALSE ; } s = bfd_make_section_with_flags ( abfd , ( bed -> default_use_rela_p ? " " : " " ) , flags | SEC_READONLY ) ; if ( s == NULL || ! bfd_set_section_alignment ( abfd , s , bed -> s -> log_file_align ) ) return FALSE ; if ( ! _bfd_elf_create_got_section ( abfd , info ) ) return FALSE ; if ( bed -> want_dynbss ) { s = bfd_make_section_with_flags ( abfd , " " , ( SEC_ALLOC | SEC_LINKER_CREATED ) ) ; if ( s == NULL ) return FALSE ; if ( ! info -> shared ) { s = bfd_make_section_with_flags ( abfd , ( bed -> default_use_rela_p ? " " : " " ) , flags | SEC_READONLY ) ; if ( s == NULL || ! bfd_set_section_alignment ( abfd , s , bed -> s -> log_file_align ) ) return FALSE ; } } return TRUE ; }
Create dynamic sections when linking against a dynamic object.
Create dynamic sections when linking against a dynamic object .
/* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
     .rel[a].bss sections.  */ /* We do not clear SEC_ALLOC here because we still want the OS to
       allocate space for the section; it's just that there's nothing
       to read in from the object file.  */ /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
     .plt section.  */ /* The .dynbss section is a place to put symbols which are defined
	 by dynamic objects, are referenced by regular objects, and are
	 not functions.  We must allocate space for them in the process
	 image and use a R_*_COPY reloc to tell the dynamic linker to
	 initialize them at run time.  The linker script puts the .dynbss
	 section into the .bss section of the final image.  */ /* The .rel[a].bss section holds copy relocs.  This section is not
	 normally needed.  We need to create it here, though, so that the
	 linker will map it to an output section.  We can't just create it
	 only if we need it, because we will not know whether we need it
	 until we have seen all the input files, and the first time the
	 main linker code calls BFD after examining all the input files
	 (size_dynamic_sections) the input sections have already been
	 mapped to the output sections.  If the section turns out not to
	 be needed, we can discard it later.  We will never need this
	 section when generating a shared object, since they do not use
	 copy relocs.  */