Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1jHM8w-00083g-0w for mharc-grub-devel@gnu.org; Thu, 26 Mar 2020 02:37:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51524) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jHM8r-00081Q-Io for grub-devel@gnu.org; Thu, 26 Mar 2020 02:37:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jHM8q-0000Pf-0q for grub-devel@gnu.org; Thu, 26 Mar 2020 02:37:25 -0400 Received: from m4a0073g.houston.softwaregrp.com ([15.124.2.131]:52209) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1jHM8p-0000Hj-Qh for grub-devel@gnu.org; Thu, 26 Mar 2020 02:37:23 -0400 Received: FROM m4a0073g.houston.softwaregrp.com (15.120.17.147) BY m4a0073g.houston.softwaregrp.com WITH ESMTP; Thu, 26 Mar 2020 06:34:51 +0000 Received: from M9W0068.microfocus.com (2002:f79:bf::f79:bf) by M4W0335.microfocus.com (2002:f78:1193::f78:1193) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1591.10; Thu, 26 Mar 2020 06:35:56 +0000 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (15.124.72.12) by M9W0068.microfocus.com (15.121.0.191) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1591.10 via Frontend Transport; Thu, 26 Mar 2020 06:35:56 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZpZLNejh6zO1CxPpNX2+dC1JRzkS5IYIzvv51e6Bm8bY04ADjK4liqX6IHoZd1qo2JtoaojkDtkGomuq0cXbYV8xIK6rng9BIQ3IU/0nMjHJs2hc5TPMp3WdRGzA/I8J6HO/E61dUip4ME7wokPDfdnXAaoQ7jbPrjlfUY6h2n92bdhp0hPxyr8RDL4blMj+IEKZsgoko3NtoS/QAD1h9zYunxGGW+hvT0td9ul/rXO1birJe9LlMgFCjCnyeGeNJawBh7pQvi7vaHGbGS7ehixGU1piDRCdjQ2pp4NYi333xDAYPxfsVII/ZKOExe4PxB6KmBDOabCXCzgc4twfWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=X+t4jY5T3naAlcCEdeHL+vKJ9+15eQBm/Y1oMiEl698=; b=k9chmAwWxkSPqtr1ur8SHJ5PQ9XTOK6yId6RASgtkQtdks3Mp/rTI43fqfmOdmIGdlZN7JHvAIOAPSK2hDEIWd0XkQRQ/rdv6d3z6yTzK5oq/zg+5Yi/58LYAr9oWSLWHeT4x6WG5wkIbQK0S4ItVW8YEnue8uEBYaG0AfHJLmtZO+J9HVtsDvqUbkCI9JNbZ0Sp4MmY/32ZK9ODRKQj5+5tWoAVE7uJCRE3LN3DXoaBjj9vMMB4AWqWUhAxocCk/8FV7J1sky4/VOM/pw62MLLJrccMfvdazOK4ngq7hCn4kBj1yM2mgD7tUI2aoLIflPqIgFXKYp4OtxJRJGPB9A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=MChang@suse.com; Received: from BY5PR18MB3140.namprd18.prod.outlook.com (2603:10b6:a03:1a1::17) by BY5PR18MB3297.namprd18.prod.outlook.com (2603:10b6:a03:1a1::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2835.19; Thu, 26 Mar 2020 06:35:55 +0000 Received: from BY5PR18MB3140.namprd18.prod.outlook.com ([fe80::a404:f256:fbe8:c2d]) by BY5PR18MB3140.namprd18.prod.outlook.com ([fe80::a404:f256:fbe8:c2d%4]) with mapi id 15.20.2856.019; Thu, 26 Mar 2020 06:35:55 +0000 From: Michael Chang To: CC: PGNet Dev , Paul Menzel , Daniel Kiper , Thomas Schmitt Subject: [PATCH 2/2] zfs: Fix gcc10 error -Werror=zero-length-bounds Date: Thu, 26 Mar 2020 14:35:35 +0800 Message-ID: <20200326063535.28022-2-mchang@suse.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20200326063535.28022-1-mchang@suse.com> References: <20200326063535.28022-1-mchang@suse.com> Content-Type: text/plain X-ClientProxiedBy: LO2P265CA0390.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:f::18) To BY5PR18MB3140.namprd18.prod.outlook.com (2603:10b6:a03:1a1::17) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mercury.suse.cz (36.226.146.226) by LO2P265CA0390.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:f::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2856.18 via Frontend Transport; Thu, 26 Mar 2020 06:35:52 +0000 X-Mailer: git-send-email 2.16.4 X-Originating-IP: [36.226.146.226] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9acdf6d8-7f0e-4efa-0665-08d7d14fef7a X-MS-TrafficTypeDiagnostic: BY5PR18MB3297: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6430; X-Forefront-PRVS: 0354B4BED2 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4636009)(136003)(396003)(376002)(366004)(39860400002)(346002)(478600001)(6486002)(966005)(2906002)(6512007)(316002)(54906003)(52116002)(6506007)(8936002)(8676002)(81166006)(81156014)(36756003)(86362001)(2616005)(26005)(186003)(956004)(16526019)(66476007)(66556008)(6916009)(1076003)(6666004)(5660300002)(4326008)(66946007); DIR:OUT; SFP:1102; SCL:1; SRVR:BY5PR18MB3297; H:BY5PR18MB3140.namprd18.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; Received-SPF: None (protection.outlook.com: suse.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: CLOgCwmPiEx7h0KqANVFQJBlSEeQsCBUrHD9ECqmaoMa35kaDq2M1IFneUigpNk5CswJFbSgKxbjIJlf073DRErozHPciOx9O0makxWed/KKQ/Zhd5k9rz5DlZd0iZXwfbMG/kgB+ZSkARK72YNhdqdAD31bEvTcKVGLJTv6D3B0zfarxqOsatRRpjo6cnM0u7Nxzxl7teuZIcZ2PFAsOraX9Nk6LzRRD6tJB50FBlM9rBbX51A4YaAOqlYmCk4YxQUfkCfeEUGYqfYl57xdgHjlyYxujwwkzOnKJyhz3Rgg/GjtUuf71UCVZzWpK/kvxQOcIvO6Y+cOkeZUoUIhrPgYTz4TrW1wL2peqg62WqrbiikwvnEeUoEwt96pI1rp2UtD7X6UBSw3PmPMgIsr+95bN3A42ejMaGnhms0AcU4RjqPtCwvhpDA5j5U3QLlm041zLbrvjvi+6AZMbMr393TZv/K2l379o9CsjiCIJUjNi8CaUqmEwsXW4PoRSERq7++NlwpGYBfDPNcSX84ovw== X-MS-Exchange-AntiSpam-MessageData: uT3Z3vV2AGOC1mjMdAc38SEMyFqx5h/zsrF7IxXjmiEWrB2kpc9fmaOVcASm7VuSijmwOLlNDP8OFtAfT4T4GMSV9qxdUitQ2AWB5zomxgAPHDP4GqmA5jDIxmjrksvAIffthtDdoGXTlNgeIK8Z1Q== X-MS-Exchange-CrossTenant-Network-Message-Id: 9acdf6d8-7f0e-4efa-0665-08d7d14fef7a X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Mar 2020 06:35:55.1604 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 856b813c-16e5-49a5-85ec-6f081e13b527 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: h1gXphIYerUEKfkXnZihYZ0IPm/Uj9VLDsrBnQUNhJg3YKbzFkNiuRAA9tQat0xl X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR18MB3297 X-OriginatorOrg: suse.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 15.124.2.131 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 26 Mar 2020 06:37:27 -0000 We bumped into the build error while testing gcc-10 pre-release. In file included from ../../include/grub/file.h:22, from ../../grub-core/fs/zfs/zfs.c:34: ../../grub-core/fs/zfs/zfs.c: In function 'zap_leaf_lookup': ../../grub-core/fs/zfs/zfs.c:2263:44: error: array subscript '' is outside the bounds of an interior zero-length array 'grub_uint16_t[0]' {aka 'short unsigned int[0]'} [-Werror=zero-length-bounds] 2263 | for (chunk = grub_zfs_to_cpu16 (l->l_hash[LEAF_HASH (blksft, h, l)], endian); ../../include/grub/types.h:241:48: note: in definition of macro 'grub_le_to_cpu16' 241 | # define grub_le_to_cpu16(x) ((grub_uint16_t) (x)) | ^ ../../grub-core/fs/zfs/zfs.c:2263:16: note: in expansion of macro 'grub_zfs_to_cpu16' 2263 | for (chunk = grub_zfs_to_cpu16 (l->l_hash[LEAF_HASH (blksft, h, l)], endian); | ^~~~~~~~~~~~~~~~~ In file included from ../../grub-core/fs/zfs/zfs.c:48: ../../include/grub/zfs/zap_leaf.h:72:16: note: while referencing 'l_hash' 72 | grub_uint16_t l_hash[0]; | ^~~~~~ Here I'd like to quote from the gcc document [1] which seems best to explain what is going on here. "Although the size of a zero-length array is zero, an array member of this kind may increase the size of the enclosing type as a result of tail padding. The offset of a zero-length array member from the beginning of the enclosing structure is the same as the offset of an array with one or more elements of the same type. The alignment of a zero-length array is the same as the alignment of its elements. Declaring zero-length arrays in other contexts, including as interior members of structure objects or as non-member objects, is discouraged. Accessing elements of zero-length arrays declared in such contexts is undefined and may be diagnosed." The l_hash[0] is apparnetly an interior member to the enclosed structure while l_entries[0] is the trailing member. And the offending code tries to access members in l_hash[0] array that triggers the diagnose. Given that the l_entries[0] is used to get proper alignment to access leaf chunks, we can accomplish the same thing through the ALIGN_UP macro thus eliminating l_entries[0] from the structure. In this way we can pacify the warning as l_hash[0] now becomes the last member to the enclosed structure. [1] https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html Signed-off-by: Michael Chang --- grub-core/fs/zfs/zfs.c | 5 ++++- include/grub/zfs/zap_leaf.h | 1 - 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/grub-core/fs/zfs/zfs.c b/grub-core/fs/zfs/zfs.c index 2f72e42bf..b5e10fd0b 100644 --- a/grub-core/fs/zfs/zfs.c +++ b/grub-core/fs/zfs/zfs.c @@ -141,7 +141,10 @@ ZAP_LEAF_NUMCHUNKS (int bs) static inline zap_leaf_chunk_t * ZAP_LEAF_CHUNK (zap_leaf_phys_t *l, int bs, int idx) { - return &((zap_leaf_chunk_t *) (l->l_entries + grub_properly_aligned_t *l_entries; + + l_entries = (grub_properly_aligned_t *) ALIGN_UP((grub_addr_t)l->l_hash, sizeof (grub_properly_aligned_t)); + return &((zap_leaf_chunk_t *) (l_entries + (ZAP_LEAF_HASH_NUMENTRIES(bs) * 2) / sizeof (grub_properly_aligned_t)))[idx]; } diff --git a/include/grub/zfs/zap_leaf.h b/include/grub/zfs/zap_leaf.h index 95c67dcba..11447c166 100644 --- a/include/grub/zfs/zap_leaf.h +++ b/include/grub/zfs/zap_leaf.h @@ -70,7 +70,6 @@ typedef struct zap_leaf_phys { */ grub_uint16_t l_hash[0]; - grub_properly_aligned_t l_entries[0]; } zap_leaf_phys_t; typedef union zap_leaf_chunk { -- 2.16.4