* ldmain.c (main): Initialise print_gc_sections field of link_info structure.
authorNick Clifton <nickc@redhat.com>
Fri, 4 Aug 2006 14:53:26 +0000 (14:53 +0000)
committerNick Clifton <nickc@redhat.com>
Fri, 4 Aug 2006 14:53:26 +0000 (14:53 +0000)
* lexsup.c: Add --print-gc-sections and --no-print-gc-sections switches.
* ld.texinfo: Document new switches.
* NEWS: Mention new switches.
* bfdlink.h (struct bfd_link_info): New field: print_gc_sections.
* elflink.c (elf_gc_sweep): If info.print_gc_sections is true, list removed sections to stderr.

bfd/ChangeLog
bfd/elflink.c
include/ChangeLog
include/bfdlink.h
ld/ChangeLog
ld/NEWS
ld/ld.texinfo
ld/ldmain.c
ld/lexsup.c

index 401c6b37312fd71377ba79e8fe75e0eeba44739c..0ba154dfd8083bf24c5aa6b0653725d7af7396a2 100644 (file)
@@ -1,3 +1,8 @@
+2006-08-04  Marcelo Tosatti  <marcelo@kvack.org>
+
+       * elflink.c (elf_gc_sweep): If info.print_gc_sections is true,
+       list removed sections to stderr.
+
 2006-08-04  Richard Sandiford  <richard@codesourcery.com>
            Kazu Hirata  <kazu@codesourcery.com>
            Phil Edwards  <phil@codesourcery.com>
