This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFC] [PATCH] ld: Add --no-print-map-discarded option


ld/
	* 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/
	* 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.
---
 ld/ld.h                                   |  3 +++
 ld/ldlang.c                               | 25 +++++++++++++------------
 ld/ldlex.h                                |  2 ++
 ld/ldmain.c                               |  1 +
 ld/lexsup.c                               | 12 ++++++++++++
 ld/testsuite/ld-gc/gc.exp                 |  2 ++
 ld/testsuite/ld-gc/skip-map-discarded.d   |  3 +++
 ld/testsuite/ld-gc/skip-map-discarded.map |  5 +++++
 ld/testsuite/ld-gc/skip-map-discarded.s   |  5 +++++
 9 files changed, 46 insertions(+), 12 deletions(-)
 create mode 100644 ld/testsuite/ld-gc/skip-map-discarded.d
 create mode 100644 ld/testsuite/ld-gc/skip-map-discarded.map
 create mode 100644 ld/testsuite/ld-gc/skip-map-discarded.s

diff --git a/ld/ld.h b/ld/ld.h
index ba914b9..76cfa0a 100644
--- 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;
diff --git a/ld/ldlang.c b/ld/ldlang.c
index 350baf2..2adee9f 100644
--- a/ld/ldlang.c
+++ b/ld/ldlang.c
@@ -2054,19 +2054,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"));
diff --git a/ld/ldlex.h b/ld/ldlex.h
index 04d6fd5..3545cf1 100644
--- a/ld/ldlex.h
+++ b/ld/ldlex.h
@@ -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.  */
diff --git a/ld/ldmain.c b/ld/ldmain.c
index f31eeb2..6a595bb 100644
--- a/ld/ldmain.c
+++ b/ld/ldmain.c
@@ -263,6 +263,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;
diff --git a/ld/lexsup.c b/ld/lexsup.c
index 86a033a..1ab141b 100644
--- a/ld/lexsup.c
+++ b/ld/lexsup.c
@@ -543,6 +543,10 @@ 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"), 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 +1581,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;
 	}
     }
 
diff --git a/ld/testsuite/ld-gc/gc.exp b/ld/testsuite/ld-gc/gc.exp
index 9b044f0..cde8435 100644
--- a/ld/testsuite/ld-gc/gc.exp
+++ b/ld/testsuite/ld-gc/gc.exp
@@ -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
index 0000000..30f4881
--- /dev/null
+++ b/ld/testsuite/ld-gc/skip-map-discarded.d
@@ -0,0 +1,3 @@
+#name: Check --no-print-map-discarded linker option
+#ld: --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
index 0000000..ca4818e
--- /dev/null
+++ b/ld/testsuite/ld-gc/skip-map-discarded.map
@@ -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
index 0000000..157c8a0
--- /dev/null
+++ b/ld/testsuite/ld-gc/skip-map-discarded.s
@@ -0,0 +1,5 @@
+.globl __start
+__start:
+	.section	_foo,"aw",%progbits
+foo:
+	.long	1
-- 
2.7.4


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]