Because of the Thanksgiving holiday in the U.S., TI E2E™ design support forum responses may be delayed the week of November 23.

F29H850TU: Linker script: inconsistency between the documentation and my test

Part Number: F29H850TU

Hello,

1/

I tried the following in my linker script (I used and updated the example "led_ex1_blinky"):

    .SSU_APR_AA_START :
    {
        . += align(4096); /* Mandatory alignment for SSU APR */
    } run = SRAM_LDAx, START(SAFESSU_lblPS0_LDA_VAR_START)
    .SSU_APR_AA_START_2 :
    {
        . += align(4096); /* Mandatory alignment for SSU APR */
    } run = 0x200e2004, START(SAFESSU_lblPS0_LDA_VAR_START_2), END(SAFESSU_lblPS0_LDA_VAR_END_2)
and I got this result (map file):
0     200e1018  .toto_end                           
0     200e2000  SAFESSU_lblPS0_LDA_VAR_START        
0     200e2004  SAFESSU_lblPS0_LDA_VAR_START_2      
0     200e3000  SAFESSU_lblPS0_LDA_VAR_END_2        
0     200e3000  table                               
with the warning "warning #10098-D: specific address 0x200e2004 overrides alignment of 4096 for ".SSU_APR_AA_START_2"".
 
The goal of this test was to verify the behavior of ". += align(4096);" when the start address of the output section is not aligned.
 
Based on the documentation,
image.png
my expectation would be that SAFESSU_lblPS0_LDA_VAR_END_2 is located at the address 0x200e3004 because the output section starts at an address aligned on 4096 + 4 and the documentation says that the alignment is relative to the start of the section as if it was started at the address 0.
 
But the test shows that the alignment is absolute and not relative to the output section.
 
Did I miss something ?
 
 
2/
Another unexpected behavior with the test described above: SAFESSU_lblPS0_LDA_VAR_START is not equal to the next address after the previous output section but is equal to an address aligned on 4096.
Is this expected ? Is this because the section is "empty" ? Where can I find this information in the documentation ?
 
Thank you
 

 

  • Hi Ronan,


    Could you share which document you are referring to? 
    As per my under standing of your issue, there seems to be a mis-match between the documentation and the generated map file. 
    If you could share the document details, i could confirm with the expert incharge of this. 


    Regards, 
    Pranav Siddappa

  • Hi Ronan, 


    Thanks for the information. I will check internally and reply with the response. 


    Regards,
    Pranav Siddappa

  • Hi Ronan, 


    Instead of instead of using the address in the section block, can you create a memory block with this address and then use it along with the align function. 
    This should do the trick. 








    Regards, 
    Pranav Siddappa

  • Hello Pranav,

    In fact, you just did the same test that I did, just in a different way. And it shows exactly the same thing as mine did.

    So the 2 points are still open:

    1/ the inconsistency of the behavior compared to what is specified in the documentation

    2/ the questions regarding the label SAFESSU_lblPS0_LDA_VAR_START which is not equal to 0x20120004 but to the next address aligned on 4096

    Thank you

  • Hi Ronan, 


    In that case, sorry for the confusion. I have redirected the thread to the dedicated team for more detailed support. 



    Regards, 
    Pranav Siddappa

  • Hi Ronan,

    I am looking into this now. I'll report back once I have more information on the linker behavior.

    Regards,
    Mackay

  • Hi Ronan,

    The goal of this test was to verify the behavior of ". += align(4096);" when the start address of the output section is not aligned.

    To clarify when using the . += align(4096) operator the linker will advance the section address to the next absolute 4096-byte boundary from it's current address. It does not calculate a relative alignment to the start of the output section. In your case, starting at 0x200e2004, the next boundary 0x1000 byte aligned is 0x200e3000, which is why SAFESSU_lblPS0_LDA_VAR_END_2 is placed there. If your desired behavior is to intentionally create a 0x1000 byte hole you can use the . += operator with a set 0x1000 bytes size as so:

    .SSU_APR_AA_START :
    {
    . += 0x1000;
    } run = SRAM_LDAx, START(SAFESSU_lblPS0_LDA_VAR_START)

    .SSU_APR_AA_START_2 :
    {
    . += 0x1000;
    } run = 0x200e2004, START(SAFESSU_lblPS0_LDA_VAR_START_2), END(SAFESSU_lblPS0_LDA_VAR_END_2)
    However, in context to APR's it is better to use aligned addresses in conjunction with the PALIGN operator as mentioned in the documentation here: https://software-dl.ti.com/codegen/docs/c29clang/rel2_2_2_LTS/compiler_manual/linker_description/05_linker_command_files/the-sections-directive-stdz0759595.html?highlight=palign

    .SSU_APR_AA_START : {} run = SRAM_LDAx, palign(4096), 
    START(SAFESSU_lblPS0_LDA_VAR_START)

    .SSU_APR_AA_START_2 : {} run = SRAM_LDAx, palign(4096), 
    START(SAFESSU_lblPS0_LDA_VAR_START_2), END(SAFESSU_lblPS0_LDA_VAR_END_2)

    This will enforce that each section is placed on a n-byte aligned boundary and pad the end of the output section so that it ends on an n-byte aligned boundary
    enforcing each APR section to be 4096 byte aligned. Resulting in placement as so:

    0     200e2000  SAFESSU_lblPS0_LDA_VAR_START        
    0     200e3000  SAFESSU_lblPS0_LDA_VAR_START_2      
    0     200e4000  SAFESSU_lblPS0_LDA_VAR_END_2        

  • Hello Mackay,

    My test is there just to show that the behavior is inconsistent with the documentation.

    In your answer, you say that . += align(xxx) will align on the next address multiple of xxx.

    But as I said in my initial post, this is not what the documentation says.

    And this is problematic to not be able to trust the documentation.

    Regarding your proposal to do ".SSU_APR_AA_START : {} run = SRAM_LDAx, palign(4096), START(SAFESSU_lblPS0_LDA_VAR_START)", it does not work.

    I added ".SSU_APR_AA_START : {} > FLASH_RP0, palign(16384), START(SAFESSU_lblPS0_LDA_VAR_START)" between 2 output sections redirected of FLASH_RP0 (orig = 0x10001000) and .SSU_APR_AA_START address is 0x10004000 while the previous output section ends at 0x10027000 and the next section is not moved to be aligned on 16384 (its start address remains at 0x10027000).

    And previously, I did the same kind of tests on RAM with the same result (but I redid the test above just to be sure).

    And my guess is that this does not work because the section is empty (but not sure of that) and this is why I used:

    .SSU_APR_AA_START :
    {
       . += align(4096); /* Mandatory alignment for SSU APR */
    } run = SRAM_LDAx, START(SAFESSU_lblPS0_LDA_VAR_START)

    Ronan

  • Hi Ronan,

    But as I said in my initial post, this is not what the documentation says.

    I understand the confusion with the documentation and I have filled an enhancement for it here: EXT_EP-13762

    I added ".SSU_APR_AA_START : {} > FLASH_RP0, palign(16384), START(SAFESSU_lblPS0_LDA_VAR_START)" between 2 output sections

    Regarding you attempt to use palign, can you elaborate more on what you mean by adding the ".SSU" output sections between 2 other output sections?

    The order in which you place input sections in the linker command file does not order the placement by the linker. If you desire that behavior you will need to use the honor_cmdfile_order option documented here:https://software-dl.ti.com/codegen/docs/c29clang/rel2_2_2_LTS/compiler_manual/linker_description/05_linker_command_files/the-sections-directive-stdz0759595.html?highlight=honor_cmdfile_order

    the next section is not moved to be aligned on 16384 (its start address remains at 0x10027000).

    Every section you would like to be placed on aligned boundary will need to be annotated with the palign(16384) to gaurntee alignment.

    And my guess is that this does not work because the section is empty (but not sure of that) and this is why I used:

    The section being empty does not inherently impact the function of the . += align(4096) operator it will instead append the hole at the beginning of the section address.

    With these updates can you confirm the output of your test using palign?

    Regards,
    Mackay

  • Hello Mackay,

    Interesting choice of word: confusion.

    Here is exactly what the documentation says (already provided in my initial post):

    All values assigned to the . symbol within a section refer to the relative address within the section. The linker handles assignments to the . symbol as if the section started at address 0 (even if you have specified a binding address). Consider the statement . = align(16) in the example. This statement effectively aligns the file3.c.o .text section to start on a 16-byte boundary within outsect. If outsect is ultimately allocated to start on an address that is not aligned, the file3.c.o .text section will not be aligned either.

    Here is what you are saying and what my tests showed:

    . = align(16) or . += align(16) will move . on the next address in memory aligned on 16 bytes

    There is no confusion here, there is an error in the documentation.

    Also, in the ticket you created to "enhance" ("to correct" would have been more appropriate in my humble opinion) the documentation, you didn't mention this paragraph which is totally wrong. And a low priority seems also odd because, if I write a linker script based on the documentation, it will not work as expected.

    Regarding the order of output sections, this is in fact why I am already using the option "--honor_cmdfile_order".

    Regarding the text that I did, here is exactly the content of the linker script:

    .text.cpu1 : { <commands to capture input sections> } > FLASH_RP0, palign(4096)

    .SSU_APR_AA_START : {} > FLASH_RP0, palign(16384), START(SAFESSU_lblPS0_LDA_VAR_START)

    .rodata.cpu1 : { <commands to capture input sections> } > FLASH_RP0, palign(4096)

    .text.cpu1 starts at 0x10001000 and ends at 0x10027000.

    My expectation would be that .SSU_APR_AA_START starts and ends at 0x10028000 (first address aligned on 16384 after the section .text.cpu1) and that .rodata.cpu1 also starts at 0x10028000.

    But this is not the case. In fact, .SSU_APR_AA_START starts and ends at 0x10004000 (first address aligned on 16384 after the start of the memory FLASH_RP0, which is 0x10001000).

    Now, if I do:

    .text.cpu1 : { <commands to capture input sections> } > FLASH_RP0, palign(4096)

    .SSU_APR_AA_START : { . += align(16384); } > FLASH_RP0, START(SAFESSU_lblPS0_LDA_VAR_START)

    .rodata.cpu1 : { <commands to capture input sections> } > FLASH_RP0, palign(4096)

    .SSU_APR_AA_START starts and ends at 0x10028000 (first address aligned on 16384 after the section .text.cpu1) and .rodata.cpu1 also starts at 0x10028000.

    So, as I said in my previous post, ".SSU_APR_AA_START : {} > FLASH_RP0, palign(16384)" does not work and ".SSU_APR_AA_START : { . += align(16384); } > FLASH_RP0" does.

    And so, if your documentation is saying otherwise, it should be corrected.

    Thank you

  • Hi Ronan, I want to circle back to your first post because I believe there was a fundamental misunderstanding in the initial problem statement.

    the documentation says that the alignment is relative to the start of the section as if it was started at the address 0.


    In this clause in the documentation, we're talking about the alignment of an input section inside the output section. In the quoted text, this refers to the file3.c.o .text section being added to 'outsect' in the documentation example. The difference between input and output section is described in the linker command file primer https://software-dl.ti.com/ccs/esd/documents/sdto_cgt_Linker-Command-File-Primer.html#glossary

    The intent of this clause is to specify that input sections within an output section are placed and aligned relative to the start of the output section. For example:

    • Specify a 16-byte alignment for an input section
    • Place this input section into an output section, even after a dot expression such as 
      . = align(16)
    • Specify a run address of 0x4 for the output section
    • The result: The same warning you get, and the resulting input section may not be 16-byte aligned relative to the absolute memory map (that is, address & 0xF may not be 0), but will be 16-byte aligned relative to the output section ((address - 0x4) & 0xF is guaranteed to be 0)


    For 2/, the minimum alignment of an output section is the maximum alignment of all of its members. Assigning '.' to align is part of that list of members, so the output section is 4096-byte aligned. This is supported by the fact that there is a warning when specifying a non-4096 aligned address for the second output section in your example.

    As an aside, please note that it's not a common use-case to use '+=' when aligning SPC.

    See the example in the documentation, which only uses '= align(...)'. To see why, consider:

    . += 0x1
    . += align(4096) versus . = align(4096)
    
    . += 0x1 assigns SPC to 1
    align(0x1, 4096) = 4096
    So with =, SPC becomes 4096 and is aligned
    However, with +=, SPC becomes 4097.

  • Hi James,

    I tried to reproduce something similar to the example you described in the post (for me it does not seem that much different, but maybe it is).

    So, I did the following:

    .bss :
    {
       *(.bss.table4)
       . = align(64);
       *(.bss)
    } run = 0x80000004

    with table4 being a table of 5 bytes.

    And I got the following result:

    .bss 0 80000004 00000090 UNINITIALIZED
           80000004 00000005 led_ex1_blinky.o (.bss.table4)
           80000009 00000037 --HOLE--
           80000040 00000014 led_ex1_blinky.o (.bss.table)
           80000054 00000004 led_ex1_blinky.o (.bss.trigger_write)

    with table being an array of 5 integers.

    And for sure with the warning #10098-D: specific address 0x80000004 overrides alignment of 64 for ".bss".

    As you can see, .bss.table is aligned on 64 bytes without the shift of 4 bytes due to the non aligned starting address of the output section .bss.

    So, I suppose I missed something, but what is it ? What should I change in my test to demonstrate what the documentation specifies ?

    Regarding ". += align(xx)", you are right, that is not consistent with what I am trying to do. So, now I will use ". = align(xx)".

    Thank you

  • I can't get the linker to mis-align anything either.

    At some level, this is good, I think. If the linker didn't align addresses, some load/store/branch would fail during execution.

    However, the documentation is clearly wrong, at least for common sense cases. The implication is that an output section's structure may change if it happens to be bound to or placed at addresses with different alignment characteristics.

    The diagnostic is correct. The binding address is overriding the alignment of the section, but that's not entirely relevant to the layout of the output section in the end.

    You mentioned before that this was more a question of documentation, yes? Is there anything more you'd like us to do besides updating the misleading documentation to be more accurate?

  • Hi James,

    The current behavior is exactly what we need (that the ALIGN() works on the absolute address and not on the offset inside the output section). So, yes, our request is for the documentation to be updated to reflect the real behavior.

    Thank you

  • I will update Mackay's external Jira to reflect that.