Have the linker fail if any attempt to link in an executable is made.
authorNick Clifton <nickc@redhat.com>
Thu, 28 May 2020 16:43:21 +0000 (17:43 +0100)
committerNick Clifton <nickc@redhat.com>
Thu, 28 May 2020 16:43:21 +0000 (17:43 +0100)
PR 26047
* ldelf.c (ldelf_after_open): Fail if attempting to link one
executable into another.  Ensure that the test is made for all
forms of linking.

ld/ChangeLog
ld/ldelf.c

index 096b9a5398c4ec0b601fd857bc4ded573f3df995..28999bc49b69b3b5be772be47a47c8b974b25d7f 100644 (file)
@@ -2,7 +2,8 @@
 
        PR 26047
        * ldelf.c (ldelf_after_open): Fail if attempting to link one
-       executable into another.
+       executable into another.  Ensure that the test is made for all
+       forms of linking.
 
 2020-05-28  H.J. Lu  <hongjiu.lu@intel.com>
 
index 475fd000e6bcae9b1e9aad87439e6068a069a01d..8f2167e8895ef3bdd5029ff2f5c247ad868c3617 100644 (file)
@@ -1038,6 +1038,17 @@ 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 (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)
@@ -1054,7 +1065,7 @@ ldelf_after_open (int use_libpath, int native, int is_linux, int is_freebsd,
        }
       return;
     }
-
+  
   if (!link_info.traditional_format)
     {
       bfd *elfbfd = NULL;
This page took 0.028233 seconds and 4 git commands to generate.