This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSPM0L1304: Linker does not remove unused code

Part Number: MSPM0L1304
Other Parts Discussed in Thread: SYSCONFIG, MSPM0L1306

Tool/software:

Hello, 

I believe there is something wrong with the mspm0l1304.lds linker file. It does not remove unused code from the final .out file no matter what kind of flags i use (-Os -ffunction-sections -fdata-sections ect.. as a few examples) when compiling and generating a .out file.

I noticed there was a lot of space still used after removing a driver (not using it, but still compiling it with make).

Removing KEEP (*(.text)) from the mspm0l1304.lds on line 83 here seemed to do the trick: 

.text : {
        CREATE_OBJECT_SYMBOLS
        KEEP (*(.text))
        . = ALIGN(0x8);
        *(.text.*)
        . = ALIGN(0x8);
        KEEP (*(.ctors))
        . = ALIGN(0x8);
        KEEP (*(.dtors))
        . = ALIGN(0x8);
        KEEP (*(.init))
        . = ALIGN(0x8);
        KEEP (*(.fini*))
        . = ALIGN(0x8);
    } > REGION_TEXT AT> REGION_TEXT


Would like to hear your thoughts on this
Marcus

  • Hi Marcus,
    That seems odd. What examples were you running for this to happen? What is your version of CCS, the SDK, and SYSCONFIG? 

    Best Regards,

    Diego Abad

  • What is your version of CCS, the SDK, and SYSCONFIG

    I am using VSCode with the "TI Embedded Debug" extention on Ubuntu. The SDK im using is mspm0_sdk_03_00_07. 

    I have stripped down an example here that reproduces it. There is a readme on how to set up the example with VSCode

    In the root dir, when running

    make clean all

    In the terminal, the USE_UART definition is not set and the uart_shell.c code is not compiled. This is one way to exlude the code, but this should not be needed.

    When running 

    make debug 

    In the terminal, the USE_UART definition is set and the uart_shell.c code is compiled and takes up space (a lot of space(16KB)) even though no uart function is called. Uncommenting the uart functions i have added in main.c will increase the binary of the .out file by a little.

    Looking at the generated .map file, a lot of printf functions are added. These should not be added when they are not used? 

    Removing uart_shell.c from APP_SRC and running make debug decreases the binary by alot, but there should be no need to edit the makefile when there are unused stuff.

    Removing 

    KEEP (*(.text))
    . = ALIGN(0x8);

    from the linker file on line 83 removes all of these extra functions that are not in use when running make debug again; I guess there are risks to removing this, as functions that are only called in interrupt context or called via function pointers, will be optimized out? 

    The files of interest are the MakeFile, main.c and mspm0l1306.lds
    Note: The code now compiles for the MSPM0l1306, but the issue is still the same.


    TI_code_example.zip

    Let me know if there are anything else i can provide
    Best regards
    Marcus

  • Hi Marcus,
    Let me ask my team about this.

    Best Regards,

    Diego Abad

  • Hi Diego,

    Any updates? 
    Marcus

  • Hi Marcus,
    The software team confirmed with me that this behavior is too be expected. You can, however, remove that line of code if need it. 

    Best Regards,

    Diego Abad