Search code examples
csymbolsobjdumparm-none-eabi-gcc

How to sort the symbol table (generated by "objdump -t") sequentially by address?


I would like to see at one glance which variables are placed next to each other in memory. If I generate a symbol table by using objdump -t I get the symbol table, however sorted seemingly randomly.

SYMBOL TABLE:
00100584 l     F .text  00000000 deregister_tm_clones
001005a8 l     F .text  00000000 register_tm_clones
001005d4 l     F .text  00000000 __do_global_dtors_aux
0019c020 l       .bss   00000001 completed.10177
0019c00c l     O .fini_array    00000000 __do_global_dtors_aux_fini_array_entry
00100604 l     F .text  00000000 frame_dummy
0019c024 l       .bss   00000018 object.10182
0019c008 l     O .init_array    00000000 __frame_dummy_init_array_entry
00000000 l    df *ABS*  00000000 tcp_server_test.c
0019c03c l       .bss   00000004 xServerWorkTaskHandle
001006a4 l     F .text  00000098 prvServerWorkTask
0019c040 l       .bss   00000008 xMyTelnet
...

Is there a way to get it sorted by address (first column) in upcounting manner?

It would be great if there was a switch that could be added to objdump -t to get the desired output. I looked through the documentation and did not find anything like that, but maybe I overlooked something?

Another approach could be to write a python script that resorts it, but I would like to avoid that if possible.

Thanks!


Solution

  • You can use the universal tool "sort" to sort the output of "objdump".

    Please read its documentation for options. Without any option, it simply sorts on the first column.


    For the no-yet-enlightened command line user...

    You need to "pipe" the output of "objdump" as input into "sort" like this:

    objdump -t my_module.o | sort