[Bug target/89355] Unnecessary ENDBR

2019-05-03 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89355

Jakub Jelinek  changed:

   What|Removed |Added

   Target Milestone|9.0 |9.2

--- Comment #5 from Jakub Jelinek  ---
GCC 9.1 has been released.

[Bug target/89355] Unnecessary ENDBR

2019-02-22 Thread hjl.tools at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89355

--- Comment #4 from H.J. Lu  ---
*** Bug 89353 has been marked as a duplicate of this bug. ***

[Bug target/89355] Unnecessary ENDBR

2019-02-19 Thread hjl.tools at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89355

H.J. Lu  changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
   Last reconfirmed||2019-02-19
   Target Milestone|--- |9.0
 Ever confirmed|0   |1

--- Comment #3 from H.J. Lu  ---
A patch is posted at

https://gcc.gnu.org/ml/gcc-patches/2019-02/msg01327.html

[Bug target/89355] Unnecessary ENDBR

2019-02-14 Thread crazylht at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89355

--- Comment #2 from 刘袋鼠  ---
(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
>   movlx(%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
>   .long1f - 0f
>   .long4f - 1f
>   .long5
> 0:
>   .string  "GNU"
> 1:
>   .align 8
>   .long0xc002
>   .long3f - 2f
> 2:
>   .long0x3
> 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))


(note 13 23 39 4 ("end") NOTE_INSN_DELETED_LABEL 2)
will enter following branch which emit endbr64
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;
}


Following patch would fix this problem:

diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index 12bc7926f86..2282816ae19 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -2734,9 +2734,10 @@ rest_of_insert_endbranch (void)
  continue;
}

- if ((LABEL_P (insn) && LABEL_PRESERVE_P (insn))
+ if ((LABEL_P (insn)
  || (NOTE_P (insn)
  && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL))
+ && LABEL_PRESERVE_P (insn))
/* TODO.  Check /s bit also.  */
{
  cet_eb = gen_nop_endbr ();

[Bug target/89355] Unnecessary ENDBR

2019-02-14 Thread crazylht at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89355

--- Comment #1 from 刘袋鼠  ---
(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
>   movlx(%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
>   .long1f - 0f
>   .long4f - 1f
>   .long5
> 0:
>   .string  "GNU"
> 1:
>   .align 8
>   .long0xc002
>   .long3f - 2f
> 2:
>   .long0x3
> 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;
}