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]

Re: [binutils patch]: -print-gc-sections option: print garbage collected sections


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=<NUMBER>", required_argument, NULL, OPTION_HASH_SIZE},
>      '\0', NULL, N_("Set default hash table size close to <NUMBER>"),
>      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


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