RE: [PATCH v4 1/2] x86/delay: Fix the wrong asm constraint in `delay_loop()`

From: David Laight
Date: Wed Mar 02 2022 - 19:35:39 EST


From: Alviro Iskandar Setiawan
> Sent: 01 March 2022 11:34
>
> On Tue, Mar 1, 2022 at 4:46 PM Ammar Faizi wrote:
> > Fortunately, the constraint violation that's fixed by patch 1 doesn't
> > yield any bug due to the nature of System V ABI. Should we backport
> > this?
>
> hi sir, it might also be interesting to know that even if it never be
> inlined, it's still potential to break.
>
> for example this code (https://godbolt.org/z/xWMTxhTET)
>
> __attribute__((__noinline__)) static void x(int a)
> {
> asm("xorl\t%%r8d, %%r8d"::"a"(a));
> }

But this code isn't doing that.
In your example the compiler has looked at the static function
and realised that is doesn't use r8 so it need not be saved
even though it is a volatile register.

In this code the compiler knows %ax is being used, it just
doesn't know it is changed - so could assume the value
is unchanged.

The only code that is likely to break is:

int f(int d)
{
d += 10;
__delay(d);
return d;
}

Which might manage to return the value of %eax modified by the asm.

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)