summaryrefslogtreecommitdiff
path: root/libgo
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@gcc.gnu.org>2019-01-15 23:21:24 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2019-01-15 23:21:24 +0000
commitb7ec44e82bb50bd3adc294aa7e87252c79ea7294 (patch)
tree05ae442ca2773c5cbe254e50ce99ba0604f24614 /libgo
parent5e95646e734c1c64ea4e1a761b414581534e1d8c (diff)
downloadgcc-b7ec44e82bb50bd3adc294aa7e87252c79ea7294.tar.gz
runtime: add padding to FFI type of struct ending with zero-sized field
CL 157557 changes the compiler to add one byte padding to non-empty struct ending with a zero-sized field. Add the same padding to the FFI type, so reflect.Call works. This fixes test/fixedbugs/issue26335.go in the main repo. Reviewed-on: https://go-review.googlesource.com/c/158018 From-SVN: r267956
Diffstat (limited to 'libgo')
-rw-r--r--libgo/go/runtime/ffi.go10
1 files changed, 10 insertions, 0 deletions
diff --git a/libgo/go/runtime/ffi.go b/libgo/go/runtime/ffi.go
index 00858f19ab4..e8088ec3947 100644
--- a/libgo/go/runtime/ffi.go
+++ b/libgo/go/runtime/ffi.go
@@ -227,6 +227,7 @@ func structToFFI(typ *structtype) *__ffi_type {
fields := make([]*__ffi_type, 0, c+1)
checkPad := false
+ lastzero := false
for i, v := range typ.fields {
// Skip zero-sized fields; they confuse libffi,
// and there is no value to pass in any case.
@@ -235,8 +236,10 @@ func structToFFI(typ *structtype) *__ffi_type {
// next field.
if v.typ.size == 0 {
checkPad = true
+ lastzero = true
continue
}
+ lastzero = false
if checkPad {
off := uintptr(0)
@@ -257,6 +260,13 @@ func structToFFI(typ *structtype) *__ffi_type {
fields = append(fields, typeToFFI(v.typ))
}
+ if lastzero {
+ // The compiler adds one byte padding to non-empty struct ending
+ // with a zero-sized field (types.cc:get_backend_struct_fields).
+ // Add this padding to the FFI type.
+ fields = append(fields, ffi_type_uint8())
+ }
+
fields = append(fields, nil)
return &__ffi_type{