[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Xen reliance on non-standard GCC features


  • To: Roberto Bagnara <roberto.bagnara@xxxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Mon, 5 Jun 2023 11:40:58 +0200
  • 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
  • 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=qu/Q6PWnmkcVSQtna83LsHMYzG+EOd7kszTotD0akJY=; b=FYrsA836lwTBs07ZXlPNbCq7JbjY4Tdh2NSVMd8dYbVVqrv8J0xGupS1a6Y2E20zbKqF7yNIlJ/PtwNQ1lkgFNBhI8Hbo7BEs3bcgWx87nOlgJlJyQpMVRVOy+vlcj377P3ul3/c+EosAQTJhcfPywNBgejbtDOIvNu+NhU6dU94R3yniyNzzRMrxR/ep+fFfXQhVu2Dzn4oizmPJAz/5mA1C1INPxoruzNsiigArii3oROwnqj5t8Y7rI1vhxwvZVwnJSuWjHzPUv21EKZ6/KAoWkyROdACI/3lC6im/pGGzSEwasZhoXg8GK8I+TvEOzUlqDVLic9gwDHvRo7Lzg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UcTq2cD6Umt5gQG5XvtSFB2JeeWWUGpC3MywCsT7nSzZQFK4qxyibm6ZIuZ9X9P8yTagEvMika/qyQ6XwnzHRY04yJrtjALYjtLBKi2CdfwRdTtUplmIN40gDKzq+BHeJGGf4cnwlYVZ0PkQCksHmyuuemfEhr/n3B4fL85e5crS+jkSONiRE3pniyaHz5w0UToA0DE/RSN3quoLfrTM46ajGXxeKBpQcQCFvP+8XxKS/qUwUUQp5Dw/ra5bTbP2K5rk4lTyFMRdv8KPNP1K+F6Qt26RZ2o+UjHDU3QxhvyS6O7Jqd+uunKHoiuKyhoO4mQvBrwwKiAo/V8hgzC1DA==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Stefano Stabellini <stefano.stabellini@xxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Mon, 05 Jun 2023 09:41:24 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 05.06.2023 11:19, Roberto Bagnara wrote:
> On 05/06/23 09:35, Jan Beulich wrote:
>> On 05.06.2023 07:28, Roberto Bagnara wrote:
>>> Finally, Xen seems to rely on explicitly undefined behavior, namely
>>> C99 UB 58: "A structure or union is defined as containing no named
>>> members (6.7.2.1)." All instances but one occur via macro BUILD_BUG_ON_ZERO,
>>> the remaining instance concerns struct
>>> `cpu_policy::<anonymous union>::<anonymous struct>::<anonymous 
>>> union>::<anonymous struct>'.
>>> Reliance on undefined behavior might be hard to justify.
>>
>> For starters just a comment here: I'm pretty sure this case was discussed
>> before, and that it was agreed that if need be we'd simply add _ as the
>> name there. Yet then - how did you notice this? Code inspection? I would
>> expect no analysis tool would spot it because it's used for gcc < 4.6
>> only. And I doubt you run analysis tools in combination with this old a
>> gcc?
> 
> It is detected by ECLAIR, but the analysis is based on GCC 12,
> and the detection of implementation-defined behaviors (including
> predefined macros) is completely automatic, so I don't think there
> is any configuration error.
> 
> One of the instances arises from
> 
> xen/arch/arm/dm.c:50.19-50.37:
> all the members of struct `dm_op(const struct dmop_args*)::<anonymous 
> struct>' are unnamed (undefined for the C99 standard, ISO/IEC 9899:1999 Annex 
> J.2 item 58: "A structure or union is defined as containing no named members 
> (6.7.2.1)." [STD.anonstct]). Tool used is `/usr/bin/aarch64-linux-gnu-gcc-12'
> 
> and, in turn:
> 
> xen/include/xen/lib.h:54.12-54.17: expanded from macro `BUILD_BUG_ON_ZERO'

Oh, indeed:

#define BUILD_BUG_ON_ZERO(cond) \
    sizeof(struct { _Static_assert(!(cond), "!(" #cond ")"); })

uses a struct with no real member as well. I did overlook this earlier on.
Not sure though how to deal with this here.

Jan

> xen/include/xen/compiler.h:126.3-126.77: expanded from macro `__must_be_array'
> xen/include/xen/lib.h:77.53-77.70: expanded from macro `ARRAY_SIZE'
> 
> I apologize in advance if I have misunderstood something.
> Kind regards,
> 
>     Roberto




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.