Skip to content

cmd/cgo: fix unaligned arguments typedmemmove crash on iOS #1

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions src/cmd/asm/internal/asm/testdata/loong64enc1.s
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,16 @@ lable2:
VMOVQ V3.W[1], V7.W4 // 67e4f772
VMOVQ V4.V[0], V6.V2 // 86f0f772

// Load data from memory and broadcast to each element of a vector register: VMOVQ offset(Rj), <Vd>.<T>
VMOVQ (R4), V0.B16 // 80008030
VMOVQ 1(R4), V1.H8 // 81044030
VMOVQ 2(R4), V2.W4 // 82082030
VMOVQ 3(R4), V3.V2 // 830c1030
XVMOVQ (R4), X0.B32 // 80008032
XVMOVQ 1(R4), X1.H16 // 81044032
XVMOVQ 2(R4), X2.W8 // 82082032
XVMOVQ 3(R4), X3.V4 // 830c1032

// VSEQ{B,H,W,V}, XVSEQ{B,H,W,V} instruction
VSEQB V1, V2, V3 // 43040070
VSEQH V1, V2, V3 // 43840070
Expand Down Expand Up @@ -1035,3 +1045,53 @@ lable2:
PRELD (R4), $0 // 8000c02a
PRELD -1(R4), $8 // 88fcff2a
PRELD 8(R4), $31 // 9f20c02a

// [X]{VBITCLR/VBITSET/VBITREV}{B,H,W,V} instructions
VBITCLRB V1, V2, V3 // 43040c71
VBITCLRH V1, V2, V3 // 43840c71
VBITCLRW V1, V2, V3 // 43040d71
VBITCLRV V1, V2, V3 // 43840d71
VBITSETB V1, V2, V3 // 43040e71
VBITSETH V1, V2, V3 // 43840e71
VBITSETW V1, V2, V3 // 43040f71
VBITSETV V1, V2, V3 // 43840f71
VBITREVB V1, V2, V3 // 43041071
VBITREVH V1, V2, V3 // 43841071
VBITREVW V1, V2, V3 // 43041171
VBITREVV V1, V2, V3 // 43841171
XVBITCLRB X3, X2, X1 // 410c0c75
XVBITCLRH X3, X2, X1 // 418c0c75
XVBITCLRW X3, X2, X1 // 410c0d75
XVBITCLRV X3, X2, X1 // 418c0d75
XVBITSETB X3, X2, X1 // 410c0e75
XVBITSETH X3, X2, X1 // 418c0e75
XVBITSETW X3, X2, X1 // 410c0f75
XVBITSETV X3, X2, X1 // 418c0f75
XVBITREVB X3, X2, X1 // 410c1075
XVBITREVH X3, X2, X1 // 418c1075
XVBITREVW X3, X2, X1 // 410c1175
XVBITREVV X3, X2, X1 // 418c1175
VBITCLRB $7, V2, V3 // 433c1073
VBITCLRH $15, V2, V3 // 437c1073
VBITCLRW $31, V2, V3 // 43fc1073
VBITCLRV $63, V2, V3 // 43fc1173
VBITSETB $7, V2, V3 // 433c1473
VBITSETH $15, V2, V3 // 437c1473
VBITSETW $31, V2, V3 // 43fc1473
VBITSETV $63, V2, V3 // 43fc1573
VBITREVB $7, V2, V3 // 433c1873
VBITREVH $15, V2, V3 // 437c1873
VBITREVW $31, V2, V3 // 43fc1873
VBITREVV $63, V2, V3 // 43fc1973
XVBITCLRB $7, X2, X1 // 413c1077
XVBITCLRH $15, X2, X1 // 417c1077
XVBITCLRW $31, X2, X1 // 41fc1077
XVBITCLRV $63, X2, X1 // 41fc1177
XVBITSETB $7, X2, X1 // 413c1477
XVBITSETH $15, X2, X1 // 417c1477
XVBITSETW $31, X2, X1 // 41fc1477
XVBITSETV $63, X2, X1 // 41fc1577
XVBITREVB $7, X2, X1 // 413c1877
XVBITREVH $15, X2, X1 // 417c1877
XVBITREVW $31, X2, X1 // 41fc1877
XVBITREVV $63, X2, X1 // 41fc1977
2 changes: 1 addition & 1 deletion src/cmd/cgo/out.go
Original file line number Diff line number Diff line change
Expand Up @@ -1051,7 +1051,7 @@ func (p *Package) writeExports(fgo2, fm, fgcc, fgcch io.Writer) {
// string.h for memset, and is also robust to C++
// types with constructors. Both GCC and LLVM optimize
// this into just zeroing _cgo_a.
fmt.Fprintf(fgcc, "\ttypedef %s %v _cgo_argtype;\n", ctype.String(), p.packedAttribute())
fmt.Fprintf(fgcc, "\ttypedef %s %v __attribute__((aligned(%d))) _cgo_argtype;\n", ctype.String(), p.packedAttribute(), p.PtrSize)
fmt.Fprintf(fgcc, "\tstatic _cgo_argtype _cgo_zero;\n")
fmt.Fprintf(fgcc, "\t_cgo_argtype _cgo_a = _cgo_zero;\n")
if gccResult != "void" && (len(fntype.Results.List) > 1 || len(fntype.Results.List[0].Names) > 1) {
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/compile/internal/test/mulconst_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func BenchmarkMulconstI32(b *testing.B) {
}
mulSinkI32 = x
})
// -120x = 8x - 120x
// -120x = 8x - 128x
b.Run("-120", func(b *testing.B) {
x := int32(1)
for i := 0; i < b.N; i++ {
Expand Down Expand Up @@ -202,7 +202,7 @@ func BenchmarkMulconstI64(b *testing.B) {
}
mulSinkI64 = x
})
// -120x = 8x - 120x
// -120x = 8x - 128x
b.Run("-120", func(b *testing.B) {
x := int64(1)
for i := 0; i < b.N; i++ {
Expand Down
25 changes: 25 additions & 0 deletions src/cmd/internal/obj/loong64/a.out.go
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,31 @@ const (
AXVPCNTW
AXVPCNTV

AVBITCLRB
AVBITCLRH
AVBITCLRW
AVBITCLRV
AVBITSETB
AVBITSETH
AVBITSETW
AVBITSETV
AVBITREVB
AVBITREVH
AVBITREVW
AVBITREVV
AXVBITCLRB
AXVBITCLRH
AXVBITCLRW
AXVBITCLRV
AXVBITSETB
AXVBITSETH
AXVBITSETW
AXVBITSETV
AXVBITREVB
AXVBITREVH
AXVBITREVW
AXVBITREVV

// LSX and LASX integer comparison instruction
AVSEQB
AXVSEQB
Expand Down
24 changes: 24 additions & 0 deletions src/cmd/internal/obj/loong64/anames.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading