This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

__attribute__((section("name"))) variable attribute

Hi,

I'm trying to have a certain variable lets say "const uint8_t Version[4] = {0x01,0x02,0x03,0x04}" at a specific place memory region.
For doing so i've used the section attribute of "__attribute__((section("name"))) variable attribute".
Here is the definition:
const uint8_t Version[4] __attribute__((section("VER_SECTION"))) = {0x01,0x02,0x03,0x04};

I've also added another execution region in the corresponding scatter file like below:
ER_VER __VER_BASE __VER_SIZE
 {
        opcodes.o (VER_SECTION)
 }

However during link stage i got the below error:
" Warning: L6329W: Pattern opcodes.o(VER_SECTION) only matches removed unused sections"

I though that using the "--keep" linker flag will help to solve the problem so i tried:
--keep="opcodes.o (VER_SECTION)"
but it didn't help.

Your help will be appreciated.

BTW, regarding "section attribute" usage i understood that "The section attribute specifies that a variable must be placed in a particular data section". While my variable is of const uint8_t which means it goes into RO/CODE area - maybe this is the problem root cause?

Thanks,
Ronen

Parents
  • Hi Ronen,

    The warning states the reason why this structure was removed - it is not referenced by the rest of the image.
    You could add the 'used' attribute:

    const uint8_t Version[4] __attribute__((section("VER_SECTION"), used)) = {0x01,0x02,0x03,0x04};

    FYI, you can see all sections that have been removed with the linker option --info=unused.

    Ronan

    PS - I just saw your reply... you should be using the section name?

Reply
  • Hi Ronen,

    The warning states the reason why this structure was removed - it is not referenced by the rest of the image.
    You could add the 'used' attribute:

    const uint8_t Version[4] __attribute__((section("VER_SECTION"), used)) = {0x01,0x02,0x03,0x04};

    FYI, you can see all sections that have been removed with the linker option --info=unused.

    Ronan

    PS - I just saw your reply... you should be using the section name?

Children
  • Hi Ronan,

    Here is the correct definition sequence:

    1. Variable definition using "attribute" :
      1. "const uint8_t VER_NUM[VER_NUM_SIZE_IN_BYTES] __attribute__((section("VER_NUM_SEC"))) = {0x01,0x02,0x03,0x04};"
    2. Scatter definition:
      1. ER_VER (__VER_BASE) (__VER_SIZE)
        {
             opcodes.o (VER_NUM_SEC)
        }
    3. linker --keep flag usage:
      1. ---keep="VER_NUM"

    As we can see, the ''--keep" points on the variable name ("VER_NUM") and not the section name ("VER_NUM_SEC").

    Thanks,
    Ronen