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
cmd/compile: bad codegen for 386 PIC code #15496
Comments
I should add that getting the disassembly from gdb required adding //go:noinline to heapBitsSetTypeNoScan (otherwise it gets inlined). To get the registerizer and peephole logs, I ran
The failure shows up in misc/cgo/testcshared:
|
Would it work to just switch the PC-relative sequence to a less-special register, like EBX? |
I was thinking the same thing. |
Though it looks like we hard-code BX for indirect calls (Thearch.REGCALLX), so maybe that's not safe? cgen64 hard-codes AX, CX, and DX. BP is free, but according to a comment in peep.go, we can't use BP with index-offset. The block moves use SI and DI, but maybe they're safe? Maybe the easiest thing is to use BX and change what we use for indirect calls. |
CL https://golang.org/cl/22652 mentions this issue. |
Pretty sure CX is least-special, for better or worse.
|
go version
)? Current master cd95657go env
)? linux/386PC-relative references in 386 code compiled with -buildmode=c-shared clobber ECX, but can occur in the middle of code sequences that are using ECX (I think because of shift instructions).
For example, heapBitsSetTypeNoScan in https://go-review.googlesource.com/#/c/22632/3 triggers this behavior, causing the runtime to crash very early because the h.bitp pointer wound up in ECX and was clobbered.
ecx is excluded from the register allocator, but code generation can pick it before register allocation happens, and then peephole optimization can spread it to many other places.
Here's an annotated heapBitsSetTypeNoScan, showing where clobbered %ecx values are being consumed. The
=>
is on the line that crashes with a clobbered pointer./cc @randall77 @mwhudson
The text was updated successfully, but these errors were encountered: