]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
ld: Add --no-print-map-discarded option
authorFaraz Shahbazker <fshahbazker@wavecomp.com>
Tue, 2 Apr 2019 20:17:16 +0000 (20:17 +0000)
committerFaraz Shahbazker <fshahbazker@wavecomp.com>
Thu, 11 Apr 2019 17:16:31 +0000 (10:16 -0700)
Add a new option to disable the listing of discarded sections
in map file output.  The use case stems from a large application
built with -ffunction-sections --gc-sections where the list of
discarded sections blows up the map file output.  The default
behaviour remains to print discarded sections,  but the new option
allows us to disable it.

ld/
* NEWS: Mention new option --no-print-map-discarded.
* ld.h (ld_config_type) <print_map_discarded>: New field.
* ldlang.c (lang_map): Conditionally output discarded sections
in map files based on configuration option.
* ldlex.h (option_values) <OPTION_PRINT_MAP_DISCARDED,
OPTION_NO_PRINT_MAP_DISCARDED>: New.
* ldmain.c (main): Enabled print_map_discarded by default.
* lexsup.c (ld_options): Add new command-line options.
(parse_args) <OPTION_NO_PRINT_MAP_DISCARDED,
OPTION_PRINT_MAP_DISCARDED>: New cases.
* ld.texi: Document new options.
* testsuite/ld-gc/gc.exp: Add new test.
* testsuite/ld-gc/skip-map-discarded.s: New file.
* testsuite/ld-gc/skip-map-discarded.d: New file.
* testsuite/ld-gc/skip-map-discarded.map: New file.

12 files changed:
ld/ChangeLog
ld/NEWS
ld/ld.h
ld/ld.texi
ld/ldlang.c
ld/ldlex.h
ld/ldmain.c
ld/lexsup.c
ld/testsuite/ld-gc/gc.exp
ld/testsuite/ld-gc/skip-map-discarded.d [new file with mode: 0644]
ld/testsuite/ld-gc/skip-map-discarded.map [new file with mode: 0644]
ld/testsuite/ld-gc/skip-map-discarded.s [new file with mode: 0644]

index 8e6a2d423fe771fe7645a637ad4f6455275cf442..c8eda47e2f5d8c16984a0f79e0d6aa93b2880a6a 100644 (file)
@@ -1,3 +1,21 @@
+2019-04-11  Faraz Shahbazker  <fshahbazker@wavecomp.com>
+
+       * NEWS: Mention new option --no-print-map-discarded.
+       * ld.h (ld_config_type) <print_map_discarded>: New field.
+       * ldlang.c (lang_map): Conditionally output discarded sections
+       in map files based on configuration option.
+       * ldlex.h (option_values) <OPTION_PRINT_MAP_DISCARDED,
+       OPTION_NO_PRINT_MAP_DISCARDED>: New.
+       * ldmain.c (main): Enabled print_map_discarded by default.
+       * lexsup.c (ld_options): Add new command-line options.
+       (parse_args) <OPTION_NO_PRINT_MAP_DISCARDED,
+       OPTION_PRINT_MAP_DISCARDED>: New cases.
+       * ld.texi: Document new options.
+       * testsuite/ld-gc/gc.exp: Add new test.
+       * testsuite/ld-gc/skip-map-discarded.s: New file.
+       * testsuite/ld-gc/skip-map-discarded.d: New file.
+       * testsuite/ld-gc/skip-map-discarded.map: New file.
+
 2019-04-11  H.J. Lu  <hongjiu.lu@intel.com>
 
        * ld.texi: Document -z cet-report=[none|warning|error].
diff --git a/ld/NEWS b/ld/NEWS
index 597845a351f3dac787579cf43b4d9056ea373bb3..de2cd16c4ef1bd725a15e447be766a441d598564 100644 (file)
--- a/ld/NEWS
+++ b/ld/NEWS
@@ -1,5 +1,7 @@
 -*- text -*-
 
+* Add command-line option --no-print-map-discarded.
+
 Changes in 2.33:
 
 * Add target handlers for AArch64 for ELF GNU program properties.
diff --git a/ld/ld.h b/ld/ld.h
index b97d977f37b3a9fbda584b49395aca7ab79ee75e..55078a9637b9ad09f18ef58ae44c6ff089ddb3f4 100644 (file)
--- a/ld/ld.h
+++ b/ld/ld.h
@@ -318,6 +318,9 @@ typedef struct
 
   /* The common page size for ELF.  */
   bfd_vma commonpagesize;
+
+  /* If set, print discarded sections in map file output.  */
+  bfd_boolean print_map_discarded;
 } ld_config_type;
 
 extern ld_config_type config;
index 8e2ce869f86c47ac1bb81b33fa58a9463b8c2c59..71c8d2599b83f73fe16d42b06a13f2833258fe55 100644 (file)
@@ -783,6 +783,14 @@ when merging properties in  @file{foo.o}, whose 0xc0010001 property value
 is 0x1, and @file{bar.o}, whose 0xc0010001 property value is 0x1.
 @end itemize
 
+@cindex link map discarded
+@kindex --print-map-discarded
+@kindex --no-print-map-discarded
+@item --print-map-discarded
+@itemx --no-print-map-discarded
+Print (or do not print) the list of discarded and garbage collected sections
+in the link map.  Enabled by default.
+
 @kindex -n
 @cindex read-only text
 @cindex NMAGIC