index 99f0acc7588f51f9281778cac7ade7380f1d60e4..ba0e77e3aa435e10570988d89815ca3069bca339 100644 (file)
@@ -9356,7 +9356,8 @@ _bfd_elf_gc_mark (struct bfd_link_info *info,
 
 /* Sweep symbols in swept sections.  Called via elf_link_hash_traverse.  */
 
-struct elf_gc_sweep_symbol_info {
+struct elf_gc_sweep_symbol_info
+{
   struct bfd_link_info *info;
   void (*hide_symbol) (struct bfd_link_info *, struct elf_link_hash_entry *,
                       bfd_boolean);
@@ -9419,6 +9420,9 @@ elf_gc_sweep (bfd *abfd, struct bfd_link_info *info)
             to remove a section from the output.  */
          o->flags |= SEC_EXCLUDE;
 
+         if (info->print_gc_sections == TRUE)
+           _bfd_error_handler (_("Removing unused section '%s' in file '%B'"), sub, o->name);
+
          /* But we also have to update some of the relocation
             info we collected before.  */
          if (gc_sweep_hook
index 75f1ed22f054569e084f6c8150f8f301e83ab04f..5140f8d196471a77a64778f1390c6053fe632a8e 100644 (file)
@@ -1,3 +1,7 @@
+2006-08-04  Marcelo Tosatti  <marcelo@kvack.org>
+
+       * bfdlink.h (struct bfd_link_info): New field: print_gc_sections.
+
 2006-07-10  Jakub Jelinek  <jakub@redhat.com>
 
        * bfdlink.h (struct bfd_link_info): Add emit_hash and
index 761bd0513e35ca79f130b48ff7094bd7ac491ecf..bbedd6089f2d082a40f2bbd80883e2350add171a 100644 (file)
@@ -324,6 +324,9 @@ struct bfd_link_info
   /* TRUE if unreferenced sections should be removed.  */
   unsigned int gc_sections: 1;
 
+  /* TRUE if user shoudl be informed of removed unreferenced sections.  */
+  unsigned int print_gc_sections: 1;
+
   /* TRUE if .hash section should be created.  */
   unsigned int emit_hash: 1;
 
index 45129658a3a80c67f39c3c76ece76f3841b06ad8..1ee78d4e3817f25c43af37f2acfb87d56be381aa 100644 (file)
@@ -1,3 +1,12 @@
+2006-08-04  Marcelo Tosatti  <marcelo@kvack.org>
+
+       * ldmain.c (main): Initialise print_gc_sections field of link_info
+       structure.
+       * lexsup.c: Add --print-gc-sections and --no-print-gc-sections
+       switches.
+       * ld.texinfo: Document new switches.
+       * NEWS: Mention new switches.
+
 2006-08-04  Richard Sandiford  <richard@codesourcery.com>
            Kazu Hirata  <kazu@codesourcery.com>
            Phil Edwards  <phil@codesourcery.com>
diff --git a/ld/NEWS b/ld/NEWS
index 27fb0ae1154bbb2a94dac82c48b27c6f3bad273a..4ca2e9b1ccbaba6e8c463507373f2033920d2a57 100644 (file)
--- a/ld/NEWS
+++ b/ld/NEWS
@@ -1,4 +1,8 @@
 -*- text -*-
+* New switch: --print-gc-sections to list any sections removed by garabge
+  collection.
+
+Changes in 2.17:
 
 * Support for the Infineon XC16X has been added by KPIT Cummins Infosystems.
 
index f3d958051883b1ea9f00eb3e90479c9f1fcf36aa..835482d1c294e24609539fe441e36be78e7a9428 100644 (file)
@@ -1230,14 +1230,26 @@ it ends in a @code{.exe} suffix.
 @kindex --gc-sections
 @kindex --no-gc-sections
 @cindex garbage collection
-@item --no-gc-sections
-@itemx --gc-sections
+@item --gc-sections
+@itemx --no-gc-sections
 Enable garbage collection of unused input sections.  It is ignored on
 targets that do not support this option.  This option is not compatible
 with @samp{-r}. The default behaviour (of not performing this garbage
 collection) can be restored by specifying @samp{--no-gc-sections} on
 the command line.
 
+@kindex --print-gc-sections
+@kindex --no-print-gc-sections
+@cindex garbage collection
+@item --print-gc-sections
+@itemx --no-print-gc-sections
+List all sections removed by garbage collection.  The listing is
+printed on stderr.  This option is only effective if garbage
+collection has been enabled via the @samp{--gc-sections}) option.  The
+default behaviour (of not listing the sections that are removed) can
+be restored by specifying @samp{--no-print-gc-sections} on the command
+line.
+
 @cindex help
 @cindex usage
 @kindex --help
index cb56a8d85f90c414c74edd7ff07b155b6d34ff3a..4dab0d6bd4d601cf0e2f63d9567b6c9dc9ac97d5 100644 (file)
@@ -318,6 +318,7 @@ main (int argc, char **argv)
   link_info.relax_pass = 1;
   link_info.warn_shared_textrel = FALSE;
   link_info.gc_sections = FALSE;
+  link_info.print_gc_sections = FALSE;
 
   config.maxpagesize = 0;
   config.commonpagesize = 0;
index c2bef1dd4829b381c148ffda12f40206e4fe0c94..4d526b0b67387ff7384f4246132a8f68afabc181 100644 (file)
@@ -124,6 +124,8 @@ enum option_values
   OPTION_FORCE_EXE_SUFFIX,
   OPTION_GC_SECTIONS,
   OPTION_NO_GC_SECTIONS,
+  OPTION_PRINT_GC_SECTIONS,
+  OPTION_NO_PRINT_GC_SECTIONS,
   OPTION_HASH_SIZE,
   OPTION_CHECK_SECTIONS,
   OPTION_NO_CHECK_SECTIONS,
@@ -370,6 +372,12 @@ static const struct ld_option ld_options[] =
   { {"no-gc-sections", no_argument, NULL, OPTION_NO_GC_SECTIONS},
     '\0', NULL, N_("Don't remove unused sections (default)"),
     TWO_DASHES },
+  { {"print-gc-sections", no_argument, NULL, OPTION_PRINT_GC_SECTIONS},
+    '\0', NULL, N_("List removed unused sections on stderr"),
+    TWO_DASHES },
+  { {"no-print-gc-sections", no_argument, NULL, OPTION_NO_PRINT_GC_SECTIONS},
+    '\0', NULL, N_("Do not list removed unused sections"),
+    TWO_DASHES },
   { {"hash-size=<NUMBER>", required_argument, NULL, OPTION_HASH_SIZE},
     '\0', NULL, N_("Set default hash table size close to <NUMBER>"),
     TWO_DASHES },
@@ -812,6 +820,9 @@ parse_args (unsigned argc, char **argv)
        case OPTION_GC_SECTIONS:
          link_info.gc_sections = TRUE;
          break;
+       case OPTION_PRINT_GC_SECTIONS:
+         link_info.print_gc_sections = TRUE;
+         break;
        case OPTION_HELP:
          help ();
          xexit (0);
@@ -855,6 +866,9 @@ parse_args (unsigned argc, char **argv)
        case OPTION_NO_GC_SECTIONS:
          link_info.gc_sections = FALSE;
          break;
+       case OPTION_NO_PRINT_GC_SECTIONS:
+         link_info.print_gc_sections = FALSE;
+         break;
        case OPTION_NO_KEEP_MEMORY:
          link_info.keep_memory = FALSE;
          break;