tags:

views:

37

answers:

1

I need to find the code size for a library developed using C on linux. I have generated the map file using the gcc linker options against a sample application that uses this library.

The map file is quite exhaustive. How do I find out the code size of the library from the map file? any pointers to any documentation on how to interpret the map file would also be very useful.

+2  A: 

You want to find out the size of the machine instructions in a given shared object? Why do you need the map file?

This gives the size of the .text section. The .text section is where executable code is stored:

$ objdump  -x /usr/bin/objdump | grep .text
 13 .text         0002c218  0000000000403320  0000000000403320  00003320  2**4

In this example, there are 2c218 bytes of executable text. In decimal this is about 180 KiB:

$ printf %d\\n 0x2c218
180760

Edit: This is how it looks like with a library:

$ objdump -x /usr/lib/libcairo.so | grep .text
 11 .text         00054c18  000000000000cc80  000000000000cc80  0000cc80  2**4
$ printf %d\\n 0x54c18
347160
Uli Schlachter
Thanks. A sales person wanted the code size of the library so that he can communicate the same to the customer.If I run the objdump as you have suggested against the sample executable, then it gives the text size of the library as well as the sample application. Is there any way to get the text size of just the library?
sthustfo
Ah, sorry. Instead of running against the executable, you should run it against the library in question. I just used /usr/bin/objdump as a (bad) example for the output.
Uli Schlachter