--- ./ld/ldmain.c.orig 2006-05-21 17:18:46.000000000 -0300 +++ ./ld/ldmain.c 2006-05-21 17:18:55.000000000 -0300 @@ -316,6 +316,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; ldfile_add_arch (""); --- ./ld/lexsup.c.orig 2006-05-21 17:06:21.000000000 -0300 +++ ./ld/lexsup.c 2006-05-21 17:18:27.000000000 -0300 @@ -124,6 +124,7 @@ enum option_values OPTION_FORCE_EXE_SUFFIX, OPTION_GC_SECTIONS, OPTION_NO_GC_SECTIONS, + OPTION_PRINT_GC_SECTIONS, OPTION_HASH_SIZE, OPTION_CHECK_SECTIONS, OPTION_NO_CHECK_SECTIONS, @@ -370,6 +371,9 @@ 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_("Print removed unused sections"), + TWO_DASHES }, { {"hash-size=", required_argument, NULL, OPTION_HASH_SIZE}, '\0', NULL, N_("Set default hash table size close to "), TWO_DASHES }, @@ -812,6 +816,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); --- ./include/bfdlink.h.orig 2006-05-21 17:16:54.000000000 -0300 +++ ./include/bfdlink.h 2006-05-21 17:17:21.000000000 -0300 @@ -324,6 +324,9 @@ struct bfd_link_info /* TRUE if unreferenced sections should be removed. */ unsigned int gc_sections: 1; + /* TRUE if should print removed unreferenced sections. */ + unsigned int print_gc_sections: 1; + /* What to do with unresolved symbols in an object file. When producing executables the default is GENERATE_ERROR. When producing shared libraries the default is IGNORE. The --- ./bfd/elflink.c.orig 2006-05-21 17:20:57.000000000 -0300 +++ ./bfd/elflink.c 2006-05-21 18:41:19.000000000 -0300 @@ -8978,6 +8978,9 @@ elf_gc_sweep (bfd *abfd, struct bfd_link to remove a section from the output. */ o->flags |= SEC_EXCLUDE; + if (info->print_gc_sections == TRUE) + printf("%s:%s\n", sub->filename, o->name); + /* But we also have to update some of the relocation info we collected before. */ if (gc_sweep_hook