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.

Compiler/MSP432P401R: Placing a variable or symbol at the *end* of linked image?



I would like to place a specific data item (or even just a linker symbol would suffice) at the end of all used memory. The use case being somewhat development/debug oriented but wanting a general/automated solution rather than e.g. manually copying over the size from the IDE.

Via section 8.7.2 of spnu118y.pdf I found an entry in the old FAQ "How can I get the linker to place a piece of code or data so that it comes before all the rest?" (https://processors.wiki.ti.com/index.php/Code_Generation_Tools_FAQ#Q:_How_can_I_get_the_linker_to_place_a_piece_of_code_or_data_so_that_it_comes_before_all_the_rest.3F)

What's unclear is how to do the same so that "a piece of code or data" will come after all the rest, since the placement algorithm handles not just the manually configured sections but also lots of implicit/automatic placements. Is there an easy way to control the last placed item?

Basically, I just want a pointer to the last byte/word of the "used" portion of the firmware image. How can I specify that location in my linker command file?

  • Nathan Vander Wilt said:
    I would like to place a specific data item (or even just a linker symbol would suffice) at the end of all used memory.

    You can place a symbol at the end of all used memory.  If you use TI ARM compiler version 20.2.x.LTS or later, your linker command file can have an entry similar to this in the MEMORY directive ...

    HIGHEST_MEMORY_RANGE : org = 0x20000020   len = 0x20000000   LAST(symbol_name_here)

    For details, please search the TI ARM assembly tools manual for the sub-chapter titled LAST Operator.

    Thanks and regards,

    -George

  • Okay, I think I found at least one way to do it, via section 8.5.10.8 of spnu118y.pdf  on the "LAST Operator".

    I modified my linker command file's MAIN line within the MEMORY block to add a `LAST()` around my desired symbol name:

    MAIN (RC) : origin = 0x8000, length = 0x38000, LAST(app_end)

    And then within my code:

    extern void* app_end;

    printf("End is: %p\r\n", _symval(&app_end));

  • Whoops, sorry I think we were both typing after I found the solution. Appreciate the help and the confirmation that the LAST() operator is indeed the right tool for this job!