% as /dev/null -o a.o % ld.bfd a.o -o a ld.bfd: warning: cannot find entry symbol _start; defaulting to 0000000000401000 # a is an ET_EXEC ## GNU ld allows input ET_EXEC like an ET_REL % ld.bfd a -o b ld.bfd: warning: cannot find entry symbol _start; not setting start address ## gold disallows input ET_EXEC % gold a -o b gold: error: a: unsupported ELF file type 2 Accepting ET_EXEC may cause problems which will be hard to diagnose. The Linux kernel for a narrow window misused ET_EXEC as an input, which was fixed by my https://git.kernel.org/torvalds/c/90ceddcb495008ac8ba7a3dce297841efcd7d584
The master branch has been updated by Nick Clifton <nickc@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=a3fc941881e4224eff3ef20ba1e784026bcc17fa commit a3fc941881e4224eff3ef20ba1e784026bcc17fa Author: Nick Clifton <nickc@redhat.com> Date: Thu May 28 16:43:01 2020 +0100 Stop the linker from accepting executable ELF files as inputs to other links. PR 26047 * ldelf.c (ldelf_after_open): Fail if attempting to link one executable into another.
OK, I have applied an initial patch, although I suspect that it will need to be enhanced. At the moment the check does not trigger if performing a relocatable link or if the --traditional-format option is used. I suspect that both of these restrictions need to be removed.
The master branch has been updated by Nick Clifton <nickc@sourceware.org>: 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.
OK, that is better. The test should now be performed for all kinds of linking.
Created attachment 12688 [details] Proposed patch Hi Guys, It turns out that there are occasions when linking in executable files does make sense, so I am suggesting this patch as a solution. It provides a new linker command line option: -z allowexec which if used disables all warnings about linking in executable files. Comments/questions ? Cheers Nick
(In reply to Nick Clifton from comment #5) > It turns out that there are occasions when linking in executable files > does make sense, so I am suggesting this patch as a solution. It provides a > new linker command line option: -z allowexec which if used disables all > warnings about linking in executable files. > > Comments/questions ? Could you add some ELF test cases for linking against versioned symbols defined in the executable? In particular, it's not clear what to record as the soname in the version records.
The master branch has been updated by Maciej W. Rozycki <macro@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=b5dd7120f6bcbd1fe650b8839a53b2bd423fbf60 commit b5dd7120f6bcbd1fe650b8839a53b2bd423fbf60 Author: Maciej W. Rozycki <macro@wdc.com> Date: Thu Jul 23 20:11:29 2020 +0100 PR ld/26288: Revert obsolete part of PR ld/26047 fix Revert commit a3fc941881e4 ("Stop the linker from accepting executable ELF files as inputs to other links."), which has been made obsolete by commit a87e1817a435 ("Have the linker fail if any attempt to link in an executable is made."). An earlier check triggers added with the latter commit making the piece of code removed dead. ld/ PR ld/26288 Revert: PR 26047 * ldelf.c (ldelf_after_open): Fail if attempting to link one executable into another.
The binutils-2_35-branch branch has been updated by Maciej W. Rozycki <macro@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=9b6165529df6a759d65fc786a44eb28e226b81ad commit 9b6165529df6a759d65fc786a44eb28e226b81ad Author: Maciej W. Rozycki <macro@wdc.com> Date: Thu Jul 23 20:24:58 2020 +0100 PR ld/26288: Revert obsolete part of PR ld/26047 fix Revert commit a3fc941881e4 ("Stop the linker from accepting executable ELF files as inputs to other links."), which has been made obsolete by commit a87e1817a435 ("Have the linker fail if any attempt to link in an executable is made."). An earlier check triggers added with the latter commit making the piece of code removed dead. ld/ PR ld/26288 Revert: PR 26047 * ldelf.c (ldelf_after_open): Fail if attempting to link one executable into another. (cherry picked from commit b5dd7120f6bcbd1fe650b8839a53b2bd423fbf60)