https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89355

--- Comment #1 from 刘袋鼠 <crazylht at gmail dot com> ---
(In reply to H.J. Lu from comment #0)
> [hjl@gnu-cfl-2 gcc]$ cat x.i
> int
> test (int* val)
> {
>   int status = 99;
> 
>   if((val == 0))
>     {
>       status = 22;
>       goto end;
>     }
> 
>   extern int x;
>   *val = x;
> 
>   status = 0;
> end:
>   return status;
> }
> 
> [hjl@gnu-cfl-2 gcc]$ ./xgcc -B./ -S -O2 -fcf-protection  x.i
> [hjl@gnu-cfl-2 gcc]$ cat x.s
>       .file   "x.i"
>       .text
>       .p2align 4
>       .globl  test
>       .type   test, @function
> test:
> .LFB0:
>       .cfi_startproc
>       endbr64
>       testq   %rdi, %rdi
>       je      .L3
>       movl    x(%rip), %eax
>       movl    %eax, (%rdi)
>       xorl    %eax, %eax
>       ret
>       .p2align 4,,10
>       .p2align 3
> .L3:
> .L2:
>       endbr64  <<< Why is ENDBR here?  There is no indirect branch.
>       movl    $22, %eax
>       ret
>       .cfi_endproc
> .LFE0:
>       .size   test, .-test
>       .ident  "GCC: (GNU) 9.0.1 20190214 (experimental)"
>       .section        .note.GNU-stack,"",@progbits
>       .section        .note.gnu.property,"a"
>       .align 8
>       .long    1f - 0f
>       .long    4f - 1f
>       .long    5
> 0:
>       .string  "GNU"
> 1:
>       .align 8
>       .long    0xc0000002
>       .long    3f - 2f
> 2:
>       .long    0x3
> 3:
>       .align 8
> 4:
> [hjl@gnu-cfl-2 gcc]$

I investigate the second endbr64 in the upper case:
for dump x.i.312r.cet

(code_label 24 27 23 4 3 (nil) [1 uses])
(note 23 24 13 4 [bb 4] NOTE_INSN_BASIC_BLOCK)
(note 13 23 39 4 ("end") NOTE_INSN_DELETED_LABEL 2)
(insn 39 13 5 4 (unspec_volatile [
            (const_int 0 [0])
        ] UNSPECV_NOP_ENDBR) -1
     (nil))


for gcc source code:
if ((LABEL_P (insn) && LABEL_PRESERVE_P (insn))
     || (NOTE_P (insn)
   && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL))
            /* TODO.  Check /s bit also.  */
            {
              cet_eb = gen_nop_endbr ();
              emit_insn_after (cet_eb, insn);
              continue;
            }

Reply via email to