January 18th, 2025

Fixing a uname bug (Apache NuttX RTOS)

A bug in Apache NuttX RTOS caused the `uname` command to omit the commit hash due to local copies of the static variable `g_version` in applications, requiring further investigation.

Read original articleLink Icon
Fixing a uname bug (Apache NuttX RTOS)

A bug was identified in the Apache NuttX RTOS related to the `uname` command, which failed to display the commit hash in its output. The issue arose from the static variable `g_version`, which is supposed to hold the commit hash derived from the `CONFIG_VERSION_BUILD` during the build process. The `uname` function, which is not a kernel call but a library function, retrieves this information. While the NuttX kernel correctly displayed the commit hash, the NuttX application did not, indicating a potential corruption or misconfiguration in the application environment. The investigation revealed that each NuttX application maintains its own local copy of `g_version`, which can lead to discrepancies if not properly initialized. The debugging process involved examining the disassembly of the application and confirming that the `uname` function was indeed accessing the local version of `g_version`. The findings suggest that the issue lies in how the application handles the static variable, necessitating further investigation and potential fixes to ensure that the correct commit hash is displayed consistently across both the kernel and applications.

- A bug in Apache NuttX RTOS caused the `uname` command to omit the commit hash.

- The `uname` function is a library function, not a kernel call, leading to local copies of `g_version` in applications.

- The NuttX kernel correctly displayed the commit hash, while applications did not, indicating a potential corruption.

- Debugging involved examining the disassembly of the application to trace the handling of `g_version`.

- Further investigation is needed to ensure consistent display of the commit hash across the system.

Link Icon 6 comments
By @zxilly - 15 days
I had recently run into an embedded problem where when switching the order of two functions in the source code, one of them would refuse to work. I tried a number of things without identifying the real error, and finally had to add a comment warning any later parties not to do this. I even checked the assembly and they seem to be consistent. But when I upload to firmware, the error keeps coming back over and over again.
By @amiga386 - 14 days
This is a fascinating article with a good detective story, and juicy details, but the images are very distracting.

They auto-scale to the correct aspect ratio to fill most of the width of the screen. On a mobile phone, sure, that's fine. On a widescreen monitor on a desktop computer, they are monstrously huge and don't fit on the screen.

In the CSS, rustdoc.css has img{max-width: 100%;}, but it also has .content,nav{max-width: 960px;} which is what's contraining the width of the article's text. The images look a lot better on widescreen with img{max-width: 960px;} to match... but then they don't scale correctly on the mobile layout.

By @Avamander - 15 days
Bugs like these are fun to read about, but never fun to debug if you need to get something else done. Nice writeup by Lup Yuen Lee once again.
By @InfiniteRand - 15 days
There are a number of edge cases in embedded where static variables can become unreliable. I am not saying it is common exactly but it is certainly not unheard of. I usually keep it in my list of things to check when stuff is mysteriously going wrong
By @ge96 - 15 days
I like his work on the pinephone
By @blueflow - 15 days
... what was the bug?