lkml.org 
[lkml]   [2022]   [Feb]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    From
    SubjectRe: [PATCH 05/29] x86: Base IBT bits
    Date
    On 18/02/2022 21:11, David Laight wrote:
    > From: Andrew Cooper
    >> Sent: 18 February 2022 20:50
    >>
    >> On 18/02/2022 16:49, Peter Zijlstra wrote:
    >>> +/*
    >>> + * A bit convoluted, but matches both endbr32 and endbr64 without
    >>> + * having either as literal in the text.
    >>> + */
    >>> +static inline bool is_endbr(const void *addr)
    >>> +{
    >>> + unsigned int val = ~*(unsigned int *)addr;
    >>> + val |= 0x01000000U;
    >>> + return val == ~0xfa1e0ff3;
    >>> +}
    >> At this point, I feel I've earned an "I told you so". :)
    >>
    >> Clang 13 sees straight through the trickery and generates:
    >>
    >> is_endbr:                               # @is_endbr
    >>         movl    $-16777217, %eax                # imm = 0xFEFFFFFF
    >>         andl    (%rdi), %eax
    >>         cmpl    $-98693133, %eax                # imm = 0xFA1E0FF3
    >>         sete    %al
    >>         retq
    > I think it is enough to add:
    > asm("", "=r" (val));
    > somewhere in the middle.

    (First, you mean "+r" not "=r"), but no - the problem isn't val.  It's
    `~0xfa1e0ff3` which the compiler is free to transform in several unsafe way.

    ~Andrew
    \
     
     \ /
      Last update: 2022-02-18 22:25    [W:3.786 / U:0.024 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site