From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 32638 invoked by alias); 7 Jul 2006 22:21:30 -0000 Received: (qmail 32630 invoked by uid 22791); 7 Jul 2006 22:21:29 -0000 X-Spam-Check-By: sourceware.org Received: from smtp108.sbc.mail.mud.yahoo.com (HELO smtp108.sbc.mail.mud.yahoo.com) (68.142.198.207) by sourceware.org (qpsmtpd/0.31) with SMTP; Fri, 07 Jul 2006 22:21:26 +0000 Received: (qmail 28036 invoked from network); 7 Jul 2006 22:21:23 -0000 Received: from unknown (HELO lucon.org) (hjjean@sbcglobal.net@71.146.67.96 with login) by smtp108.sbc.mail.mud.yahoo.com with SMTP; 7 Jul 2006 22:21:22 -0000 Received: by lucon.org (Postfix, from userid 1000) id 565DD63EEC; Fri, 7 Jul 2006 15:21:21 -0700 (PDT) Date: Fri, 07 Jul 2006 22:21:00 -0000 From: "H. J. Lu" To: Marcelo Tosatti Cc: binutils@sources.redhat.com Subject: Re: [binutils patch]: -print-gc-sections option: print garbage collected sections Message-ID: <20060707222120.GA29900@lucon.org> References: <20060701231428.GA23415@dmt> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20060701231428.GA23415@dmt> User-Agent: Mutt/1.4.2.1i Mailing-List: contact binutils-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sourceware.org X-SW-Source: 2006-07/txt/msg00099.txt.bz2 I am forwarding it to the binutils mailing list. H.J. On Sat, Jul 01, 2006 at 08:14:28PM -0300, Marcelo Tosatti wrote: > Hi H.J.Lu, > > I have been working on a Linux kernel patch to use -gc-sections option > along with -ffunction-sections to waste unused functions (which are > pretty common in the kernel due to the many possible configuration). > > http://lkml.org/lkml/2006/6/4/169 > > I came up with the need to be informed about what sections ld is > removing, so I added the followed option: -print-gc-sections. > > The other possible way to know which sections are dumped is to two > images: once with "gc-sections", once without, and compare. Which is > rather dumb. > > Do you think its good for inclusion or it would be better to specify a > file instead of printing to stdout? > > Against recent binutils... > > --- ./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