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

Re: [PATCH v2 3/4] tools/tests/x86_emulator: fix undefined behaviour in shift


  • To: Jan Beulich <jbeulich@xxxxxxxx>
  • From: Edwin Torok <edwin.torok@xxxxxxxxxx>
  • Date: Tue, 3 Mar 2026 14:30:57 +0000
  • Accept-language: en-GB, en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=CNA/W/W10RAlFstbwozHjga1br7vkdyk0F1vsAPxDBI=; b=ZBZZ48hGWjkuvVd3Hn1tG5vPuOJ+qM7Vogl2eKEE6cq6SCyXvELvzANOlPGhUEruJVBSTQbXoA136Cw+K9it/X8V1udzOjw9XCfJixTqmAMyrwqj+t7OurCCiYhRuSu+JkDCNDDkgRaT0l6bhWdNdwdGhMpWLCLWWlwYml37vbzwtg0qrnLQVih0ggxS0IESyxMhDkyS1AwomYc8stCqe1Ctu/zX0iBplBRhH+woPtZ4dRj9/oEJaevplbiLwOLkZ42XNU1rxOU4FdvWi0vlzDf6Q7NUEKLDhlgB7T+ONCAbLGKW5OmJUCrZHE4MY9C+NA5QwtUw8SlSMDynBSdakg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Qd6lXoyfWFhzelmtfKUR0zKnWiMAyLFvxUXm381/AjpOkqgPf/wZgybZInGNz0HRWJio1nyjNl/K81xbDva4Mxr+ialCScyx+fU4v5JkVHDOOSY8wfF8MjNTREeq/xXxq9nCuVLRB3fHUAOP4leThJCwaSAI6edjDmMLtKbVYC25lhIuBwb5bZJNz/bFnrbvNwstmmjZ4WMDlBzRQQh3itsIjaYkehsrEdS/xr0Sfj7kFBODG0CXohAC6QoIFgiNUs6EYb0qP+JqFqLouDDjElwlDsMngQ8jovqoDcXt3c9WrFwCWlF9Qvrm43Zga+K+jz5jf++RQnxvxQYxqH/PYA==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Roger Pau Monne <roger.pau@xxxxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Tue, 03 Mar 2026 14:31:19 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHcp9gCO67+yoRhk0SyNFZDTeRIWLWc3oEAgAAAhQCAAAXugA==
  • Thread-topic: [PATCH v2 3/4] tools/tests/x86_emulator: fix undefined behaviour in shift


> On 3 Mar 2026, at 14:09, Jan Beulich <jbeulich@xxxxxxxx> wrote:
> 
> On 03.03.2026 15:07, Jan Beulich wrote:
>> On 27.02.2026 11:58, Edwin Török wrote:
>>> --- a/tools/tests/x86_emulator/test_x86_emulator.c
>>> +++ b/tools/tests/x86_emulator/test_x86_emulator.c
>>> @@ -1100,7 +1100,7 @@ int main(int argc, char **argv)
>>>     regs.edi    = (unsigned long)res;
>>>     rc = x86_emulate(&ctxt, &emulops);
>>>     if ( (rc != X86EMUL_OKAY) ||
>>> -         (*res != ((0x2233445F << 2) | 2)) ||
>>> +         (*res != ((0x2233445FUL << 2) | 2)) ||
>> 
>> Why the L when res is an array of unsigned int? With it dropped (happy
>> to do so while committing):
>> Acked-by: Jan Beulich <jbeulich@xxxxxxxx>
> 
> I should probably add that nevertheless it's not quite clear to me what use it
> is to compile the harness source itself with sanitizer options.


I was trying to see why the tests were failing with clang, but not GCC.
That could also be because clang takes different (optimisation) decisions on 
how to handle undefined behaviour.
It turned out that undefined behaviour wasn’t the reason the results were 
different, but I sent some patches to fix
some of the (currently latent) bugs it uncovered.

> I can see that
> to be useful for the core emulator files compiled into the harness binary.
> 

For sanitisers like the memory sanitisers (which detects reads from 
uninitialized values) I think it is best to have the whole program compiled 
with it
(the uninitialised value could originate in a different file). Or at least as 
far as reasonable (I’m not rebuilding libc).
But even for the address sanitiser a buffer could be allocated (e.g. on the 
stack) in a different file than where the bug is.


Best regards,
—Edwin


 


Rackspace

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