[binutils-gdb] Have the linker fail if any attempt to link in an executable is made.

Nick Clifton nickc@sourceware.org
Thu May 28 16:44:02 GMT 2020


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=a87e1817a435dab6c6c042f9306497c9f13d4236

commit a87e1817a435dab6c6c042f9306497c9f13d4236
Author: Nick Clifton <nickc@redhat.com>
Date:   Thu May 28 17:43:21 2020 +0100

    Have the linker fail if any attempt to link in an executable is made.
    
            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.

Diff:
---
 ld/ChangeLog |  3 ++-
 ld/ldelf.c   | 13 ++++++++++++-
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/ld/ChangeLog b/ld/ChangeLog
index 096b9a5398c..28999bc49b6 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -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>
 
diff --git a/ld/ldelf.c b/ld/ldelf.c
index 475fd000e6b..8f2167e8895 100644
--- a/ld/ldelf.c
+++ b/ld/ldelf.c
@@ -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;


More information about the Binutils-cvs mailing list