Skip to main content
B Zikhali
Associate III
July 15, 2016
Question

Removing dead code from HAL Library and optimising for size breaks functionality

  • July 15, 2016
  • 3 replies
  • 1465 views
Posted on July 15, 2016 at 11:47

 

 

The original post was too long to process during our migration. Please click on the attachment to read the original post.
    This topic has been closed for replies.

    3 replies

    Rosiney Silva
    Associate
    July 15, 2016
    Posted on July 15, 2016 at 18:41

    If you use gcc, there is an

    option

    of compilation (-flto) you should do what you want without having to change

    the code

    . The option of compilation -flto, performs a blobal optimization. Below is the result (in bytes) of compilation of 3 code examples

    :

            | p1-avr | p2-stm32f1 | p3-stm32f4 |

    --------|--------|------------|------------|

    Os      |  23911 |    34180   |    75384   |

    Os-flto |  21015 |    11552   |    33036   |

    O3      |  27219 |    43708   |    93416   |

    O3-flto |  29813 |    13416   |    41460   |

    --------|--------|------------|------------|

    matic
    Associate III
    July 15, 2016
    Posted on July 16, 2016 at 00:52

    For the highest speed performance and smallest code size I suggest to not use any libraries. Program with registers directly. When I remove from our project all HAL functions (which were used for peripheral initialisation only), the code size goes from 32kB to around 18 kB.

    B Zikhali
    B ZikhaliAuthor
    Associate III
    July 18, 2016
    Posted on July 18, 2016 at 11:03

    Thank you Silva for the suggestion to use Link Time Optimisation; it does actually reduce code size and increase the speed of my application. Unfortunately the disassembly of the LTO'd code removes comments and I can't verify if the 'useless' code is actually removed. And also out of curiosity, I would still like to know why removing dead code would break the code when optimised for size and work with every other optimisation level.