4

My intention is to limit the visibility of a number of symbols to the translation unit where they are defined. This commit is adding 688 bytes to the resulting firmware file. Any ideas why?

The compiler involved is a GCC 4.8.2 The target device is an ESP-8266 microcontroller. The optimizer is set to -Os.

Frank Meerkötter
  • 2,778
  • 2
  • 20
  • 26
  • 4
    Interesting. Perhaps after adding `static` the functions are now inlined by the compiler, while before they were not? A function does not have to be explicitly marked with `inline` to be inlined. – kfx Nov 10 '18 at 19:47
  • In my opinion, it is good practice to do as you are doing (make all functions not used outside their TU `static`) — you can routinely see it in the C code I post on SO, though I don't usually comment on it. So, good job on doing that. If, as seems plausible, inlining causes the growth and that is a problem for you, you may need to investigate 'optimizing for space' instead of 'optimizing for speed'. (GCC 8.2.0 documentation on [Optimizing options](https://gcc.gnu.org/onlinedocs/gcc-8.2.0/gcc/Optimize-Options.html#Optimize-Options). You'll need the equivalent for 4.8.2 — easy to deduce.) – Jonathan Leffler Nov 10 '18 at 21:32
  • 2
    What optimization levels are you using? Does this happen with `-Os` optimisation? Probably one function is inlined twice or more, thus you will get bigger resulting firmare. Can you check what if you mark all those functions with `__attribute__((__noinline__))`? – KamilCuk Nov 10 '18 at 21:36
  • Try compiling with `-Os` ? – M.M Nov 10 '18 at 21:55
  • Updated the question with the optimization level used. – Frank Meerkötter Nov 11 '18 at 05:49
  • Generate the assembly for both versions. Compare. – Raymond Chen Nov 11 '18 at 06:04
  • @KamilCuk thanks for your suggestion. I sprinkled __attribute__((noinline__)) over that commit but very much to my surprise it only changes the size of the firmware by a few bytes (20 something). – Frank Meerkötter Nov 11 '18 at 20:06

0 Answers0