index 1952d4a475c26b1728da8c3426b00eafc7b7da35..898735efab59a0d3a0494d4a54efcee62c042153 100644 (file)
@@ -2251,19 +2251,20 @@ lang_map (void)
          || file->flags.just_syms)
        continue;
 
-      for (s = file->the_bfd->sections; s != NULL; s = s->next)
-       if ((s->output_section == NULL
-            || s->output_section->owner != link_info.output_bfd)
-           && (s->flags & (SEC_LINKER_CREATED | SEC_KEEP)) == 0)
-         {
-           if (!dis_header_printed)
-             {
-               fprintf (config.map_file, _("\nDiscarded input sections\n\n"));
-               dis_header_printed = TRUE;
-             }
+      if (config.print_map_discarded)
+       for (s = file->the_bfd->sections; s != NULL; s = s->next)
+         if ((s->output_section == NULL
+              || s->output_section->owner != link_info.output_bfd)
+             && (s->flags & (SEC_LINKER_CREATED | SEC_KEEP)) == 0)
+           {
+             if (! dis_header_printed)
+               {
+                 fprintf (config.map_file, _("\nDiscarded input sections\n\n"));
+                 dis_header_printed = TRUE;
+               }
 
-           print_input_section (s, TRUE);
-         }
+             print_input_section (s, TRUE);
+           }
     }
 
   minfo (_("\nMemory Configuration\n\n"));
index 32853debe45738685bea60e22aaddbbde27ff8ae..32a7a6409e8e88e9b316636c4e6b435821e3ab9b 100644 (file)
@@ -148,6 +148,8 @@ enum option_values
   OPTION_REQUIRE_DEFINED_SYMBOL,
   OPTION_ORPHAN_HANDLING,
   OPTION_FORCE_GROUP_ALLOCATION,
+  OPTION_PRINT_MAP_DISCARDED,
+  OPTION_NO_PRINT_MAP_DISCARDED,
 };
 
 /* The initial parser states.  */
index 77cdbd0dd29146b70e5cd32cd38448fd8370a760..da1c6a7658f1c41fed33c98f314d8d996f2aab0d 100644 (file)
@@ -264,6 +264,7 @@ main (int argc, char **argv)
   config.make_executable = TRUE;
   config.magic_demand_paged = TRUE;
   config.text_read_only = TRUE;
+  config.print_map_discarded = TRUE;
   link_info.disable_target_specific_optimizations = -1;
 
   command_line.warn_mismatch = TRUE;
index 88e85c73f496e68d254673b21d575b0f2960d22a..dacb9623b404a766b8ac65e35eb538b999fa6446 100644 (file)
@@ -543,6 +543,12 @@ static const struct ld_option ld_options[] =
   { {"orphan-handling", required_argument, NULL, OPTION_ORPHAN_HANDLING},
     '\0', N_("=MODE"), N_("Control how orphan sections are handled."),
     TWO_DASHES },
+  { {"print-map-discarded", no_argument, NULL, OPTION_PRINT_MAP_DISCARDED},
+    '\0', NULL, N_("Show discarded sections in map file output (default)"),
+    TWO_DASHES },
+  { {"no-print-map-discarded", no_argument, NULL, OPTION_NO_PRINT_MAP_DISCARDED},
+    '\0', NULL, N_("Do not show discarded sections in map file output"),
+    TWO_DASHES },
 };
 
 #define OPTION_COUNT ARRAY_SIZE (ld_options)
@@ -1577,6 +1583,14 @@ parse_args (unsigned argc, char **argv)
            einfo (_("%F%P: invalid argument to option"
                     " \"--orphan-handling\"\n"));
          break;
+
+       case OPTION_NO_PRINT_MAP_DISCARDED:
+         config.print_map_discarded = FALSE;
+         break;
+
+       case OPTION_PRINT_MAP_DISCARDED:
+         config.print_map_discarded = TRUE;
+         break;
        }
     }
 
index 536356c3816301b1ad469476dc3a8199e981ce45..13968cc7d1b47b8162e979eb8deb08f6d0e441d7 100644 (file)
@@ -171,3 +171,5 @@ if { [is_elf_format] && [check_shared_lib_support] \
     ]
     run_dump_test "pr20306"
 }
+
+run_dump_test "skip-map-discarded"
diff --git a/ld/testsuite/ld-gc/skip-map-discarded.d b/ld/testsuite/ld-gc/skip-map-discarded.d
new file mode 100644 (file)
index 0000000..2e79f0b
--- /dev/null
@@ -0,0 +1,3 @@
+#name: Check --no-print-map-discarded linker option
+#ld: -e 0 --gc-sections --no-print-map-discarded
+#map: skip-map-discarded.map
diff --git a/ld/testsuite/ld-gc/skip-map-discarded.map b/ld/testsuite/ld-gc/skip-map-discarded.map
new file mode 100644 (file)
index 0000000..ca4818e
--- /dev/null
@@ -0,0 +1,5 @@
+#failif
+Discarded input sections
+#...
+ _foo.*
+#...
diff --git a/ld/testsuite/ld-gc/skip-map-discarded.s b/ld/testsuite/ld-gc/skip-map-discarded.s
new file mode 100644 (file)
index 0000000..630aab0
--- /dev/null
@@ -0,0 +1,5 @@
+.globl __start
+__start:
+       .section        _foo
+foo:
+       .long   1