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.

Optimizing code by placing sections

Hi,

I try to optimize code for AM335x and I have the following situation:
1. .bss section has to be the last section to keep the final binary file small and therefore loadtime from SD card is short
2. .cinit, .data, .const and sections that are only used to hold code that is copied to (and runs in) internal SRAM should be after .text. So that .text is the first section placed in memory.

Point 1 I got solved by grouping .bss, .stack and .sysmem and using "(HIGH)".
For Point 2 I tried a lot of different things but in vain so far.

1. Question: Is it possible to place .cinit behind .text section?

2. Question: Is it possible to switch-off the autoinitialisation of .bss with zero?

Thanks and best regards,
Patrick

  • Pruf said:
    1. Question: Is it possible to place .cinit behind .text section?

    I can tell you how to make sure .text is first.  And I think that will solve your problem.

    It will look like this in your linker command file ...

    #define SRAM_START 0x1000
    ...
    MEMORY
    {
       SRAM : o = SRAM_START, l = 0x4000
    ...
    }
    
    SECTIONS
    {
       .text  > SRAM_START
       .cinit > SRAM
       ...
    }

    Obviously, change those hex values to the real ones.

    Pruf said:
    2. Question: Is it possible to switch-off the autoinitialisation of .bss with zero?

    Look up the linker option --zero_init=off in the ARM assembly language tools manual.  Especially note the warning about how this means all global variables can have any value in them when the system starts running.

    Thanks and regards,

    -George

  • Hi George,

    Thanks for the answer. The problem is that there is a .init section that has to be in front of .text section. So I can't make .text section the first section. Sorry I did not mention that in my first post. I did try the GROUP command. This works for .text and .init section but not for the following section:

    .text_SRAM : LOAD > DDR_MEM, RUN > SRAM_CACHELOCK_MEN
                           LOAD_START(sram_code_load_start)
                           RUN_START(sram_code_run_start)
                           SIZE(sram_code_size)

    As GROUP does not allow an RUN statement within the GROUP command. So this sections gets linked always in front of .text section.
    An other problem is .cinit. If I place it in front of .data section I get Error #10333. I can place it behind . data and I get the Warning #10229-D output section ".data" refers to load symbol "..." and hence cannot be compressed... So I have to take .cinit out of the GROUP and the .cinit gets linked in front of .text again.

    I also had a look at the following discussion: http://e2e.ti.com/support/development_tools/compiler/f/343/t/247239.aspx
    But I can not see any solution to my problem.

    Best regards,
    Patrick

  • I'm still not clear on exactly what you are trying to do.  But I'm pretty sure that GROUP is the only mechanism that could work.  It is probably a bit of overkill, in that you don't need to control the order of placement for everything in the GROUP.  But that is a drawback I think you have to live with.

    Pruf said:
    As GROUP does not allow an RUN statement within the GROUP command.

    Correct.  A LOAD statement is not allowed either.  That's because you can specify an allocation (either RUN, LOAD, or both) only for the entire GROUP at once.  Note you can have LOAD_START etc. for each member output section within a GROUP.  

    Pruf said:
    I get the Warning #10229-D output section ".data" refers to load symbol "..." and hence cannot be compressed

    This is only a warning that the .data section is bigger than it could be.  If everything fits in memory, feel free to ignore it.

    Thanks and regards,

    -George