-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
lib: os: assert: Add unreachable path hint for assertion failure #48710
lib: os: assert: Add unreachable path hint for assertion failure #48710
Conversation
It looks like I just opened a Pandora's box ... converting to a draft. |
Besides the build failures due to the now-working warnings, the run-time failures (e.g. in |
d765f76
to
aea23e9
Compare
The if ((pre_addr & TARGET_PAGE_MASK) == (post_addr & TARGET_PAGE_MASK)) {
pre = opcode_at(&ctx->base, pre_addr);
ebreak = opcode_at(&ctx->base, ebreak_addr);
post = opcode_at(&ctx->base, post_addr);
} It just happened to be that the changes in this PR caused the @keith-packard any suggestions on how we should address this? p.s. for now, I have created #48745 to work around this issue. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like the API is just broken and 'chan' should be an unsigned type? I realize that's a very different change, but it seems like it might be better in the long run.
I'll note that soc/arm/nordic_nrf/nrf32/sync_rtc.c uses 'uint8_t' to hold the channel number.
Ideally, it should be an unsigned type, but I did not want to make more changes than necessary for now. By the way, that commit was only added to this PR for testing purpose; it is originally from #48729, which already got merged. |
@keith-packard re #48710 (comment), should it be updated to require the trap instructions to be placed in the same page only if the MMU is enabled? |
Sure, that would be in conformance with the spec. The picolibc version doesn't bother with the special case, but as zephyr knows whether there's an MMU in use, it could. Given that it's only for semihosting, which is unlikely to be used in production, I'm not sure it's all that important though? |
Oh well. Other than that, yes, these changes look good to me. |
Fair enough, it is simple enough to work around as done in #48745. While it would be nice if QEMU properly handles the non-MMU case, it is really not that important. |
2fc3409
to
aa6dbf2
Compare
This commit adds the `CODE_UNREACHABLE` hint at the end of the assertion failure branch so that the compiler takes note of the assert function not returning when an assertion fails. This prevents the compiler from generating misguided warnings assuming the asserted execution paths. It also introduces the `ASSERT_TEST` Kconfig symbol, which indicates that the "assert test mode" is enabled. This symbol may be selected by the tests that require the assert post action function to return without aborting so that the test can proceed. Note that the `CODE_UNREACHABLE` hint is specified only when the assert test mode is disabled in order to prevent the tests from crashing when the assert post action function returns. Signed-off-by: Stephanos Ioannidis <[email protected]>
This commit enables the assert test mode (`CONFIG_ASSERT_TEST`) for the ztest error hook test because it implements a custom post assert fail hook (`ztest_post_assert_fail_hook`) that returns without aborting to faciliate the testing of the assert functions. Signed-off-by: Stephanos Ioannidis <[email protected]>
This commit enables the assert test mode (`CONFIG_ASSERT_TEST`) for the ARM interrupt test because it relies on the assert function to return without aborting in the in-ISR "Intentional assert" test. Signed-off-by: Stephanos Ioannidis <[email protected]>
This commit enables the assert test mode (`CONFIG_ASSERT_TEST`) for the ARM interrupt test because it relies on the assert function to return without aborting in the "Assert occurring inside kernel panic" test. Signed-off-by: Stephanos Ioannidis <[email protected]>
aa6dbf2
to
e8aa6ca
Compare
Ready for review |
Hrm. Having reviewed the code in a bit more detail, I find that I'm now more confused than I was before. |
Under normal circumstances, the |
Yes, that part I followed, but (as I said), this ended up making me more confused -- this normal case now includes an annotation that code past the call to Note -- I'm not saying that your patch isn't right and good (which it seems to be), only that I can't understand why the compiler doesn't emit errors while compiling it due to the mismatching attributes. Probably just something I've missed. |
From https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html:
The reason I did not add |
Thanks much for explaining what's going on. I "should" have known what
Is that only true when |
Correct.
Also correct. However, In short, adding |
Yeah, and the win for fixing it all would be quite small -- the potential compiler optimizations are not interesting in this path, and even the compiler messages would be of marginal value when all of the names are 'abort/fatal/...'. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for taking time to explain why this patch looks the way it does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been hiding from the minutiae of the interactions being discussed, but the code as it appears in the final PR seems totally reasonable.
This commit adds the
CODE_UNREACHABLE
hint at the end of theassertion failure branch so that the compiler takes note of the assert
function not returning when an assertion fails.
This prevents the compiler from generating misguided warnings assuming
the asserted execution paths.
It also introduces the
ASSERT_TEST
Kconfig symbol, which indicatesthat the "assert test mode" is enabled. This symbol may be selected by
the tests that require the assert post action function to return
without aborting so that the test can proceed.
Note that the
CODE_UNREACHABLE
hint is specified only when the asserttest mode is disabled in order to prevent the tests from crashing when
the assert post action function returns.
Signed-off-by: Stephanos Ioannidis [email protected]
p.s. an example of the "misguided warnings": zephyrproject-rtos/sdk-ng#530 (reply in thread)