From patchwork Tue Sep 27 16:28:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Lance Taylor X-Patchwork-Id: 1495 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5044:0:0:0:0:0 with SMTP id h4csp420679wrt; Tue, 27 Sep 2022 09:30:00 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5fszEG9gfT0/Y8xfYhhhRJ2cPKMKFH+iGLEN9ixzid7rGYlT6MWLCbTM+ymCKHlrjej3Dp X-Received: by 2002:a17:906:db0a:b0:781:f24:a782 with SMTP id xj10-20020a170906db0a00b007810f24a782mr23376327ejb.399.1664296200638; Tue, 27 Sep 2022 09:30:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664296200; cv=none; d=google.com; s=arc-20160816; b=V++P5uc7g35sGC9dJSfSmMbyLG8JpnZa9oHvolmbK9lp36ncW/3jkFSUXOtZly0KYN hzFJayizZ/n/Mcdi2ILK9a6CRgCx/Zb3YssxuVhcbQAqHyTS4DP8LhJCNROf/HPNmKRH ee5JxH7smKGeonbRpFTeEWp/RHxy6DjUFaBu9A8JKVXVxb/+4EqpIDVuYokcIIrpW7YB HMA4ebmrzI9LWZKvofZhUD+6uA6GLBD1DOHL4ujbzhHNF429ZLUijru0AX35ERhuhSOB rYmwfsW033rVJNC4auUUS8jJ/HShoVaQ2jpOUitE/QMKu0XLapg68ZXUOUqE+smzcKpk luOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:to:subject :message-id:date:mime-version:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=I0KfdyQSuWLllAJydpkhWpNxtkG2PjHqwebfVQIk53w=; b=x18PSqheHxqfi2J1sVNCR9ohgdfslkgia/HahbVz565aS4+/Wfuq/WR7QEFM1hRYSs 2R9NslDt8TsuSvD1MEwdHvugPkreJl2PZqzJz84RyKTC8GkEHnJDoVhzuNNJCY7EBvmD p458W6JRVaGBV44QaQNKjGX94Fdh8hvOUEV8tUEn7A6rnIVRJ6eVymD0ZVIOKGEPQkIL pH4BRw8prQErfouVixwvGZBPgjjCAXb/0OitDNrH+8Mjqvb9VdDHBbBlKjliG+ptLaZx oSv81N4h4uRfNdUHuNQVicuVeAe9AQWw4iVJFRizju+W33xvusc9sAaYgRGCJerBdCPJ KIxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ozDfV9kN; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id r12-20020a05640251cc00b0044f441d2372si2486668edd.88.2022.09.27.09.30.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Sep 2022 09:30:00 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ozDfV9kN; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8CA693858028 for ; Tue, 27 Sep 2022 16:29:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8CA693858028 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1664296199; bh=I0KfdyQSuWLllAJydpkhWpNxtkG2PjHqwebfVQIk53w=; h=Date:Subject:To:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=ozDfV9kNxKtw3ELiciTUdmhGbObT/afPgRqmyjYZtDbss+mbJc7Q+o48CBQLnmDR8 nijWkPNoOPE3pzkLZ6Q0m7191fP3ghjwUcjc0SzsdE+6pXR/LFGTFPryad6MJGdC3v m+NEAQlO9OqKgeswXqmUX79/c9IfRca9NB6l1yl0= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-oi1-x231.google.com (mail-oi1-x231.google.com [IPv6:2607:f8b0:4864:20::231]) by sourceware.org (Postfix) with ESMTPS id 5EB2E3858C50 for ; Tue, 27 Sep 2022 16:29:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5EB2E3858C50 Received: by mail-oi1-x231.google.com with SMTP id t62so12413721oie.10 for ; Tue, 27 Sep 2022 09:29:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date; bh=I0KfdyQSuWLllAJydpkhWpNxtkG2PjHqwebfVQIk53w=; b=16mLn+LKXEUtFVh5WDY7buF79dqhD1HNPGOsXKlbomRGkE1m7yGi4mH4HQlRX6fMra eSGODT6GCjKJ3QoZQcBnoFAckUBA7/sLs8C4+age+1tQLZaP4fJumU6Tm3J98dgWSXUt Rwsscuj4vNAOKO3nNtixoKBF8EU3xqB6/FU8ZNiHcUqlV3OROWx9cTduFyiNoB4mgh3g p6xGFshOklDJ6LTbuISaKc6Odvj97g2A5bs4F0zPtVwPZmrZDLJPbCAEDHFcaLpNjlxG LQu58qOOP/xwznqfWqLffE58XvTR/mij1Gz8c2eCRIrBmybGvj78KU6J1QmVVcyByxCF LOxA== X-Gm-Message-State: ACrzQf3BSxEalcwuqhg1VSw7Xy+NIj44TulzJ3QZj08Ou3baITbgda60 ghBoN+Nz4fboa9lPmwTv+mtY/A1rQ+JSpGrf8guFOYev0PWZ0w== X-Received: by 2002:aca:ebd7:0:b0:350:47c5:46c1 with SMTP id j206-20020acaebd7000000b0035047c546c1mr2223070oih.246.1664296150289; Tue, 27 Sep 2022 09:29:10 -0700 (PDT) MIME-Version: 1.0 Date: Tue, 27 Sep 2022 09:28:59 -0700 Message-ID: Subject: libgo patch committed: Synchronize empty struct field handling To: gcc-patches , gofrontend-dev X-Spam-Status: No, score=-10.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Ian Lance Taylor via Gcc-patches From: Ian Lance Taylor Reply-To: Ian Lance Taylor Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1745141052886915757?= X-GMAIL-MSGID: =?utf-8?q?1745141052886915757?= This libgo patch by Funan Zeng synchronizes the handling of empty struct fields between the Go frontend and the libgo FFI code. In the compiler the logic for allocating one byte for the last field of a struct is: 1. the last field has zero size 2. the struct itself does not have zero size 3. the last field is not blank This patch adds the last two conditions to runtime.structToFFI. This is for https://go.dev/issue/55146. Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu. Committed to mainline. Ian 085bacba3502ff77c70a7660c19a68f50e9b7877 diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE index f7a7985287d..73aa712dbdf 100644 --- a/gcc/go/gofrontend/MERGE +++ b/gcc/go/gofrontend/MERGE @@ -1,4 +1,4 @@ -42efec8c126cf3787bc7c89d9c7f224eff7c5a21 +0140cca9bc0fad1108c7ed369376ac71cc4bfecf The first line of this file holds the git revision number of the last merge done from the gofrontend repository. diff --git a/libgo/go/runtime/ffi.go b/libgo/go/runtime/ffi.go index cd8479ef551..86ce5b85d04 100644 --- a/libgo/go/runtime/ffi.go +++ b/libgo/go/runtime/ffi.go @@ -4,6 +4,7 @@ // Only build this file if libffi is supported. +//go:build libffi // +build libffi package runtime @@ -221,9 +222,6 @@ func stringToFFI() *__ffi_type { // structToFFI returns an ffi_type for a Go struct type. func structToFFI(typ *structtype) *__ffi_type { c := len(typ.fields) - if c == 0 { - return emptyStructToFFI() - } if typ.typ.kind&kindDirectIface != 0 { return ffi_type_pointer() } @@ -231,6 +229,7 @@ func structToFFI(typ *structtype) *__ffi_type { fields := make([]*__ffi_type, 0, c+1) checkPad := false lastzero := false + sawnonzero := false for i, v := range typ.fields { // Skip zero-sized fields; they confuse libffi, // and there is no value to pass in any case. @@ -239,10 +238,13 @@ func structToFFI(typ *structtype) *__ffi_type { // next field. if v.typ.size == 0 { checkPad = true - lastzero = true + if v.name == nil || *v.name != "_" { + lastzero = true + } continue } lastzero = false + sawnonzero = true if checkPad { off := uintptr(0) @@ -263,6 +265,10 @@ func structToFFI(typ *structtype) *__ffi_type { fields = append(fields, typeToFFI(v.typ)) } + if !sawnonzero { + return emptyStructToFFI() + } + if lastzero { // The compiler adds one byte padding to non-empty struct ending // with a zero-sized field (types.cc:get_backend_struct_fields).