13

I'm working on an embedded project on an ARM mcu that has a custom linker file with several different memory spaces:

/* Memory Spaces Definitions */
MEMORY
{
  rom      (rx)  : ORIGIN = 0x00400000, LENGTH = 0x00200000
  data_tcm (rw)  : ORIGIN = 0x20000000, LENGTH = 0x00008000
  prog_tcm (rwx) : ORIGIN = 0x00000000, LENGTH = 0x00008000
  ram      (rwx) : ORIGIN = 0x20400000, LENGTH = 0x00050000
  sdram    (rw)  : ORIGIN = 0x70000000, LENGTH = 0x00200000
}

Specifically, I have a number of different memory devices with different characteristics (TCM, plain RAM (with a D-Cache in the way), and an external SDRAM), all mapped as part of the same address space.

I'm specifically placing different variables in the different memory spaces, depending on the requirements (am I DMA'ing into it, do I have cache-coherence issues, do I expect to overflow the D-cache, etc...).

If I exceed any one of the sections, I get a linker error. However, unless I do so, the linker only prints the memory usage as bulk percentage:

            Program Memory Usage    :   33608 bytes   1.6 % Full
            Data Memory Usage       :   2267792 bytes   91.1 % Full

Given that I have 3 actively used memory spaces, and I know for a fact that I'm using 100% of one of them (the SDRAM), it's kind of a useless output.

Is there any way to make the linker output the percentage of use for each memory space individually? Right now, I have to manually open the .map file, search for the section header, and then manually subtract the size from the total available memory specified in the .ld file.

While this is kind of a minor thing, it'd sure be nice to just have the linker do:

Program Memory Usage    :   33608 bytes   1.6 % Full
Data Memory Usage       :   2267792 bytes   91.1 % Full
    data_dtcm           :   xxx bytes   xx % Full
    ram                 :   xxx bytes   xx % Full
    sdram               :   xxx bytes   xx % Full

This is with GCC-ARM, and therefore GCC-LD.

Community
  • 1
  • 1
Fake Name
  • 5,556
  • 5
  • 44
  • 66

1 Answers1

25

Arrrgh, so of course, I find the answer right after asking the question:

--print-memory-usage

Used as -Wl,--print-memory-usage, you get the following:

    Memory region         Used Size  Region Size  %age Used
                 rom:       31284 B         2 MB      1.49%
            data_tcm:       26224 B        32 KB     80.03%
            prog_tcm:          0 GB        32 KB      0.00%
                 ram:      146744 B       320 KB     44.78%
               sdram:          2 MB         2 MB    100.00%
Fake Name
  • 5,556
  • 5
  • 44
  • 66
  • Note that this doesn't seem to be available in all versions/toolchains. [GCC Renesas](https://gcc-renesas.com/) (v.4.9.2.201701) based on gcc 4.9.2 does not have this option, which is disappointing. – ahogen Jun 26 '18 at 20:54
  • 1
    @ahogen - It looks like this particular flag was added [here](https://sourceware.org/ml/binutils/2015-06/msg00115.html) (10 Jun 2015), which would put it right before GCC 4.9.3 was released, but well after 4.9.2. It *might* be possible to build it yourself, the patch is pretty minimal. – Fake Name Jun 26 '18 at 22:50
  • Corrected [patch link](https://sourceware.org/ml/binutils/2015-06/msg00121.html). – Fake Name Jun 26 '18 at 22:52