This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Can't compile section variables in unit test framework

I am using the Ceedling framework for unit testing my firmware. This has qorked quite well. But now I wanted to use the section variables to decouple my code a bit more. And I could not compile them on windows, using gcc. The problem is that I can't use a linker script on windows, so I can't create the __start_section_name symbols.

But it turns out that gcc (or rather, ld) already makes those symbols, but only when the section name does not start with a dot ('.'). I tested this by removing the dot from nrf_section.h, into:

#elif defined(__GNUC__)
#define NRF_SECTION_ITEM_REGISTER(section_name, section_var) \
    section_var __attribute__ ((section(STRINGIFY(section_name)))) __attribute__((used))

that seems to work. The linker script can now also be simplified, the __start and __end symbols are now no longer needed in there, as ld handles that for us.

Is there a reason for the leading dot that I am missing? Can I safely remove it? If so, are there plans to add that change to a future SDK?

Thanks,

Michiel

Parents Reply Children
  • when use the nrf_queue_def, "section attribute cannot be specified for local variables",i donot konw why,i have declear the ".nrf_queue" in the ld file.

  • ../send_rf.c:70:33: error: section attribute cannot be specified for local variables
    70 | NRF_QUEUE_DEF(queue_data_t, my_data_queue, 5, NRF_QUEUE_MODE_NO_OVERFLOW);
    | ^~~~~~~~~~~~~
    ../../sdk_nordic/components/libraries/experimental_section_vars/nrf_section.h:149:5: note: in definition of macro 'NRF_SECTION_ITEM_REGISTER'
    149 | section_var __attribute__ ((section("." STRINGIFY(section_name)))) __attribute__((used))
    | ^~~~~~~~~~~
    ../send_rf.c:70:5: note: in expansion of macro 'NRF_QUEUE_DEF'
    70 | NRF_QUEUE_DEF(queue_data_t, my_data_queue, 5, NRF_QUEUE_MODE_NO_OVERFLOW);
    | ^~~~~~~~~~~~~
    ../send_rf.c:70:5: error: 'used' attribute ignored [-Werror=attributes]

Related