Documentation for memory tagging remote packets
[deliverable/binutils-gdb.git] / ld / ldelf.c
index 8f2167e8895ef3bdd5029ff2f5c247ad868c3617..94d775db5cd98b5bb7b7b933f69afc007dd6c0bb 100644 (file)
@@ -1,5 +1,5 @@
 /* ELF emulation code for targets using elf.em.
-   Copyright (C) 1991-2020 Free Software Foundation, Inc.
+   Copyright (C) 1991-2021 Free Software Foundation, Inc.
 
    This file is part of the GNU Binutils.
 
@@ -262,6 +262,8 @@ ldelf_try_needed (struct dt_needed *needed, int force, int is_linux)
       return FALSE;
     }
 
+  track_dependency_files (name);
+
   /* Linker needs to decompress sections.  */
   abfd->flags |= BFD_DECOMPRESS;
 
@@ -319,7 +321,7 @@ ldelf_try_needed (struct dt_needed *needed, int force, int is_linux)
              struct bfd_link_needed_list *l;
 
              for (l = needs; l != NULL; l = l->next)
-               if (CONST_STRNEQ (l->name, "libc.so"))
+               if (startswith (l->name, "libc.so"))
                  break;
              if (l == NULL)
                {
@@ -835,7 +837,7 @@ ldelf_parse_ld_so_conf (struct ldelf_ld_so_conf *info, const char *filename)
       if (p[0] == '\0')
        continue;
 
-      if (CONST_STRNEQ (p, "include") && (p[7] == ' ' || p[7] == '\t'))
+      if (startswith (p, "include") && (p[7] == ' ' || p[7] == '\t'))
        {
          char *dir, c;
          p += 8;
@@ -1041,7 +1043,9 @@ ldelf_after_open (int use_libpath, int native, int is_linux, int is_freebsd,
   /* Do not allow executable files to be used as inputs to the link.  */
   for (abfd = link_info.input_bfds; abfd; abfd = abfd->link.next)
     {
-      if (elf_tdata (abfd) != NULL
+      if (abfd->xvec->flavour == bfd_target_elf_flavour
+         && !bfd_input_just_syms (abfd)
+         && elf_tdata (abfd) != NULL
          && elf_tdata (abfd)->elf_header != NULL
          /* FIXME: Maybe check for other non-supportable types as well ?  */
          && elf_tdata (abfd)->elf_header->e_type == ET_EXEC)
@@ -1065,7 +1069,7 @@ ldelf_after_open (int use_libpath, int native, int is_linux, int is_freebsd,
        }
       return;
     }
-  
+
   if (!link_info.traditional_format)
     {
       bfd *elfbfd = NULL;
@@ -1076,13 +1080,6 @@ ldelf_after_open (int use_libpath, int native, int is_linux, int is_freebsd,
        {
          int type = 0;
 
-         if (bfd_link_executable (& link_info)
-             && elf_tdata (abfd)->elf_header->e_type == ET_EXEC)
-           {
-             einfo (_("%F%P: cannot use executable file '%pB' as input to a link\n"),
-                    abfd);
-           }
-
          if (bfd_input_just_syms (abfd))
            continue;
 
@@ -1092,7 +1089,7 @@ ldelf_after_open (int use_libpath, int native, int is_linux, int is_freebsd,
 
              if (bfd_is_abs_section (s->output_section))
                continue;
-             if (CONST_STRNEQ (name, ".eh_frame_entry"))
+             if (startswith (name, ".eh_frame_entry"))
                type = COMPACT_EH_HDR;
              else if (strcmp (name, ".eh_frame") == 0 && s->size > 8)
                type = DWARF2_EH_HDR;
@@ -1593,6 +1590,8 @@ ldelf_before_allocation (char *audit, char *depaudit,
                      (char *) &ehdr_start->u + sizeof ehdr_start->u.def.next,
                      sizeof ehdr_start_save_u);
              ehdr_start->type = bfd_link_hash_defined;
+             /* It will be converted to section-relative later.  */
+             ehdr_start->rel_from_abs = 1;
              ehdr_start->u.def.section = bfd_abs_section_ptr;
              ehdr_start->u.def.value = 0;
            }
@@ -1821,7 +1820,7 @@ output_rel_find (int isdyn, int rela)
        lookup = lookup->next)
     {
       if (lookup->constraint >= 0
-         && CONST_STRNEQ (lookup->name, ".rel"))
+         && startswith (lookup->name, ".rel"))
        {
          int lookrela = lookup->name[4] == 'a';
 
@@ -1972,7 +1971,7 @@ ldelf_place_orphan (asection *s, const char *secname, int constraint)
          default:
            break;
          }
-      else if (CONST_STRNEQ (secname, ".rel"))
+      else if (startswith (secname, ".rel"))
        {
          secname = secname[4] == 'a' ? ".rela.dyn" : ".rel.dyn";
          isdyn = 1;
@@ -2007,7 +2006,7 @@ ldelf_place_orphan (asection *s, const char *secname, int constraint)
            && (elf_section_data (os->bfd_section)->this_hdr.sh_info
                == elf_section_data (s)->this_hdr.sh_info))
            {
-             lang_add_section (&os->children, s, NULL, os);
+             lang_add_section (&os->children, s, NULL, NULL, os);
              return os;
            }
 
@@ -2050,7 +2049,7 @@ ldelf_place_orphan (asection *s, const char *secname, int constraint)
                        || !elfoutput
                        || elf_orphan_compatible (s, os->bfd_section)))))
          {
-           lang_add_section (&os->children, s, NULL, os);
+           lang_add_section (&os->children, s, NULL, NULL, os);
            return os;
          }
 
@@ -2064,7 +2063,7 @@ ldelf_place_orphan (asection *s, const char *secname, int constraint)
      unused one and use that.  */
   if (match_by_name)
     {
-      lang_add_section (&match_by_name->children, s, NULL, match_by_name);
+      lang_add_section (&match_by_name->children, s, NULL, NULL, match_by_name);
       return match_by_name;
     }
 
@@ -2085,11 +2084,11 @@ ldelf_place_orphan (asection *s, const char *secname, int constraint)
   /* If this is a final link, then always put .gnu.warning.SYMBOL
      sections into the .text section to get them out of the way.  */
   if (bfd_link_executable (&link_info)
-      && CONST_STRNEQ (s->name, ".gnu.warning.")
+      && startswith (s->name, ".gnu.warning.")
       && hold[orphan_text].os != NULL)
     {
       os = hold[orphan_text].os;
-      lang_add_section (&os->children, s, NULL, os);
+      lang_add_section (&os->children, s, NULL, NULL, os);
       return os;
     }
 
@@ -2125,7 +2124,7 @@ ldelf_place_orphan (asection *s, const char *secname, int constraint)
   else if ((flags & SEC_LOAD) != 0
           && (elfinput
               ? sh_type == SHT_NOTE
-              : CONST_STRNEQ (secname, ".note")))
+              : startswith (secname, ".note")))
     place = &hold[orphan_interp];
   else if ((flags & (SEC_LOAD | SEC_HAS_CONTENTS | SEC_THREAD_LOCAL)) == 0)
     place = &hold[orphan_bss];
