elf: Set rel_from_abs to 1 for __ehdr_start
[deliverable/binutils-gdb.git] / ld / ldelf.c
index 475fd000e6bcae9b1e9aad87439e6068a069a01d..5cfddef39b3d22aff90fac9e9c0acbbad4930024 100644 (file)
@@ -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;
 
@@ -1038,6 +1040,19 @@ ldelf_after_open (int use_libpath, int native, int is_linux, int is_freebsd,
 
   get_elf_backend_data (link_info.output_bfd)->setup_gnu_properties (&link_info);
 
+  /* 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 (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)
+       einfo (_("%F%P: cannot use executable file '%pB' as input to a link\n"),
+              abfd);
+    }
+
   if (bfd_link_relocatable (&link_info))
     {
       if (link_info.execstack == !link_info.noexecstack)
@@ -1065,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;
 
@@ -1582,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;
            }
@@ -2183,6 +2193,7 @@ ldelf_before_place_orphans (void)
              if (discarded_section (linked_to_sec))
                {
                  isec->output_section = bfd_abs_section_ptr;
+                 isec->flags |= SEC_EXCLUDE;
                  break;
                }
          }
This page took 0.036792 seconds and 4 git commands to generate.