From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30813 invoked by alias); 28 Mar 2006 09:28:27 -0000 Received: (qmail 30805 invoked by uid 22791); 28 Mar 2006 09:28:25 -0000 X-Spam-Check-By: sourceware.org Received: from province.act-europe.fr (HELO province.act-europe.fr) (212.157.227.214) by sourceware.org (qpsmtpd/0.31) with ESMTP; Tue, 28 Mar 2006 09:28:19 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-province.act-europe.fr (Postfix) with ESMTP id 614E54AD0D; Tue, 28 Mar 2006 11:28:16 +0200 (CEST) Received: from province.act-europe.fr ([127.0.0.1]) by localhost (province.act-europe.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 71312-04; Tue, 28 Mar 2006 11:28:16 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by province.act-europe.fr (Postfix) with ESMTP id B559E4AD0A; Tue, 28 Mar 2006 11:28:15 +0200 (CEST) From: Eric Botcazou To: binutils@gcc.gnu.org Subject: [PATCH] New option --print-gc-sections Date: Tue, 28 Mar 2006 12:04:00 -0000 User-Agent: KMail/1.7.1 Cc: Arnaud Charlet MIME-Version: 1.0 Content-Type: Multipart/Mixed; boundary="Boundary-00=_9JQKEYZdSEg4aCK" Message-Id: <200603281131.41402.ebotcazou@adacore.com> 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-03/txt/msg00349.txt.bz2 --Boundary-00=_9JQKEYZdSEg4aCK Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Content-length: 1345 Hi, We'd like to introduce a --print-gc-sections option, to be used in conjunction with --gc-sections, now that its output is accurate thanks to HJ's work. The warning/error message format recently changed and is now one-lined, so I'm proposing the following format: 1. "objfile:location GC function" for .text.function sections. 2. "objfile GC section" for other sections. For example, on an Ada example with --print-gc-sections --demangle=gnat: ./u.o GC .text ./u.o GC .bss ./u.o:/home/eric/gnat/bugs/F115-010/u.adb:18 GC u.unused ./u.o GC .gcc_except_table.u__unused ./u.o:/home/eric/gnat/bugs/F115-010/u.adb:27 GC u.unused_2 ./ma.o GC .text ./ma.o GC .data ./ma.o GC .bss Tentative patch attached, tested on AMD64/Linux. Comments? 2006-03-28 Eric Botcazou bfd/ * elflink.c (elf_gc_sweep): Invoke the gc_section link callback on excluded sections. include/ * bfdlink.h (struct bfd_link_info): New flag print_gc_sections. (struct bfd_link_callbacks): New method gc_section. ld/ * ld.texinfo (Command Line Options): Document --print-gc-sections. * ldmain.c (gc_section): New callback. (link_callbacks): Add gc_section. * lexsup.c (enum option_values): New value OPTION_PRINT_GC_SECTIONS. (ld_options): Add --print-gc-sections. (parse_args): Handle OPTION_PRINT_GC_SECTIONS. -- Eric Botcazou --Boundary-00=_9JQKEYZdSEg4aCK Content-Type: text/x-diff; charset="us-ascii"; name="f115-010_217.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="f115-010_217.diff" Content-length: 5267 Index: bfd/elflink.c =================================================================== RCS file: /cvs/src/src/bfd/elflink.c,v retrieving revision 1.207 diff -u -p -r1.207 elflink.c --- bfd/elflink.c 17 Mar 2006 18:37:21 -0000 1.207 +++ bfd/elflink.c 28 Mar 2006 09:06:30 -0000 @@ -8930,6 +8930,9 @@ elf_gc_sweep (bfd *abfd, struct bfd_link to remove a section from the output. */ o->flags |= SEC_EXCLUDE; + if (! (*info->callbacks->gc_section) (info, sub, o)) + return FALSE; + /* But we also have to update some of the relocation info we collected before. */ if (gc_sweep_hook Index: include/bfdlink.h =================================================================== RCS file: /cvs/src/src/include/bfdlink.h,v retrieving revision 1.58 diff -u -p -r1.58 bfdlink.h --- include/bfdlink.h 3 Nov 2005 02:52:51 -0000 1.58 +++ include/bfdlink.h 28 Mar 2006 09:06:30 -0000 @@ -327,6 +327,9 @@ struct bfd_link_info /* TRUE if unreferenced sections should be removed. */ unsigned int gc_sections: 1; + /* TRUE if we should print the list of garbage-collected 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 @@ -534,6 +537,10 @@ struct bfd_link_callbacks bfd_boolean (*notice) (struct bfd_link_info *, const char *name, bfd *abfd, asection *section, bfd_vma address); + /* A function which is called when a section is garbage-collected. + ABFD and SECTION are the section. */ + bfd_boolean (*gc_section) + (struct bfd_link_info *, bfd *abfd, asection *section); /* General link info message. */ void (*einfo) (const char *fmt, ...); Index: ld/ld.texinfo =================================================================== RCS file: /cvs/src/src/ld/ld.texinfo,v retrieving revision 1.157 diff -u -p -r1.157 ld.texinfo --- ld/ld.texinfo 3 Mar 2006 09:31:59 -0000 1.157 +++ ld/ld.texinfo 28 Mar 2006 09:06:31 -0000 @@ -1220,6 +1220,11 @@ with @samp{-r}. The default behaviour (o collection) can be restored by specifying @samp{--no-gc-sections} on the command line. +@kindex --print-gc-sections +@cindex garbage collection +@item --print-gc-sections +Print the list of garbage-collected sections with @samp{--gc-sections}. + @cindex help @cindex usage @kindex --help Index: ld/ldmain.c =================================================================== RCS file: /cvs/src/src/ld/ldmain.c,v retrieving revision 1.105 diff -u -p -r1.105 ldmain.c --- ld/ldmain.c 16 Mar 2006 12:20:16 -0000 1.105 +++ ld/ldmain.c 28 Mar 2006 09:06:31 -0000 @@ -147,6 +147,8 @@ static bfd_boolean unattached_reloc (struct bfd_link_info *, const char *, bfd *, asection *, bfd_vma); static bfd_boolean notice (struct bfd_link_info *, const char *, bfd *, asection *, bfd_vma); +static bfd_boolean gc_section + (struct bfd_link_info *, bfd *, asection *); static struct bfd_link_callbacks link_callbacks = { @@ -161,6 +163,7 @@ static struct bfd_link_callbacks link_ca reloc_dangerous, unattached_reloc, notice, + gc_section, einfo }; @@ -316,6 +319,7 @@ main (int argc, char **argv) link_info.need_relax_finalize = FALSE; link_info.warn_shared_textrel = FALSE; link_info.gc_sections = FALSE; + link_info.print_gc_sections = FALSE; ldfile_add_arch (""); @@ -1526,3 +1530,22 @@ notice (struct bfd_link_info *info, return TRUE; } + +/* This is called when a section is garbage-collected. */ + +static bfd_boolean +gc_section (struct bfd_link_info *info, + bfd *abfd, + asection *section) +{ + if (! info->print_gc_sections) + return TRUE; + + if (strncmp (section->name, ".text.", 6) == 0) + einfo ("%D GC %s\n", abfd, section, (bfd_vma) 0, + demangle (section->name+6)); + else + einfo ("%B GC %A\n", abfd, section); + + return TRUE; +} Index: ld/lexsup.c =================================================================== RCS file: /cvs/src/src/ld/lexsup.c,v retrieving revision 1.87 diff -u -p -r1.87 lexsup.c --- ld/lexsup.c 30 Oct 2005 18:08:52 -0000 1.87 +++ ld/lexsup.c 28 Mar 2006 09:06:31 -0000 @@ -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, @@ -421,6 +422,8 @@ static const struct ld_option ld_options { {"oformat", required_argument, NULL, OPTION_OFORMAT}, '\0', N_("TARGET"), N_("Specify target of output file"), EXACTLY_TWO_DASHES }, + { {"print-gc-sections", no_argument, NULL, OPTION_PRINT_GC_SECTIONS}, + '\0', NULL, N_("Print garbage-collected sections"), TWO_DASHES }, { {"qmagic", no_argument, NULL, OPTION_IGNORE}, '\0', NULL, N_("Ignored for Linux compatibility"), ONE_DASH }, { {"reduce-memory-overheads", no_argument, NULL, @@ -952,6 +955,9 @@ parse_args (unsigned argc, char **argv) case OPTION_OFORMAT: lang_add_output_format (optarg, NULL, NULL, 0); break; + case OPTION_PRINT_GC_SECTIONS: + link_info.print_gc_sections = TRUE; + break; case 'q': link_info.emitrelocations = TRUE; break; --Boundary-00=_9JQKEYZdSEg4aCK--