Skip to content

linker: section_tags: missing include #76254

Closed
@Finomnis

Description

@Finomnis

Describe the bug
Using section tags like __dtcm_noinit_section should resolve to:

__attribute__((section(".dtcm_noinit"), used))

However, due to a missing include, they resolve to:

__attribute__((section("_DTCM_NOINIT_SECTION_NAME"), used))

... failing to move the variable to the proper section and causing the following warning:

ld.bfd.exe: warning: orphan section `_DTCM_NOINIT_SECTION_NAME' from `app/libapp.a(main.c.obj)' being placed in section `_DTCM_NOINIT_SECTION_NAME'

To Reproduce

  • Checkout Zephyr in a workspace
  • modify samples/hello_world/src/main.c to contain:
    #include <stdio.h>
    
    #include <zephyr/linker/section_tags.h>
    
    __dtcm_bss_section int data[1024];
    
    int main(void)
    {
    	// Just some usage of the variable to prevent optimizing it away
    	for (int i = 0; i < 1024; i++) {
    		data[i] = i * i;
    	}
    
    	int result = 0;
    	for (int i = 0; i < 1024; i++) {
    		result += data[i];
    	}
    
    	printf("Result: %d", result);
    
    	return 0;
    }
  • Run west build -b mimxrt1170_evk/mimxrt1176/cm7 samples/hello_world/

Expected behavior

-- west build: building application
[1/134] Generating include/generated/zephyr/version.h
-- Zephyr version: 3.7.0-rc3 (C:/Users/Martin/work/zephyrproject/zephyr), build: v3.7.0-rc3-91-gf9e3b65d3a97
[134/134] Linking C executable zephyr\zephyr.elf
Memory region         Used Size  Region Size  %age Used
           FLASH:       40302 B        16 MB      0.24%
             RAM:        4416 B        64 MB      0.01%
           OCRAM:          0 GB       256 KB      0.00%
          OCRAM1:          0 GB       512 KB      0.00%
          OCRAM2:          0 GB       512 KB      0.00%
            ITCM:          0 GB       256 KB      0.00%
            DTCM:          4 KB       256 KB      1.56%
        IDT_LIST:          0 GB        32 KB      0.00%

Impact
All projects that use <zephyr/linker/linker_sections.h> directly fail to link to the appropriate section.
There is no indication anywhere that this header cannot be used directly. (at least none that I could find)

Logs and console output

-- west build: building application
[1/134] Generating include/generated/zephyr/version.h
-- Zephyr version: 3.7.0-rc3 (C:/Users/Martin/work/zephyrproject/zephyr), build: v3.7.0-rc3-91-gf9e3b65d3a97
[129/134] Linking C executable zephyr\zephyr_pre0.elf
c:/zephyr-sdk-0.16.8/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd.exe: warning: orphan section `_DTCM_BSS_SECTION_NAME' from `app/libapp.a(main.c.obj)' being placed in section `_DTCM_BSS_SECTION_NAME'
[134/134] Linking C executable zephyr\zephyr.elf
c:/zephyr-sdk-0.16.8/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd.exe: warning: orphan section `_DTCM_BSS_SECTION_NAME' from `app/libapp.a(main.c.obj)' being placed in section `_DTCM_BSS_SECTION_NAME'
Memory region         Used Size  Region Size  %age Used
           FLASH:       44398 B        16 MB      0.26%
             RAM:        8512 B        64 MB      0.01%
           OCRAM:          0 GB       256 KB      0.00%
          OCRAM1:          0 GB       512 KB      0.00%
          OCRAM2:          0 GB       512 KB      0.00%
            ITCM:          0 GB       256 KB      0.00%
            DTCM:          0 GB       256 KB      0.00%
        IDT_LIST:          0 GB        32 KB      0.00%

Additional context
This wasn't reproducible on any of the examples before, because the ones that are susceptible (like samples/boards/mimxrt1170_evk_cm7/magic_addr/) include <zephyr/kernel.h>, which indirectly pulls in the required header to resolve the defines:

  • #include <zephyr/kernel.h>
  • #include <zephyr/kernel_includes.h>
  • #include <zephyr/linker/sections.h>

Workarounds
Including <zephyr/kernel.h> or <zephyr/linker/sections.h> in user code fixes this issue.

Environment (please complete the following information):

  • OS: Windows 11
  • Zephyr SDK 0.16.8
  • Used commit f9e3b65 (Zephyr v3.7.0-rc3 + main)

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions