This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Need some help with a patch for new command --warn-execstack for ld
- From: Magnus Granberg <zorry at gentoo dot org>
- To: binutils at sourceware dot org
- Date: Sat, 15 May 2010 14:51:14 +0200
- Subject: Need some help with a patch for new command --warn-execstack for ld
Hi
This patch started in the gcc-patches ml http://gcc.gnu.org/ml/gcc-patches/2010-05/msg00352.html
Have move the warning from gcc to ld now. Need some help with.
1. To get the object file .o (Y in the patch).
2. To get the symbol or function that need the execstack (X in the patch).
/Magnus
---
--- a/ld/ld.h 2009-09-14 13:43:29.000000000 +0200
+++ b/ld/ld.h 2010-05-11 22:26:43.000000000 +0200
@@ -241,6 +241,12 @@
/* If TRUE, warn about merging common symbols with others. */
bfd_boolean warn_common;
+ /* If TRUE, warn about execstack. */
+ /* ??? A better way to do this is perhaps to define this in the
+ ld_emulation_xfer_struct since this is really a target dependent
+ parameter. */
+ bfd_boolean warn_execstack;
+
/* If TRUE, only warn once about a particular undefined symbol. */
bfd_boolean warn_once;
--- a/ld/emultempl/elf32.em 2009-09-14 13:43:30.000000000 +0200
+++ b/ld/emultempl/elf32.em 2010-05-11 22:07:27.000000000 +0200
@@ -1396,6 +1396,37 @@
fi
fragment <<EOF
+static
+warn_execstack_check (bfd *output_bfd, struct bfd_link_info *info)
+{
+ const struct elf_backend_data *bed;
+ bed = get_elf_backend_data (output_bfd);
+ if (info->execstack)
+ einfo ("ld: warning: -z execstack has been passed to the command line and it will mark executable as requiring executable stack\n");
+ else
+ {
+ bfd *inputobj;
+ for (inputobj = info->input_bfds;
+ inputobj;
+ inputobj = inputobj->link_next)
+ {
+ asection *s;
+
+ if (inputobj->flags & (DYNAMIC | EXEC_P | BFD_LINKER_CREATED))
+ continue;
+ s = bfd_get_section_by_name (inputobj, ".note.GNU-stack");
+ if (s)
+ {
+ if (s->flags & SEC_CODE)
+ einfo ("ld: Y: warning: function X requiring executable stack\n");
+ }
+ else if (bed->default_execstack)
+ einfo ("ld: Y: warning: function X requiring executable stack but object Y miss the .note.GNU-stack\n");
+ }
+ }
+ return 0;
+}
+
/* This is called after the sections have been attached to output
sections, but before any sizes or addresses have been set. */
@@ -1424,6 +1455,8 @@
(const char * const *) command_line.auxiliary_filters,
&link_info, &sinterp, lang_elf_version_info)))
einfo ("%P%F: failed to set dynamic section sizes: %E\n");
+ if (config.warn_execstack)
+ warn_execstack_check (link_info.output_bfd, &link_info);
${ELF_INTERPRETER_SET_DEFAULT}
/* Let the user override the dynamic linker we are using. */
@@ -2007,6 +2007,7 @@
#define OPTION_EXCLUDE_LIBS (OPTION_EH_FRAME_HDR + 1)
#define OPTION_HASH_STYLE (OPTION_EXCLUDE_LIBS + 1)
#define OPTION_BUILD_ID (OPTION_HASH_STYLE + 1)
+#define OPTION_WARN_EXECSTACK (OPTION_BUILD_ID + 1)
static void
gld${EMULATION_NAME}_add_options
@@ -2026,6 +2027,7 @@
{"exclude-libs", required_argument, NULL, OPTION_EXCLUDE_LIBS},
{"hash-style", required_argument, NULL, OPTION_HASH_STYLE},
{"Bgroup", no_argument, NULL, OPTION_GROUP},
+ {"warn-execstack", no_argument, NULL, OPTION_WARN_EXECSTACK},
EOF
fi
@@ -2111,6 +2113,10 @@
einfo (_("%P%F: invalid hash style \`%s'\n"), optarg);
break;
+ case OPTION_WARN_EXECSTACK:
+ config.warn_execstack = TRUE;
+ break;
+
case 'z':
if (strcmp (optarg, "initfirst") == 0)
link_info.flags_1 |= (bfd_vma) DF_1_INITFIRST;
@@ -2233,6 +2239,8 @@
fprintf (file, _("\
--hash-style=STYLE Set hash style to sysv, gnu or both\n"));
fprintf (file, _("\
+ --warn-execstack Warn when stack requiring executable stack\n"));
+ fprintf (file, _("\
-z combreloc Merge dynamic relocs into one section and sort\n"));
fprintf (file, _("\
-z defs Report unresolved symbols in object files.\n"));