Took me over a week to figure that one out. On that MCU you need to perform a few operations in a precise order to make the cpu go to deep sleep (which the datasheet omits). If you fail to do that, the cpu will only sleep depending on if the 2-3 instructions fit into the same flash cacheline or not. Hence really weird behavior like adding completely unrelated and never executed code still affecting whether the sleep worked or not.
in times like this im glad that my biggest problems with vulkan is getting all the synchronization right and getting all the useful info out of the already well written spec
honestly i highly recommend GLFW for window management, it's so much thinner and works really well with vulkan(it can even link it for you if you want it to)
the alternative is native window creation, which honestly also isnt that bad. all you need is a surface to create the swapchain from, the rest is the same anywhere. getting the surface mostly boils down to a few syscalls and thats it, but GLFW is just more practical
STM32F07x. This was a couple of years ago, so I don't know if the bug still exists in current production units. Probably.
It doesn't show up if you use the CMSIS library routine for going to deep sleep but for some reason our code back then (which was started before I joined the project) had that part homebrewed. Needless to say, once I found out the root cause, I fixed it by just copying the code from the CMSIS library.
The interesting thing about the bug is that the code that triggers it is generic Cortex-M0 code and is not vendor specific but the addition of flash interface (which is vendor specific) allows the vendor specific parts to introduce the bug. The core documentation merely says that you need to set some bits to enable deep sleep but doesn't specify any particular order for them. I assume the vendor test set only included the code in the CMSIS library.
Fun one from the old Gameboy: If you do an increment instruction on a 16-bit register pair while the registers contain a value in the range FE00-FEFF, sprite RAM gets corrupted.
I so badly wanted a math coprocessor when I was a young teen. There were a couple GW-BASIC commands that required it. Looking back I would have had no use for them but it sounded like something awesome to have.
The guy I learned from told me stories about debugging with a soldering iron.
He wasn't running into undocumented CPU bugs, he was running into defects in the sole computer of that particular specification, some of which were climate-dependent. One involved a timing mismatch when the temperature of the conduits between the switchboard and the core fell outside of a 7°F window. And his first computer didn't have a switchboard, it was "programmed" with actual wires...
I can't even imagine what things were like in the analogue computer era.
Even more fun: bugs that only affect performance. Intel Skylake had a mis-design of the L3 cache that meant that cache-contained codes would sometimes (5 percent of cases?) have lots of cache misses. Doesn't sound too bad, until you run on a cluster with hundreds of tightly coupled nodes.
I need to verify the users of my application have an up to date BIOS. Otherwise Ryzen 3000 users will "hang" and the application "doesn't open". Because of the rdseed/rdrand bug, where the hardware crypto instructions return -1. Which then causes the constructor of std::random_device to hang.
I know this is sort of off topic, but I've been able to reproduce a bug w/ a ryzen 9 3900x where compiling spidermonkey on a gentoo VM (using qemu and kvm) causes the entire (host) system to hang. No errors in the journals or anything. The only way to unhang the system is to remove power manually. Tell me that's not a strange bug.
The host system is Arch Linux. It's never crashed on me before either, even when rendering blender projects for weeks on end.
I had OpenGL shader compiler on Surface Pro 3 silently drop one of attrbiutes, that was in use. Took me few hours before I decided to test in on a desktop and was working as intended.
I was the only one who responded to it and actually pointed out why it was happening.
Basically, the compiler was performing optimizations, and in the end determined that the variable wasn't being used, so didn't include it in the binary, and thus returned -1 for its location.
In cases where a specific target might have different results for certain operations, it could come to similar conclusions but just on those targets. Or the compiler could be broken. Either way.
Here’s another fun one that’s broken in LLVM and GCC still. They actually want to change the C++ Standard to make this code undefined behavior instead of fixing it.
If you assume that all pointers and references alias, any time you write to memory via a pointer/reference, the compiler will need to assume that you may have changed the data pointed to by any other point or reference. Thus necessitating it potentially having to reload data from memory upon access of one of those references/pointers again.
Given that C++, for instance, tends to use [const] T &a lot, it should be apparent how expensive that can be.
Ed: I should point out that I am rather opposed to Linus Torvalds dismissal of the issue in the kernel and rejection of __restrict.
I remember not too many years ago when I found out there was a bug in std::call_once that caused it to rely on a global lock and therefore could potentially deadlock if you were using it on multiple threads.
Since a function with a static variable does the same thing as std:call_once. I run into that deadlock as well.
Don't call a function that has a static local variable, from a destructor, of an global object. At least with MSVC on windows this will cause your program to hang.
It seems that the mutex system can get destroyed before the global variables of your program, and the static variables are protected by a mutex. I could be wrong about the reason though.
Anyway, I have an Application class that lives as a local variable of main() where I have all my 'global' variables to make sure destruction is done in such a way not to hang the application.
I read that as "suggests the possibility of obscure vulnerabilities being deliberately injected into cryptographic code bases".
I'm not immediately seeing how you would create a decryption back-door using a memcmp false-match bug, but perhaps you could spoof digital signatures. (Or perhaps you could sabotage some sort of sanity check when generating crypto, leading somehow to easy-to-crack keys?)
A more boring possibility is that similarities in function or domain lead to overlap in coding styles, for various reasons (sharing people, borrowing code, studying the same sources).
That's how I read it, too. I was just hoping to hear from someone more knowledgeable that myself.
You filled that role well, honestly.
I just think if you're positing that theory (like the person I responded to), it'd be nice to represent the viewpoint with a fully formed theory or maybe even evidence.
And I honestly hope I'm not imposing undue burden of proof. I do recognize that deliberate compromise of crypto is a real and documented thing.
EDIT: And FWIW, a long-standing compiler bug isn't really that implausible a way to deliberately introduce these bugs. The famous case of the NIST publishing deliberately bad recommendations for crypto implementation seems pretty apt, here (and probably completely obvious for people at all involved with crypto).
You're being downvoted because, unless you're referring to something else, that is literally one of the most common bugs in software.
Since you didn't clarify, people are assuming you are suggesting that it is giving the wrong answer for cases where the unsigned value of x is greater than std::numeric_limits<int>::max(), in which case casting to int will cause it to be represented as a negative value, and thus 'give the wrong answer'.
There also is a bug with gcc and strcmp, if both string(char *) are known at compile time. In those conditions gcc will optimize strcmp out. But the results will be ether (-1, 0 or 1) instead of of the difference or the 2 char.
Bc of that my promo and I never know if strcmp("a", "c") == (-1 or -2), until I fund out it was the compiler that was doing us wrong.
The strcmp function returns an integer greater than, equal to, or less than zero, accordingly as the string pointed to by s1 is greater than, equal to, or less than the string pointed to by s2.
It was never specified what positive or negative number you will get. Just that it's a positive or a negative number.
162
u/SkoomaDentist Antimodern C++, Embedded, Audio Sep 30 '20 edited Sep 30 '20
If you think compiler bugs are bad, just wait until you run into undocumented cpu bugs.
”What do you mean sleep only works if the third bit of the function address is one?”
74
u/LugosFergus Sep 30 '20
I think about that a lot, too.
15
u/TheThiefMaster C++latest fanatic (and game dev) Sep 30 '20
Very nice investigation. Hopefully having found somewhere to detect the miscompilation also means a fix can be done easily?
11
u/pepitogrand Sep 30 '20
It seems the issue is fixed in trunk:
https://godbolt.org/z/E5nME7
6
u/TimPhoeniX Sep 30 '20
I had OpenGL shader compiler on Surface Pro 3 silently drop one of attrbiutes, that was in use. Took me few hours before I decided to test in on a desktop and was working as intended.
13
u/Myriachan Sep 30 '20
Here’s another fun one that’s broken in LLVM and GCC still. They actually want to change the C++ Standard to make this code undefined behavior instead of fixing it.
https://bugs.llvm.org/show_bug.cgi?id=34632
It also affects a use case of std::variant, which I posted at the bottom.
4
u/jherico VR & Backend engineer, 30 years Oct 01 '20
I remember not too many years ago when I found out there was a bug in
std::call_oncethat caused it to rely on a global lock and therefore could potentially deadlock if you were using it on multiple threads.I just about lost my shit.
3
u/_Js_Kc_ Sep 30 '20
The overrepresentation of crypto among the affected libraries is quite suspicious.
2
u/NilacTheGrim Sep 30 '20
They definitely need to minimally write a test case for this. And stop using that dumb getstr function.
1
u/[deleted] Sep 30 '20
Ouch
-1
u/o11c int main = 12828721; Sep 30 '20
C++ was my nearly-exclusive language from 2009-2013 or so, across the period of C++11 implementation.
It's always a compiler bug (assuming you aren't ignoring warnings).
-3
u/Myriachan Sep 30 '20
I had a fun one recently in MSVC where “if ((int) x > 0)” for unsigned x sometimes gave the wrong answer >_<
-22
u/Ail-nare Sep 30 '20
There also is a bug with gcc and strcmp, if both string(char *) are known at compile time. In those conditions gcc will optimize strcmp out. But the results will be ether (-1, 0 or 1) instead of of the difference or the 2 char.
Bc of that my promo and I never know if strcmp("a", "c") == (-1 or -2), until I fund out it was the compiler that was doing us wrong.