public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [Patch] Sort symbols in linker map
@ 2009-07-08  9:27 Tristan Gingold
  2009-07-13 10:05 ` Ping: " Tristan Gingold
  0 siblings, 1 reply; 4+ messages in thread
From: Tristan Gingold @ 2009-07-08  9:27 UTC (permalink / raw)
  To: binutils

Hi,

this patch improved the linker map output by sorting symbols by  
address.  Currently they are ordered
according to the bfd_link_hash, which is not very user friendly.

No regressions on powerpc-elf.

Tristan.

2009-07-08  Tristan Gingold  <gingold@adacore.com>

	* ld.h (fat_user_section_struct): Add map_symbol_def_count field.
	* ldlang.c (hash_entry_addr_cmp): New function.
	(print_all_symbols): Sort the symbols by address before printing them.

RCS file: /cvs/src/src/ld/ld.h,v
retrieving revision 1.43
diff -u -p -r1.43 ld.h
--- ld.h	18 Mar 2009 11:27:18 -0000	1.43
+++ ld.h	8 Jul 2009 09:08:52 -0000
@@ -114,6 +114,7 @@ typedef struct fat_user_section_struct {
       list of hash table entries for symbols defined in this  
section.  */
    struct map_symbol_def *map_symbol_def_head;
    struct map_symbol_def **map_symbol_def_tail;
+  unsigned long map_symbol_def_count;
  } fat_section_userdata_type;

  #define get_userdata(x) ((x)->userdata)
Index: ldlang.c
===================================================================
RCS file: /cvs/src/src/ld/ldlang.c,v
retrieving revision 1.311
diff -u -p -r1.311 ldlang.c
--- ldlang.c	25 Jun 2009 13:18:46 -0000	1.311
+++ ldlang.c	8 Jul 2009 09:08:53 -0000
@@ -1988,6 +1988,7 @@ init_map_userdata (bfd *abfd ATTRIBUTE_U
    ASSERT (get_userdata (sec) == NULL);
    get_userdata (sec) = new_data;
    new_data->map_symbol_def_tail = &new_data->map_symbol_def_head;
+  new_data->map_symbol_def_count = 0;
  }

  static bfd_boolean
@@ -2015,6 +2016,7 @@ sort_def_symbol (struct bfd_link_hash_en
        def->entry = hash_entry;
        *(ud->map_symbol_def_tail) = def;
        ud->map_symbol_def_tail = &def->next;
+      ud->map_symbol_def_count++;
      }
    return TRUE;
  }
@@ -3940,18 +3942,48 @@ print_one_symbol (struct bfd_link_hash_e
    return TRUE;
  }

+static int
+hash_entry_addr_cmp (const void *a, const void *b)
+{
+  const struct bfd_link_hash_entry *l = *(const struct  
bfd_link_hash_entry **)a;
+  const struct bfd_link_hash_entry *r = *(const struct  
bfd_link_hash_entry **)b;
+
+  if (l->u.def.value < r->u.def.value)
+    return -1;
+  else if (l->u.def.value > r->u.def.value)
+    return 1;
+  else
+    return 0;
+}
+
  static void
  print_all_symbols (asection *sec)
  {
    struct fat_user_section_struct *ud = get_userdata (sec);
    struct map_symbol_def *def;
+  struct bfd_link_hash_entry **entries;
+  unsigned int i;

    if (!ud)
      return;

    *ud->map_symbol_def_tail = 0;
-  for (def = ud->map_symbol_def_head; def; def = def->next)
-    print_one_symbol (def->entry, sec);
+
+  /* Sort the symbols by address.  */
+  entries = obstack_alloc (&map_obstack,
+                           ud->map_symbol_def_count * sizeof  
(*entries));
+
+  for (i = 0, def = ud->map_symbol_def_head; def; def = def->next, i++)
+    entries[i] = def->entry;
+
+  qsort (entries, ud->map_symbol_def_count, sizeof (*entries),
+         hash_entry_addr_cmp);
+
+  /* Print the symbols.  */
+  for (i = 0; i < ud->map_symbol_def_count; i++)
+    print_one_symbol (entries[i], sec);
+
+  obstack_free (&map_obstack, entries);
  }

  /* Print information about an input section to the map file.  */

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Ping: [Patch] Sort symbols in linker map
  2009-07-08  9:27 [Patch] Sort symbols in linker map Tristan Gingold
@ 2009-07-13 10:05 ` Tristan Gingold
  2009-07-14  7:20   ` Nick Clifton
  0 siblings, 1 reply; 4+ messages in thread
From: Tristan Gingold @ 2009-07-13 10:05 UTC (permalink / raw)
  To: binutils

Ping for:

On Jul 8, 2009, at 11:27 AM, Tristan Gingold wrote:

> Hi,
>
> this patch improved the linker map output by sorting symbols by  
> address.  Currently they are ordered
> according to the bfd_link_hash, which is not very user friendly.
>
> No regressions on powerpc-elf.
>
> Tristan.
>
> 2009-07-08  Tristan Gingold  <gingold@adacore.com>
>
> 	* ld.h (fat_user_section_struct): Add map_symbol_def_count field.
> 	* ldlang.c (hash_entry_addr_cmp): New function.
> 	(print_all_symbols): Sort the symbols by address before printing  
> them.
>
> RCS file: /cvs/src/src/ld/ld.h,v
> retrieving revision 1.43
> diff -u -p -r1.43 ld.h
> --- ld.h	18 Mar 2009 11:27:18 -0000	1.43
> +++ ld.h	8 Jul 2009 09:08:52 -0000
> @@ -114,6 +114,7 @@ typedef struct fat_user_section_struct {
>      list of hash table entries for symbols defined in this  
> section.  */
>   struct map_symbol_def *map_symbol_def_head;
>   struct map_symbol_def **map_symbol_def_tail;
> +  unsigned long map_symbol_def_count;
> } fat_section_userdata_type;
>
> #define get_userdata(x) ((x)->userdata)
> Index: ldlang.c
> ===================================================================
> RCS file: /cvs/src/src/ld/ldlang.c,v
> retrieving revision 1.311
> diff -u -p -r1.311 ldlang.c
> --- ldlang.c	25 Jun 2009 13:18:46 -0000	1.311
> +++ ldlang.c	8 Jul 2009 09:08:53 -0000
> @@ -1988,6 +1988,7 @@ init_map_userdata (bfd *abfd ATTRIBUTE_U
>   ASSERT (get_userdata (sec) == NULL);
>   get_userdata (sec) = new_data;
>   new_data->map_symbol_def_tail = &new_data->map_symbol_def_head;
> +  new_data->map_symbol_def_count = 0;
> }
>
> static bfd_boolean
> @@ -2015,6 +2016,7 @@ sort_def_symbol (struct bfd_link_hash_en
>       def->entry = hash_entry;
>       *(ud->map_symbol_def_tail) = def;
>       ud->map_symbol_def_tail = &def->next;
> +      ud->map_symbol_def_count++;
>     }
>   return TRUE;
> }
> @@ -3940,18 +3942,48 @@ print_one_symbol (struct bfd_link_hash_e
>   return TRUE;
> }
>
> +static int
> +hash_entry_addr_cmp (const void *a, const void *b)
> +{
> +  const struct bfd_link_hash_entry *l = *(const struct  
> bfd_link_hash_entry **)a;
> +  const struct bfd_link_hash_entry *r = *(const struct  
> bfd_link_hash_entry **)b;
> +
> +  if (l->u.def.value < r->u.def.value)
> +    return -1;
> +  else if (l->u.def.value > r->u.def.value)
> +    return 1;
> +  else
> +    return 0;
> +}
> +
> static void
> print_all_symbols (asection *sec)
> {
>   struct fat_user_section_struct *ud = get_userdata (sec);
>   struct map_symbol_def *def;
> +  struct bfd_link_hash_entry **entries;
> +  unsigned int i;
>
>   if (!ud)
>     return;
>
>   *ud->map_symbol_def_tail = 0;
> -  for (def = ud->map_symbol_def_head; def; def = def->next)
> -    print_one_symbol (def->entry, sec);
> +
> +  /* Sort the symbols by address.  */
> +  entries = obstack_alloc (&map_obstack,
> +                           ud->map_symbol_def_count * sizeof  
> (*entries));
> +
> +  for (i = 0, def = ud->map_symbol_def_head; def; def = def->next, i 
> ++)
> +    entries[i] = def->entry;
> +
> +  qsort (entries, ud->map_symbol_def_count, sizeof (*entries),
> +         hash_entry_addr_cmp);
> +
> +  /* Print the symbols.  */
> +  for (i = 0; i < ud->map_symbol_def_count; i++)
> +    print_one_symbol (entries[i], sec);
> +
> +  obstack_free (&map_obstack, entries);
> }
>
> /* Print information about an input section to the map file.  */
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Ping: [Patch] Sort symbols in linker map
  2009-07-13 10:05 ` Ping: " Tristan Gingold
