Live data from Hacker News

We found a bug in Go's ARM64 compiler

blog.cloudflare.com

121–130 of 146 posts

Re: We found a bug in Go's ARM64 compiler

#121
post #5

Earlier quoted context omitted.

> So another win for being able to read arm assembly. Yes, though that weird stuff with dollars in it is not normal AArch64 assembly! The article could have mentioned the "stack moves once" rule.

> Yes, though that weird stuff with dollars in it is not normal AArch64 assembly! See the AT&T vs Intel syntax since you aren't familiar with assembly: https://en.wikipedia.org/wiki/X86_assembly_language#Syntax

That's an x86 thing, though.

Re: We found a bug in Go's ARM64 compiler

#123
post #29

Earlier quoted context omitted.

Yeah but we have codegen bugs in .NET as well. The biggest difference that stood out to me in this write up, is we would have gone straight for “coredump” instead of other investigation tools. Our default mode of investigating memory corruption issues is dumps.

Sure, I have experienced them, e.g. once in 2006 using IBM's JVM implementation with Websphere. However it is probably not as problematic due to the way Go allows for Assembly being used directly. While the JVM and CLR don't allow for direct access to Assembly code, Go does, thus I assume expecting safepoints everywhere is not an option, as any subroutine call can land on code that was manually written.

Go users can only insert assembly wrapped in a function call. That might be safety related, I am not entirely sure.

(Well technically there is a way to inject assembly without the function call overhead. That's what https://pkg.go.dev/runtime/internal/atomic is doing. But you will need to modify the runtime and compiler toolchain for it.)

Re: We found a bug in Go's ARM64 compiler

#124
I find it interesting, how rare it has become to find s compiler bug. For me, at least, it used to be a regular event.

Even Java, as widespread as it is, I have made half-a-dozen reports. None in the last several years, though.

Better testing? The sheer scale of software being produced?

Re: We found a bug in Go's ARM64 compiler

#125

I find it interesting, how rare it has become to find s compiler bug. For me, at least, it used to be a regular event. Even Java, as widespread as it is, I have made half-a-dozen reports. None in the last several years, though. Better testing? The sheer scale of software being produced?

Linus's law [1]? When it comes to compilers for mainstream languages, the userbases are so large that they will explore a surprisingly large portion of the compiler's state space.

But definitely, better engineering and QA practices must also help here.

[1] https://en.wikipedia.org/wiki/Linus%27s_law

Re: We found a bug in Go's ARM64 compiler

#126

Always adjust your stack pointer atomically, kids.

I guess those that wrote the preemption were on X86 where this doesn't happen thanks to variable length instructions being able to hold the constant and thus relied on the code-gen to do it atomically, then the ARM port had an automatic "split" from a higher level to make things "easy" thus giving us this bug. Nobodys fault really, but bad results ensued.

Hands up, the dozens of us pedants that have used a relaxed atomic add in situations like these. Updating the SP in the most paranoid way possible is the reason that sort of thing exists.

(You cannot express relaxed atomics in golang, but you could technically add support in the compiler for use in the runtime code)

Re: We found a bug in Go's ARM64 compiler

#127
post #3

That's an incredible find and once I saw the assembly I was right along with them on the debug path. Interestingly it doesn't need to be assembly for this to work, it's just that that's where the split was. The IR could've done it, it just doesn't for very good reasons. So another win for being able to read arm assembly. Unsure if this would be another way to do it but to save an instruction at the cost of a memory a…

[dead]

Re: We found a bug in Go's ARM64 compiler

#128

Earlier quoted context omitted.

It becomes fun when you narrow down to the solution. Before that it's hell. I don't think I'd be allowed spend weeks to debug something like this. Credit to Cloudflare's PMs.

Apparently they have a "unexplained crashes must have an explanation determined" policy ever since there was a trend of uninvestigated unexplained crashes that were canaries in the mine for a security issue. https://blog.cloudflare.com/however-improbable-the-story-of-... > But [the Cloudbleed sensitive information disclosure security incident] wasn’t the only consequence of the bug. Sometimes it could lead to an inva…

Yes, and we set up all the tooling for that and I would look at the output every single day and keep an eye on what was happening. Any team that didn't fix a crash quickly got a personal message from me. That responsibility has been taken over by others now.

Re: We found a bug in Go's ARM64 compiler

#129
Great find and writeup.

As an aside, this is the type of a problem that I think model checkers can't help with. You can write perfect and complicated TLA+/Lean/FizzBee models and even if somehow these models can generate code for you from your correct models you can still run into bugs like these due to platform/compiler/language issues. But, thankfully, such bugs are rare.

Re: We found a bug in Go's ARM64 compiler

#130
post #129

Great find and writeup. As an aside, this is the type of a problem that I think model checkers can't help with. You can write perfect and complicated TLA+/Lean/FizzBee models and even if somehow these models can generate code for you from your correct models you can still run into bugs like these due to platform/compiler/language issues. But, thankfully, such bugs are rare.

Yep. Model checking is for checking that your design is sound, basically, not at all the implementation.

For the implementation, you can use certified compilers like CompCert [1], but:

- you still have to show your code is correct

- there are still parts of CompCert that are not certified

[1] https://compcert.org/

Post reply on HN