@@ -2138,7 +2137,7 @@ ldelf_place_orphan (asection *s, const char *secname, int constraint)
   else if ((flags & SEC_LOAD) != 0
           && (elfinput
               ? sh_type == SHT_RELA || sh_type == SHT_REL
-              : CONST_STRNEQ (secname, ".rel")))
+              : startswith (secname, ".rel")))
     place = &hold[orphan_rel];
   else if ((flags & SEC_CODE) == 0)
     place = &hold[orphan_rodata];
@@ -2189,13 +2188,29 @@ ldelf_before_place_orphans (void)
               been discarded.  */
            asection *linked_to_sec;
            for (linked_to_sec = elf_linked_to_section (isec);
-                linked_to_sec != NULL;
+                linked_to_sec != NULL && !linked_to_sec->linker_mark;
                 linked_to_sec = elf_linked_to_section (linked_to_sec))
-             if (discarded_section (linked_to_sec))
-               {
-                 isec->output_section = bfd_abs_section_ptr;
-                 break;
-               }
+             {
+               if (discarded_section (linked_to_sec))
+                 {
+                   isec->output_section = bfd_abs_section_ptr;
+                   isec->flags |= SEC_EXCLUDE;
+                   break;
+                 }
+               linked_to_sec->linker_mark = 1;
+             }
+           for (linked_to_sec = elf_linked_to_section (isec);
+                linked_to_sec != NULL && linked_to_sec->linker_mark;
+                linked_to_sec = elf_linked_to_section (linked_to_sec))
+             linked_to_sec->linker_mark = 0;
          }
       }
 }
+
+void
+ldelf_set_output_arch (void)
+{
+  set_output_arch_default ();
+  if (link_info.output_bfd->xvec->flavour == bfd_target_elf_flavour)
+    elf_link_info (link_info.output_bfd) = &link_info;
+}
This page took 0.038336 seconds and 4 git commands to generate.