@ 2009-07-14  7:20   ` Nick Clifton
  2009-08-12 12:42     ` Tristan Gingold
  0 siblings, 1 reply; 4+ messages in thread
From: Nick Clifton @ 2009-07-14  7:20 UTC (permalink / raw)
  To: Tristan Gingold; +Cc: binutils

Hi Tristan,

>> 2009-07-08  Tristan Gingold  <gingold@adacore.com>
>>
>>     * ld.h (fat_user_section_struct): Add map_symbol_def_count field.
>>     * ldlang.c (hash_entry_addr_cmp): New function.
>>     (print_all_symbols): Sort the symbols by address before printing 
>> them.

Approved - please apply.

Cheers
   Nick


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Ping: [Patch] Sort symbols in linker map
  2009-07-14  7:20   ` Nick Clifton
@ 2009-08-12 12:42     ` Tristan Gingold
  0 siblings, 0 replies; 4+ messages in thread
From: Tristan Gingold @ 2009-08-12 12:42 UTC (permalink / raw)
  To: Nick Clifton; +Cc: binutils


On Jul 14, 2009, at 9:19 AM, Nick Clifton wrote:

> Hi Tristan,
>
>>> 2009-07-08  Tristan Gingold  <gingold@adacore.com>
>>>
>>>    * ld.h (fat_user_section_struct): Add map_symbol_def_count field.
>>>    * ldlang.c (hash_entry_addr_cmp): New function.
>>>    (print_all_symbols): Sort the symbols by address before  
>>> printing them.
>
> Approved - please apply.

Thanks, just committed.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-08-12 12:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-07-08  9:27 [Patch] Sort symbols in linker map Tristan Gingold
2009-07-13 10:05 ` Ping: " Tristan Gingold
2009-07-14  7:20   ` Nick Clifton
2009-08-12 12:42     ` Tristan Gingold

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).