Linking and optimization in the GNU toolchain
Writing small code is one thing, another step is linking the code into one program. The linking step is when is decided which code will be part of the program and what will be left out. In order to create a small executable program you need to know the limitations of your tool chain.
Let's have a look at a part of the .map file that is generated as a result of builting the LCD test program:
.text 0x400004b4 0x388 i2c.o
0x400004d4 i2cInit
0x400007c0 i2cRead
0x40000540 i2cStart
0x40000748 i2cPoll
0x400005b8 i2cStop
0x400004b4 i2cCheckStatus
0x4000060c i2cGetChar
0x4000057c i2cRepeatStart
0x400006b0 i2cWrite
0x40000688 i2cPutCharAndWait
0x400005e0 i2cPutChar
0x40000668 i2cWaitAfterTransmit
This shows that the file i2c.o is linked with all the functions that are in the file, even the i2cRead and i2cGetChar functions that are not used in the program are still linked as part of the process.
|