3

Is there a convenient way to find the full size cost of a compiled function? Measuring function code sizes is simple (with objdump or nm), but what if a function generates in a non-text section static data such as jump tables from switches. How can I conveniently add the sizes of those (especially in situations where there's multiple functions per object file and several of them each reference a jumptable) to the text size of a function?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Petr Skocik
  • 58,047
  • 6
  • 95
  • 142
  • 3
    I don't think there's a good way to do this. The ELF object file format does not provide an association between the jump tables and the functions, so it doesn't even seem like the desired information is present without some guesswork. – fuz Nov 15 '21 at 17:33
  • 2
    What about static data (like a string literal) used by multiple functions? Does it get attributed to all of them? None of them? Divided equally? – Ben Voigt Nov 15 '21 at 17:51
  • There are also initializers that might go to data/static data section – Eugene Sh. Nov 15 '21 at 18:01
  • 2
    I'd say, compile with the function. Then compile with an empty stub and compare. Still won't give much though, because it might get inlined here and there. – Eugene Sh. Nov 15 '21 at 18:03
  • 1
    For now, `-fdata-sections -ffunction-sections` seems like a viable way to split it all up per function for information purposes, although it sometimes does affect codegen a bit like the gcc manual says. – Petr Skocik Nov 15 '21 at 18:11
  • 1
    Another sometimes-significant source of static size is SIMD vector constants when auto-vectorizing. e.g. multiple 4-byte `float` constants replicated into 32-byte vectors (so they can be memory operands directly without AVX-512, without needing `vbroadcastss` loads). – Peter Cordes Nov 16 '21 at 01:43
  • Where are you starting from? Do you know about `size a.out` (if you are on Linux, are you on Linux?) – ADBeveridge Nov 16 '21 at 02:09
  • @ADBeveridge Yes. For now, `size -A file.o` after the file was compiled with `-ffunction-section -fdata-section` is the closest to an ideal solution, although something that works without requiring `-ffunction-section -fdata-section` would be better. – Petr Skocik Nov 16 '21 at 06:39
  • @BenVoigt Ideally, I'd like to easily show both how much space a function requires and how much of it is shared with other functions. – Petr Skocik Nov 16 '21 at 06:45

0 Answers0