ld: don't generate base relocations in PE output for absolute symbols
[deliverable/binutils-gdb.git] / ld / ldelf.c
index 729239c101e1ba83a7423456f0b2315a5f2f3dd2..049992544a26a780ce57922e23e445524f51c4a1 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.
 
@@ -1043,7 +1043,8 @@ 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 (!bfd_input_just_syms (abfd)
+      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 ?  */
@@ -1589,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;
            }
@@ -2003,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;
            }
 
@@ -2046,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;
          }
 
@@ -2060,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,7 +2088,7 @@ ldelf_place_orphan (asection *s, const char *secname, int constraint)
       && 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;
     }
 
@@ -2185,13 +2188,21 @@ 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;
          }
       }
 }
This page took 0.027185 seconds and 4 git commands to generate.