News for hackers. Stuff that matters.
Re:We found a bug in Go's ARM64 compiler by pklausler on Wednesday October 08, 2025 @01:40PM (#45518661)
I'm a little surprised that this bug wasn't fixed in the assembler as a special case for immediate adds to RSP. If the patch was to the compiler only, other instances of the bug could be lurking out there in aarch64 assembly code.
Re:We found a bug in Go's ARM64 compiler by moefh on Wednesday October 08, 2025 @06:12PM (#45521184)
Would that be wise? The implemented solution uses a temporary register to hold the full value being added to rsp.

I don't know enough about how people use the go assembler, but I imagine it would be very surprising if `add $imm, rsp, rsp` clobbered an unrelated register when `$imm` is large enough. Especially since what's clobbered is the designated "temporary register", which I imagine is used all the time in handwritten go assembly.

Re:We found a bug in Go's ARM64 compiler by pklausler on Wednesday October 08, 2025 @07:34PM (#45521835)
Some architectures, and I believe aarch64 is one, have scratch registers reserved for being clobbered in special situations required by the assembler.
Re:We found a bug in Go's ARM64 compiler by anyfoo on Wednesday October 08, 2025 @08:19PM (#45522096)
Not really, or at least not that I know if in the case of arm64. What you have is calling conventions that specify what one function/procedure/whatever can expect both from the caller and the callee's side.n I.e. some registers are caller-saved, some are callee-saved, which basically means the called function can treat them as "scratch".

Additionally, they call out interactions with the OS/execution environment. For example, x18 is the "platform register", and it's unspecified what the OS does with it. It's entirely possible that it clobbers it on context switch or during an interrupt or whatever. So don't use that one unless you have a contract with the OS itself.

But locally, i.e. "from instruction to instruction", no such convention exists to my knowledge, and you probably don't want to have registers that pseudo-instructions might trash inadvertently in general, because it means you can't optimally use these registers.

It's possible for pseudo-instructions or generally macros to be documented as, e.g., "this macro uses x3 as a temporary register and trashes it", but in my experience most macros that need additional temporary registers actually ask you to specify them as part of the macro invocation.

E.g. suppose you have a macro "weirdhash" that takes two registers and saves some kind of hash of them in a third register, but that also needs an extra register to perform its work. You would call it with:

    weirdhash x9, x10, x11, x0
Where x0 would be the scratch register you don't care about.
Re:We found a bug in Go's ARM64 compiler by adastra22 on Thursday October 09, 2025 @04:11AM (#45524910)
There are some architectures that do, but they're all old RISC chips.
Re:We found a bug in Go's ARM64 compiler by immibis on Thursday October 09, 2025 @01:08PM (#45530382)
On some architectures there is a register reserved for assembler use, and even registers reserved for kernel use which can be changed in interrupt handlers and not changed back.
Re:We found a bug in Go's ARM64 compiler by anyfoo on Thursday October 09, 2025 @07:44PM (#45534171)
Yeah, I mentioned x18 on arm64 as an example for the latter one. Didn't know about the register reserved for assembly use, apparently MIPS indeed had that: $1, also known as $at, is the "assembler temporary".
Re:We found a bug in Go's ARM64 compiler by saagarjha on Wednesday October 08, 2025 @10:38PM (#45522921)
No, I think that’s just a MIPS thing.
Re:We found a bug in Go's ARM64 compiler by Someone on Thursday October 09, 2025 @04:11AM (#45524905)
Is that possible? I think you would have [1] to use a register to build up the immediate value. The assembler cannot/should not default to one, so I think the best one could do is having another macro for ADD that takes that helper register as an argument. That wouldn’t fix other instances in the AArch64 assembly code.

[1] I’m not familiar with AMD64, but maybe, you could use a thread local or reserve space in the stack frame for it, too, but I don’t see those as realistic options