Skip to content

Commit f0cb9ff

Browse files
committed
cmd/cgo: fix unaligned arguments typedmemmove crash on iOS
Irregularly typedmemmove and bulkBarrierPreWrite crashes on unaligned arguments. By aligning the arguments on 8 bytes this is fixed. Fixes #46893
1 parent 7791e93 commit f0cb9ff

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/cmd/cgo/out.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,7 @@ func (p *Package) writeExports(fgo2, fm, fgcc, fgcch io.Writer) {
10031003
// string.h for memset, and is also robust to C++
10041004
// types with constructors. Both GCC and LLVM optimize
10051005
// this into just zeroing _cgo_a.
1006-
fmt.Fprintf(fgcc, "\ttypedef %s %v _cgo_argtype;\n", ctype, p.packedAttribute())
1006+
fmt.Fprintf(fgcc, "\ttypedef %s %v __attribute__((aligned(8))) _cgo_argtype;\n", ctype, p.packedAttribute())
10071007
fmt.Fprintf(fgcc, "\tstatic _cgo_argtype _cgo_zero;\n")
10081008
fmt.Fprintf(fgcc, "\t_cgo_argtype _cgo_a = _cgo_zero;\n")
10091009
if gccResult != "void" && (len(fntype.Results.List) > 1 || len(fntype.Results.List[0].Names) > 1) {

0 commit comments

Comments
 (0)