Hi Guys,
I have just updated PR 26047 with a suggested patch which I think could
resolve
this situation. (Patch attached here as well in order to save time). It adds
a new linker command line option: -z allowexec which will disable the
warnings
about linking in executable files. The default is still to have these
warnings
as I think that in most cases this behaviour makes sense.
Will this solve the problem for you ?
Cheers
Nick
diff --git a/include/bfdlink.h b/include/bfdlink.h
index 7163433383..d9c0fe6367 100644
--- a/include/bfdlink.h
+++ b/include/bfdlink.h
@@ -520,6 +520,10 @@ struct bfd_link_info
the linker. */
unsigned int non_contiguous_regions_warnings : 1;
+ /* TRUE if "-z allowexec" has been set in order to allow use of
+ executable files (ELF type ET_EXEC) as inputs to a link. */
+ unsigned int allow_exec_input : 1;
+
/* Char that may appear as the first char of a symbol, but should be
skipped (like symbol_leading_char) when looking up symbols in
wrap_hash. Used by PowerPC Linux for 'dot' symbols. */
diff --git a/ld/NEWS b/ld/NEWS
index eb2cff12ea..544d1324e1 100644
--- a/ld/NEWS
+++ b/ld/NEWS
@@ -1,5 +1,8 @@
-*- text -*-
+~ Add -z allowexec command line option to permit the use of executable files as
+ inputs to a link.
+
Changes in 2.35:
* X86 NaCl target support is removed.
diff --git a/ld/emultempl/elf.em b/ld/emultempl/elf.em
index 356f34538b..538f8a096c 100644
--- a/ld/emultempl/elf.em
+++ b/ld/emultempl/elf.em
@@ -708,6 +708,10 @@ fragment <<EOF
case 'z':
if (strcmp (optarg, "defs") == 0)
link_info.unresolved_syms_in_objects = RM_DIAGNOSE;
+ else if (strcmp (optarg, "allowexec") == 0)
+ link_info.allow_exec_input = TRUE;
+ else if (strcmp (optarg, "noallowexec") == 0)
+ link_info.allow_exec_input = FALSE;
else if (strcmp (optarg, "undefs") == 0)
link_info.unresolved_syms_in_objects = RM_IGNORE;
else if (strcmp (optarg, "muldefs") == 0)
diff --git a/ld/ld.texi b/ld/ld.texi
index 165a3d935e..49e63abe6f 100644
--- a/ld/ld.texi
+++ b/ld/ld.texi
@@ -1207,6 +1207,12 @@ for Solaris compatibility.
The recognized keywords are:
@table @samp
+@item allowexec
+@itemx noallowexec
+Allow or prevent executable files (ELF type ET_EXEC) as inputs to a
+link. The default is to prevent their inclusion, but there are some
+situations in which they are needed.
+
@item bndplt
Always generate BND prefix in PLT entries. Supported for Linux/x86_64.
diff --git a/ld/ldelf.c b/ld/ldelf.c
index 6fa09cfe6f..f2a6a5690b 100644
--- a/ld/ldelf.c
+++ b/ld/ldelf.c
@@ -1040,15 +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)
+ /* PR 26047: Do not allow executable files to be used as inputs
+ to the link unless specifically requested by the user. */
+ if (!link_info.allow_exec_input)
{
- 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);
+ 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))
@@ -1078,12 +1082,13 @@ ldelf_after_open (int use_libpath, int native, int is_linux, int is_freebsd,
{
int type = 0;
- if (bfd_link_executable (& link_info)
+ /* PR 26047: Do not allow executable files to be used as inputs
+ to the link unless specifically requested by the user. */
+ if (!link_info.allow_exec_input
+ && 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);
- }
+ einfo (_("%F%P: cannot use executable file '%pB' as input to a link\n"),
+ abfd);
if (bfd_input_just_syms (abfd))
continue;
diff --git a/ld/lexsup.c b/ld/lexsup.c
index a79bec0b45..017fecdaa8 100644
--- a/ld/lexsup.c
+++ b/ld/lexsup.c
@@ -2022,6 +2022,8 @@ elf_static_list_options (FILE *file)
-z noexecstack Mark executable as not requiring executable stack\n"));
fprintf (file, _("\
-z globalaudit Mark executable requiring global auditing\n"));
+ fprintf (file, _("\
+ -z allowexec Allow executable files as inputs to the link\n"));
}
static void
_______________________________________________
SeaBIOS mailing list -- [email protected]
To unsubscribe send an email to [email protected]