I’ve spent the last few weeks working with the security architecture of the nRF54L series from Nordic Semiconductor (in case you missed it, I recently joined Nordic!). While doing so, I have engaged my typical…

74 points•hasheddan•9 days ago•20 comments•

20 comments

pletnes6 days ago
Reminds me of the time when visual studio would show one value of a variable, but print would show a different one. Never trusted VS again after that.
Loren_SL8 days ago
Nice writeup. WinDbg has the same stale-cache trap on live Windows targets.
zavec6 days ago
Very cool! I love reading about details like this.
LoganDark6 days ago
Once upon a time I had to figure out an issue where I forgot a `return` statement at the end of a non-`void` function, so the C++ compiler happily omitted both RETs for some reason and let the program go straight into illegal instructions. That was fun to debug (not fun, I practically had to single-step through the entire program) because every time this happened the debugger was incredibly confused about what the fuck was going on and nothing made any sense.
VorpalWay6 days ago
It makes no sense to me that C and C++ didn't require a diagnostic for this, rather you hit UB.

I know that at least modern GCC and Clang will warn and/or error for this (not sure which as I use -Werror), but still, this is pointless UB to have.

And no, in this case I don't buy that a C90 compiler would have been unable to check this.

jcranmer6 days ago
Having been involved in the WG14 discussions on this topic:

The issue is that there is a contingent of users who complains about cases where the return dynamically can't be hit but that isn't obvious statically. Consider something like this:

  int do_something(enum meow koala) {
    switch (koala) {
    case enum_val_1: return 5;
    case enum_val_2: return 3;
    /* etc., covering all the enum values */
    }
  }
Should this be required to diagnose? That's the sticking point.
StilesCrisis4 days ago
In some cases it's easy to diagnose, but in others it amounts to the halting problem, so it makes sense that the requirements are loose. Like many things, the standards body considers it a "quality of implementation" issue for compilers to be friendly.
Brian_K_White6 days ago
It seems like something that could have been trapped right in k&r.

Was it ever even theoretically under any circumstances for any reason intended to be able to write a stack of functions with no returns that just fall into each other like assembly? I can't believe it.

So it seems like something even the very first compiler could have cought right in an early parser pass or stage.

But I also decline to believe I have a better idea about something than K or R, so there must be a non-triviality I don't see. I mean goto() exists in the language so ?

... I guess simply detecting the end of a function, or detecting that the process reached the end of a function, isn't a good enough definition of the problem. You can have any number of returns or gotos in the middle that you are always supposed to hit, and intentionally no return at the end because instead you have an assert or a goto.

assert you should never get here, goto error, goto not error but just next step, etc. They might or might not be error conditions that the process reached that spot, but it's not an error that the code doesn't end with a return.

LoganDark6 days ago
I think I was using C++14 at the time...
StilesCrisis6 days ago
Real
LoganDark6 days ago
Another issue that happened in the same project is that for some reason whenever I compiled it with a regular C++ compiler, field writes were disappearing into the abyss. I think I actually never figured that out because it was literally the same object at the same memory address, there were no other threads and yet when a subroutine returned after writing the field, the write disappeared?? The strangest thing is that Emscripten's C++-to-WASM cross-compiler worked perfectly fine with the exact same routines. I wonder if the compiler I used simply had fuckass issues, it was an oldish (by modern standards) Apple clang from like probably macOS 10.14 or so.
sharktheone6 days ago
Debuggers can lie pretty often. Especially if you are just doing things with ASM. I had some issues with V8 debugging and the debugger just saying that a function got called which for sure wasn't. Even with the option that V8 should emit gdb info :/

Read the full thread on Hacker News →

Related stories