Ping: [Patch] Sort symbols in linker map
Tristan Gingold
gingold@adacore.com
Mon Jul 13 10:05:00 GMT 2009
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. */
>
More information about the Binutils
mailing list