aboutsummaryrefslogtreecommitdiff
path: root/ld/lexsup.c
diff options
context:
space:
mode:
authorNick Clifton <nickc@redhat.com>2023-11-10 11:37:27 +0000
committerNick Clifton <nickc@redhat.com>2023-11-10 11:37:27 +0000
commite922d1eaa3774a68c96eae01e0fd08f8a30cda8c (patch)
tree6d9c2ebe96dd8c440f848518bd2d087045de52ed /ld/lexsup.c
parenta73c0d9b228cb11d4dd9c045c692229ff6b7b06a (diff)
downloadgdb-e922d1eaa3774a68c96eae01e0fd08f8a30cda8c.zip
gdb-e922d1eaa3774a68c96eae01e0fd08f8a30cda8c.tar.gz
gdb-e922d1eaa3774a68c96eae01e0fd08f8a30cda8c.tar.bz2
Add ability to change linker warning messages into errors when reporting executable stacks and/or executable segments.
include * bfdlink.h (struct bfd_link_info): Update descriptions of the 'execstack', 'noexecstack' and 'warn_execstack' fields. Add 'error_exectack' and 'warn_is_error_for_rwx_segments' fields. bfd * elf.c (assign_file_positions_except_relocs): Turn warnings about executable segments into errors if so requested. * elflink.c (bfd_elf_size_dynamic_sections): Turn warnings about executable stacks into errors if so requested. ld * ldlex.h (enum option_values): Add OPTION_ERROR_EXECSTACK, OPTION_NO_ERROR_EXECSTACK, OPTION_WARN_EXECSTACK_OBJECTS, OPTION_ERROR_RWX_SEGMENTS and OPTION_NO_ERROR_RWX_SEGMENTS. (struct ld_option): Add new long options. (parse_args): Parse new long options. (elf_static_list_options): Display the new options. * ld.texi: Document the new command line options. * configure.ac (error-execstack): New configuration option. (error-rwx-segments): New configuration option. * emultempl/elf.em (_before_parse): Initialse the new linkinfo fields. * NEWS: Mention the new features. * config.in: Regenerate. * configure: Regenerate. * testsuite/ld-elf/commonpage2.d: Disable errors for RWX segments and/or executable stacks. * testsuite/ld-elf/elf.exp: Likewise. * testsuite/ld-elf/header.d: Likewise. * testsuite/ld-elf/loadaddr1.d: Likewise. * testsuite/ld-elf/loadaddr2.d: Likewise. * testsuite/ld-elf/maxpage4.d: Likewise. * testsuite/ld-elf/nobits-1.d: Likewise. * testsuite/ld-elf/note-1.d: Likewise. * testsuite/ld-elf/orphan-10.d: Likewise. * testsuite/ld-elf/orphan-11.d: Likewise. * testsuite/ld-elf/orphan-12.d: Likewise. * testsuite/ld-elf/orphan-5.d: Likewise. * testsuite/ld-elf/orphan-7.d: Likewise. * testsuite/ld-elf/orphan-8.d: Likewise. * testsuite/ld-elf/orphan-9.d: Likewise. * testsuite/ld-elf/orphan-region.d: Likewise. * testsuite/ld-elf/orphan.d: Likewise. * testsuite/ld-elf/pr19539.d: Likewise. * testsuite/ld-elf/pr26256-1a.d: Likewise. * testsuite/ld-elf/pr26907.d: Likewise. * testsuite/ld-elf/pr28597.d: Likewise. * testsuite/ld-elf/retain2.d: Likewise. * testsuite/ld-elf/shared.exp: Likewise. * testsuite/ld-elf/size-1.d: Likewise. * testsuite/ld-elf/textaddr7.d: Likewise. * testsuite/ld-elf/warn1.d: Likewise. * testsuite/ld-elf/warn2.d: Likewise. * testsuite/ld-i386/discarded1.d: Likewise. * testsuite/ld-i386/pr19175.d: Likewise. * testsuite/ld-i386/pr19539.d: Likewise. * testsuite/ld-i386/pr23189.d: Likewise. * testsuite/ld-plugin/lto-3r.d: Likewise. * testsuite/ld-plugin/lto-5r.d: Likewise. * testsuite/ld-plugin/lto.exp: Likewise. * testsuite/ld-powerpc/ppc476-shared.d: Likewise. * testsuite/ld-powerpc/ppc476-shared2.d: Likewise. * testsuite/ld-powerpc/pr28827-2.d: Likewise. * testsuite/ld-s390/s390.exp: Likewise. * testsuite/ld-scripts/align2a.d: Likewise. * testsuite/ld-scripts/align2b.d: Likewise. * testsuite/ld-scripts/align5.d: Likewise. * testsuite/ld-scripts/alignof.exp: Likewise. * testsuite/ld-scripts/crossref.exp: Likewise. * testsuite/ld-scripts/defined2.d: Likewise. * testsuite/ld-scripts/defined3.d: Likewise. * testsuite/ld-scripts/defined5.d: Likewise. * testsuite/ld-scripts/pr14962.d: Likewise. * testsuite/ld-scripts/pr18963.d: Likewise. * testsuite/ld-scripts/pr20302.d: Likewise. * testsuite/ld-scripts/print-memory-usage.exp: Likewise. * testsuite/ld-scripts/rgn-at1.d: Likewise. * testsuite/ld-scripts/rgn-at10.d: Likewise. * testsuite/ld-scripts/rgn-at4.d: Likewise. * testsuite/ld-scripts/rgn-at6.d: Likewise. * testsuite/ld-scripts/rgn-at8.d: Likewise. * testsuite/ld-scripts/rgn-at9.d: Likewise. * testsuite/ld-scripts/rgn-over1.d: Likewise. * testsuite/ld-scripts/rgn-over2.d: Likewise. * testsuite/ld-scripts/rgn-over4.d: Likewise. * testsuite/ld-scripts/rgn-over5.d: Likewise. * testsuite/ld-scripts/rgn-over6.d: Likewise. * testsuite/ld-scripts/script.exp: Likewise. * testsuite/ld-scripts/sizeof.exp: Likewise. * testsuite/ld-scripts/sort-file.d: Likewise. * testsuite/ld-x86-64/discarded1.d: Likewise. * testsuite/ld-x86-64/pr19175.d: Likewise. * testsuite/ld-x86-64/pr19539a.d: Likewise. * testsuite/ld-x86-64/pr19539b.d: Likewise. * testsuite/ld-x86-64/pr23189.d: Likewise.
Diffstat (limited to 'ld/lexsup.c')
-rw-r--r--ld/lexsup.c64
1 files changed, 54 insertions, 10 deletions
diff --git a/ld/lexsup.c b/ld/lexsup.c
index 49dfc13..aa4c76e 100644
--- a/ld/lexsup.c
+++ b/ld/lexsup.c
@@ -551,14 +551,27 @@ static const struct ld_option ld_options[] =
{ {"warn-constructors", no_argument, NULL, OPTION_WARN_CONSTRUCTORS},
'\0', NULL, N_("Warn if global constructors/destructors are seen"),
TWO_DASHES },
+
+ { {"error-execstack", no_argument, NULL, OPTION_ERROR_EXECSTACK},
+ '\0', NULL, NULL, TWO_DASHES },
+ { {"no-error-execstack", no_argument, NULL, OPTION_NO_ERROR_EXECSTACK},
+ '\0', NULL, NULL, TWO_DASHES },
+ { {"warn-execstack-objects", no_argument, NULL, OPTION_WARN_EXECSTACK_OBJECTS},
+ '\0', NULL, NULL, TWO_DASHES },
{ {"warn-execstack", no_argument, NULL, OPTION_WARN_EXECSTACK},
- '\0', NULL, N_("Warn when creating an executable stack"), TWO_DASHES },
+ '\0', NULL, NULL, TWO_DASHES },
{ {"no-warn-execstack", no_argument, NULL, OPTION_NO_WARN_EXECSTACK},
- '\0', NULL, N_("Do not warn when creating an executable stack"), TWO_DASHES },
+ '\0', NULL, NULL, TWO_DASHES },
+
+ { {"error-rwx-segments", no_argument, NULL, OPTION_ERROR_RWX_SEGMENTS},
+ '\0', NULL, NULL, TWO_DASHES },
+ { {"no-error-rwx-segments", no_argument, NULL, OPTION_NO_ERROR_RWX_SEGMENTS},
+ '\0', NULL, NULL, TWO_DASHES },
{ {"warn-rwx-segments", no_argument, NULL, OPTION_WARN_RWX_SEGMENTS},
- '\0', NULL, N_("Warn when creating executable segments"), TWO_DASHES },
+ '\0', NULL, NULL, TWO_DASHES },
{ {"no-warn-rwx-segments", no_argument, NULL, OPTION_NO_WARN_RWX_SEGMENTS},
- '\0', NULL, N_("Do not warn when creating executable segments"), TWO_DASHES },
+ '\0', NULL, NULL, TWO_DASHES },
+
{ {"warn-multiple-gp", no_argument, NULL, OPTION_WARN_MULTIPLE_GP},
'\0', NULL, N_("Warn if the multiple GP values are used"), TWO_DASHES },
{ {"warn-once", no_argument, NULL, OPTION_WARN_ONCE},
@@ -944,12 +957,29 @@ parse_args (unsigned argc, char **argv)
case OPTION_NON_CONTIGUOUS_REGIONS_WARNINGS:
link_info.non_contiguous_regions_warnings = true;
break;
+
+ case OPTION_ERROR_EXECSTACK:
+ link_info.error_execstack = 1;
+ break;
+ case OPTION_NO_ERROR_EXECSTACK:
+ link_info.error_execstack = 0;
+ break;
+ case OPTION_WARN_EXECSTACK_OBJECTS:
+ link_info.warn_execstack = 2;
+ break;
case OPTION_WARN_EXECSTACK:
link_info.warn_execstack = 1;
break;
case OPTION_NO_WARN_EXECSTACK:
link_info.warn_execstack = 0;
break;
+
+ case OPTION_ERROR_RWX_SEGMENTS:
+ link_info.warn_is_error_for_rwx_segments = 1;
+ break;
+ case OPTION_NO_ERROR_RWX_SEGMENTS:
+ link_info.warn_is_error_for_rwx_segments = 0;
+ break;
case OPTION_WARN_RWX_SEGMENTS:
link_info.no_warn_rwx_segments = 0;
link_info.user_warn_rwx_segments = 1;
@@ -958,6 +988,7 @@ parse_args (unsigned argc, char **argv)
link_info.no_warn_rwx_segments = 1;
link_info.user_warn_rwx_segments = 1;
break;
+
case 'e':
lang_add_entry (optarg, true);
break;
@@ -2239,24 +2270,32 @@ elf_static_list_options (FILE *file)
-z muldefs Allow multiple definitions\n"));
fprintf (file, _("\
-z stack-size=SIZE Set size of stack segment\n"));
+
fprintf (file, _("\
-z execstack Mark executable as requiring executable stack\n"));
fprintf (file, _("\
- -z noexecstack Mark executable as not requiring executable stack\n"));
-#if DEFAULT_LD_WARN_EXECSTACK == 1
+ -z noexecstack Mark executable as not requiring executable stack\n"));
fprintf (file, _("\
- --warn-execstack Generate a warning if the stack is executable (default)\n"));
+ --warn-execstack-objects Generate a warning if an object file requests an executable stack\n"));
+#if DEFAULT_LD_WARN_EXECSTACK == 0
+ fprintf (file, _("\
+ --warn-execstack Generate a warning if creating an executable stack\n"));
#else
fprintf (file, _("\
- --warn-execstack Generate a warning if the stack is executable\n"));
+ --warn-execstack Generate a warning if creating an executable stack (default)\n"));
#endif
#if DEFAULT_LD_WARN_EXECSTACK == 0
fprintf (file, _("\
- --no-warn-execstack Do not generate a warning if the stack is executable (default)\n"));
+ --no-warn-execstack Do not generate a warning if creating an executable stack (default)\n"));
#else
fprintf (file, _("\
- --no-warn-execstack Do not generate a warning if the stack is executable\n"));
+ --no-warn-execstack Do not generate a warning if creating an executable stack\n"));
#endif
+ fprintf (file, _("\
+ --error-execstack Turn warnings about executable stacks into errors\n"));
+ fprintf (file, _("\
+ --no-error-execstack Do not turn warnings about executable stacks into errors\n"));
+
#if DEFAULT_LD_WARN_RWX_SEGMENTS
fprintf (file, _("\
--warn-rwx-segments Generate a warning if a LOAD segment has RWX permissions (default)\n"));
@@ -2269,6 +2308,11 @@ elf_static_list_options (FILE *file)
--no-warn-rwx-segments Do not generate a warning if a LOAD segments has RWX permissions (default)\n"));
#endif
fprintf (file, _("\
+ --error-rwx-segments Turn warnings about loadable RWX segments into errors\n"));
+ fprintf (file, _("\
+ --no-error-rwx-segments Do not turn warnings about loadable RWX segments into errors\n"));
+
+ fprintf (file, _("\
-z unique-symbol Avoid duplicated local symbol names\n"));
fprintf (file, _("\
-z nounique-symbol Keep duplicated local symbol names (default)\n"));