-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
hal: nxp: ARRAY_SIZE collision #51371
Comments
It turns out we have yet another case:
|
One could argue that Zephyr should consider namespace protection as well. While I agree that we shouldn't rely on include order the reason we have to is because for some reason the Zephyr project decided not to protect these generic definitions with "#ifndef" type of constructs like the NXP SDK does. So when we create our NXP shim drivers we ensure the order of includes to protect against this problem. The logistics of actually changing this in our HAL is much more problematic due to how the NXP HAL is sourced. It isn't clear to me why we can't just put the name space collision check in the Zephyr code? |
Using |
I understand you don't like ordering include files and you have a concern that the definition doesn't align if you happen to do the wrong order. So this problem is going to continue to happen since Zephyr doesn't protect this commonly defined macro. If we are that concerned that a common macro is not going to be defined correctly by these included modules then we should make a change to the Zephyr definition. Either of these would work (one seems less annoying):
See the following as a separate example Also, quick search of the tree finds the following: \bootloader\mcuboot\boot\boot_serial\src\zcbor_common.h:#333 Every time we include a new module or HAL with this particular approach we have to confirm that this new module isn't trying to define ARRAY_SIZE and if it does then we have to change the module code instead of changing things once in the Zephyr code base. |
I'm not sure how you reached this conclusion, I've precisely proposed to follow Google include guidelines a few times, https://google.github.io/styleguide/cppguide.html#Names_and_Order_of_Includes. Zephyr is now a mess in this area, just see the issues triggered by this single commit: a6a4400. Namespacing the Zephyr one is definitely an option that we should consider, specially because we integrate with many 3rd party code that doesn't necessarily follow good practices. I wish Zephyr had a namespace for everything, actually. Lacking formal namespaces, this is something every C project should do, specially libraries or code integrating other libraries like Zephyr.
Even if Zephyr adds a namespace, one could still see clashes if using 2 3rd party libraries in Zephyr. The best solution in the end is that every library does proper namespacing.
#undef is discouraged by e.g. MISRA, so if we care about safety we should likely follow the advice. #undef also makes 3rd party code use another implementation without any warning or sign, current patch makes it clear that hey, we've done this conscious choice in the context of Zephyr.
We should really pay more attention to what gets in as modules and not accept everything. You could have security issues because of module bugs, for example. And... let's not open the debate about the size of |
Again, in this particular case with ARRAY_SIZE, I think it is arguable that the issue should be fixed on the Zephyr side and not on the modules we include. Where there are collisions between modules/libraries we can fix that but in most all of those cases, the modules have the #ifndef framing around the define. |
Note: see full discussion in https://discord.com/channels/720317445772017664/1014241011989487716/1032623375228608522 |
This commit is the outcome of the discussion that has taken place in multiple forums: Discord: https://discord.com/channels/720317445772017664/1014241011989487716/1032623375228608522 GitHub: zephyrproject-rtos#51371 zephyrproject-rtos#50239 Signed-off-by: Carles Cufi <[email protected]>
This commit is the outcome of the discussion that has taken place in multiple forums: Discord: https://discord.com/channels/720317445772017664/1014241011989487716/1032623375228608522 GitHub: zephyrproject-rtos#51371 zephyrproject-rtos#50239 Signed-off-by: Carles Cufi <[email protected]>
This commit is the outcome of the discussion that has taken place in multiple forums: Discord: https://discord.com/channels/720317445772017664/1014241011989487716/1032623375228608522 GitHub: zephyrproject-rtos#51371 zephyrproject-rtos#50239 Signed-off-by: Carles Cufi <[email protected]>
This commit is the outcome of the discussion that has taken place in multiple forums: Discord: https://discord.com/channels/720317445772017664/1014241011989487716/1032623375228608522 GitHub: #51371 #50239 Signed-off-by: Carles Cufi <[email protected]>
This commit is the outcome of the discussion that has taken place in multiple forums: Discord: https://discord.com/channels/720317445772017664/1014241011989487716/1032623375228608522 GitHub: zephyrproject-rtos/zephyr#51371 zephyrproject-rtos/zephyr#50239 (cherry picked from commit d095f7d) Original-Signed-off-by: Carles Cufi <[email protected]> GitOrigin-RevId: d095f7d Change-Id: I473d1b1f55da92b34bd429cd60f0cf75488ed5d4 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/zephyr/+/4287511 Tested-by: Keith Short <[email protected]> Reviewed-by: Keith Short <[email protected]> Tested-by: Al Semjonovs <[email protected]> Commit-Queue: Al Semjonovs <[email protected]> Tested-by: CopyBot Service Account <[email protected]> Reviewed-by: Al Semjonovs <[email protected]>
This commit is the outcome of the discussion that has taken place in multiple forums: Discord: https://discord.com/channels/720317445772017664/1014241011989487716/1032623375228608522 GitHub: zephyrproject-rtos#51371 zephyrproject-rtos#50239 Signed-off-by: Carles Cufi <[email protected]>
Describe the bug
It looks like hal_nxp (mcux-sdk code) defines its own
ARRAY_SIZE
in a public scope, thus polluting the namespace. While it doesn't re-define if already defined, it is still problematic if included beforezephyr/sys/util.h
, and we should not rely on include order. In some situations, one can observe now:To Reproduce
Expected behavior
HAL respects Zephyr
ARRAY_SIZE
. There are multiple ways to solve this:FSL_ARRAY_SIZE
Impact
Build warnings, CI failures.
Logs and console output
See above.
Environment (please complete the following information):
Additional context
https://github.com/zephyrproject-rtos/zephyr/actions/runs/3272340917/jobs/5383270655
The text was updated successfully, but these errors were encountered: