Skip to content

Objects with storage-class specifier static and attribute __nocache not initialized before "program startup" #85236

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jfischer-no opened this issue Feb 5, 2025 · 5 comments
Assignees
Labels
area: Kernel bug The issue is a bug, or the PR is fixing a bug priority: low Low impact/importance bug

Comments

@jfischer-no
Copy link
Collaborator

jfischer-no commented Feb 5, 2025

Describe the bug

Objects with storage-class specifier static and attribute __nocache not initialized before "program startup".

To Reproduce

diff --git a/samples/hello_world/src/main.c b/samples/hello_world/src/main.c
index c550ab461cb..1ae4ac8a45e 100644
--- a/samples/hello_world/src/main.c
+++ b/samples/hello_world/src/main.c
@@ -5,10 +5,17 @@
  */
 
 #include <stdio.h>
+#include <zephyr/kernel.h>
+
+static uint64_t __nocache __aligned(4) abc123;
+static uint64_t __nocache __aligned(4) abc456 = 42;
 
 int main(void)
 {
-       printf("Hello World! %s\n", CONFIG_BOARD_TARGET);
+       printf("Hello World! %s %llu %llu\n", CONFIG_BOARD_TARGET, abc123, abc456);
+       abc123 = 1;
+       abc456 = 2;
+       printf("Hello World! %s %llu %llu\n", CONFIG_BOARD_TARGET, abc123, abc456);
 
        return 0;
 }

Steps to reproduce the behavior:

  1. mkdir build; cd build
  2. cmake -DBOARD=mimxrt1020_evk -DCONFIG_NOCACHE_MEMORY=y ~/zephyr-project/zephyr/samples/hello_world/
  3. make
  4. See output

Expected behavior
I think the nocache section should not be initialized, but that is probably not inline with the specification when storage-class specifier static is used, anyway it needs to be documented.

Impact
Unknown

Logs and console output

*** Booting Zephyr OS build v4.0.0-4626-ge783f69ebfae ***
Hello World! mimxrt1020_evk/mimxrt1021 1610636641 42
Hello World! mimxrt1020_evk/mimxrt1021 1 2

(reset)

*** Booting Zephyr OS build v4.0.0-4626-ge783f69ebfae ***
Hello World! mimxrt1020_evk/mimxrt1021 1 2
Hello World! mimxrt1020_evk/mimxrt1021 1 2

Environment (please complete the following information):

  • OS:Linux
  • Toolchain Zephyr SDK
  • Commit SHA e783f69
@jfischer-no jfischer-no added area: Kernel bug The issue is a bug, or the PR is fixing a bug priority: low Low impact/importance bug labels Feb 5, 2025
@JarmouniA
Copy link
Collaborator

@jfischer-no __nocache alone doesn't suffice to place the object in nocache memory region, we need to know if CONFIG_NOCACHE_MEMORY is set or not.

#if defined(CONFIG_NOCACHE_MEMORY)

@jfischer-no
Copy link
Collaborator Author

@jfischer-no __nocache alone doesn't suffice to place the object in nocache memory region, we need to know if CONFIG_NOCACHE_MEMORY is set or not.

zephyr/include/zephyr/linker/section_tags.h

Line 53 in e783f69
#if defined(CONFIG_NOCACHE_MEMORY)

yes, it was already in the description but not visible, fixed it.

Copy link

github-actions bot commented Apr 7, 2025

This issue has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this issue will automatically be closed in 14 days. Note, that you can always re-open a closed issue at any time.

@jachatzi
Copy link
Contributor

@jfischer-no should be fixed on main now, as #87826 has been merged.

@jfischer-no
Copy link
Collaborator Author

@jfischer-no should be fixed on main now, as #87826 has been merged.

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Kernel bug The issue is a bug, or the PR is fixing a bug priority: low Low impact/importance bug
Projects
None yet
Development

No branches or pull requests

6 participants