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: [PATCH] New option --print-gc-sections


> I still like the idea of displaying discarded sections in the link map
> output though.  I think it would be useful to do so whenever -Map or -M
> is given, so you wouldn't need a new ld option.  You also shouldn't need
> any new hooks.  At the end of lang_map, just iterate over input
> sections, looking for any that don't make it to the output bfd.

Thanks, works fine.  I've put it between the list of archives members included
in the link and the memory map.  Tested on AMD64/Linux.


2006-04-04  Eric Botcazou  <ebotcazou@adacore.com>

	* ldlang.c (lang_map): Print the list of discarded input sections.
	(print_input_section): Change parameter and print zero-sized sections.
	(print_statement): Adjust call to print_input_section.


-- 
Eric Botcazou
Index: ldlang.c
===================================================================
RCS file: /cvs/src/src/ld/ldlang.c,v
retrieving revision 1.213
diff -u -p -r1.213 ldlang.c
--- ldlang.c	16 Mar 2006 12:20:16 -0000	1.213
+++ ldlang.c	4 Apr 2006 07:43:58 -0000
@@ -81,6 +81,7 @@ static void print_statement (lang_statem
 static void print_statement_list (lang_statement_union_type *,
 				  lang_output_section_statement_type *);
 static void print_statements (void);
+static void print_input_section (asection *);
 static bfd_boolean lang_one_common (struct bfd_link_hash_entry *, void *);
 static void lang_record_phdrs (void);
 static void lang_do_version_exports_section (void);
@@ -1598,6 +1599,22 @@ lang_map (void)
   lang_memory_region_type *m;
   bfd *p;
 
+  fprintf (config.map_file, _("\nDiscarded input sections\n\n"));
+
+  LANG_FOR_EACH_INPUT_STATEMENT (file)
+    {
+      asection *s;
+
+      if ((file->the_bfd->flags & (BFD_LINKER_CREATED | DYNAMIC)) != 0
+	  || file->just_syms_flag)
+	continue;
+
+      for (s = file->the_bfd->sections; s != NULL; s = s->next)
+	if (s->output_section == NULL
+	    || s->output_section->owner != output_bfd)
+	  print_input_section (s);
+    }
+
   minfo (_("\nMemory Configuration\n\n"));
   fprintf (config.map_file, "%-16s %-18s %-18s %s\n",
 	   _("Name"), _("Origin"), _("Length"), _("Attributes"));
@@ -3475,13 +3492,12 @@ print_all_symbols (sec)
 /* Print information about an input section to the map file.  */
 
 static void
-print_input_section (lang_input_section_type *in)
+print_input_section (asection *i)
 {
-  asection *i = in->section;
   bfd_size_type size = i->size;
 
   init_opb ();
-  if (size != 0)
+
     {
       int len;
       bfd_vma addr;
@@ -3501,7 +3517,7 @@ print_input_section (lang_input_section_
 	  ++len;
 	}
 
-      if (i->output_section != NULL && (i->flags & SEC_EXCLUDE) == 0)
+      if (i->output_section != NULL && i->output_section->owner == output_bfd)
 	addr = i->output_section->vma + i->output_offset;
       else
 	{
@@ -3528,7 +3544,7 @@ print_input_section (lang_input_section_
 	  minfo (_("%W (size before relaxing)\n"), i->rawsize);
 	}
 
-      if (i->output_section != NULL && (i->flags & SEC_EXCLUDE) == 0)
+      if (i->output_section != NULL && i->output_section->owner == output_bfd)
 	{
 	  if (command_line.reduce_memory_overheads)
 	    bfd_link_hash_traverse (link_info.hash, print_one_symbol, i);
@@ -3797,7 +3813,7 @@ print_statement (lang_statement_union_ty
       print_reloc_statement (&s->reloc_statement);
       break;
     case lang_input_section_enum:
-      print_input_section (&s->input_section);
+      print_input_section (s->input_section.section);
       break;
     case lang_padding_statement_enum:
       print_padding_statement (&s->padding_statement);

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