https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84176
Bug ID: 84176
Summary: Need a different thunk for
-mindirect-branch=thunk-extern -fcf-protection -mcet
Product: gcc
Version: 8.0.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: hjl.tools at gmail dot com
CC: igor.v.tsimbalist at intel dot com
Blocks: 81652
Target Milestone: ---
Target: x86_64-*-*, i?86-*-*
When -fcf-protection -mcet is used to compile kernel, nocf_check attribute
can be used to add notrack prefix:
[hjl@gnu-skx-1 nt-1]$ cat x.i
void (*func1) (void) __attribute__((nocf_check));
void (*func2) (void);
void
bar (void)
{
func1 ();
func2 ();
}
[hjl@gnu-skx-1 nt-1]$ /export/build/gnu/gcc-test/build-x86_64-linux/gcc/xgcc
-B/export/build/gnu/gcc-test/build-x86_64-linux/gcc/ -O2 -fcf-protection -mcet
-S x.i
[hjl@gnu-skx-1 nt-1]$ cat x.s
.file "x.i"
.text
.p2align 4,,15
.globl bar
.type bar, @function
bar:
.LFB0:
.cfi_startproc
endbr64
subq $8, %rsp
.cfi_def_cfa_offset 16
notrack call *func1(%rip)
addq $8, %rsp
.cfi_def_cfa_offset 8
jmp *func2(%rip)
.cfi_endproc
.LFE0:
.size bar, .-bar
When -mindirect-branch=thunk-extern is added, we need a thunk with
a different name to tell a thunk for indirect branch with notrack
prefix from a thunk for indirect branch without notrack prefix
[hjl@gnu-skx-1 nt-1]$ /export/build/gnu/gcc-test/build-x86_64-linux/gcc/xgcc
-B/export/build/gnu/gcc-test/build-x86_64-linux/gcc/ -O2 -fcf-protection -mcet
-mindirect-branch=thunk-extern -S -o y.s x.i
[hjl@gnu-skx-1 nt-1]$ cat y.s
.file "x.i"
.text
.p2align 4,,15
.globl bar
.type bar, @function
bar:
.LFB0:
.cfi_startproc
endbr64
subq $8, %rsp
.cfi_def_cfa_offset 16
movq func1(%rip), %rax
call __x86_indirect_thunk_rax
movq func2(%rip), %rax
addq $8, %rsp
.cfi_def_cfa_offset 8
jmp __x86_indirect_thunk_rax
.cfi_endproc
.LFE0:
.size bar, .-bar
Otherwise kernel can't properly update a thunk to an indirect branch with
notrack prefix for indirect branch with notrack prefix.
Referenced Bugs:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81652
[Bug 81652] [meta-bug] -fcf-protection=full -mcet bugs