[Openmp-commits] [openmp] [openmp] Support CET in z_Linux_asm.S (PR #123213)

Nikita Popov via Openmp-commits openmp-commits at lists.llvm.org
Thu Jan 16 07:03:10 PST 2025


https://github.com/nikic created https://github.com/llvm/llvm-project/pull/123213

When libomp is built with -cf-protection, add endbr instructions to the start of functions for Intel CET support.

>From fb4d432a9bf3f087ccc326f2252895df26b398db Mon Sep 17 00:00:00 2001
From: Nikita Popov <npopov at redhat.com>
Date: Thu, 16 Jan 2025 15:59:44 +0100
Subject: [PATCH] [openmp] Support CET in z_Linux_asm.S

When libomp is built with -cf-protection, add endbr instructions
to the start of functions for Intel CET support.
---
 openmp/runtime/src/z_Linux_asm.S | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/openmp/runtime/src/z_Linux_asm.S b/openmp/runtime/src/z_Linux_asm.S
index cc5344cdd124a7..0bf9f07a13f147 100644
--- a/openmp/runtime/src/z_Linux_asm.S
+++ b/openmp/runtime/src/z_Linux_asm.S
@@ -19,6 +19,16 @@
 
 #if KMP_ARCH_X86 || KMP_ARCH_X86_64
 
+# if defined(__ELF__) && defined(__CET__) && defined(__has_include)
+# if __has_include(<cet.h>)
+# include <cet.h>
+# endif
+# endif
+
+# if !defined(_CET_ENDBR)
+# define _CET_ENDBR
+# endif
+
 # if KMP_MIC
 // the 'delay r16/r32/r64' should be used instead of the 'pause'.
 // The delay operation has the effect of removing the current thread from
@@ -66,6 +76,7 @@
 	ALIGN  4
 	.globl KMP_PREFIX_UNDERSCORE($0)
 KMP_PREFIX_UNDERSCORE($0):
+	_CET_ENDBR
 .endmacro
 # else // KMP_OS_DARWIN
 #  define KMP_PREFIX_UNDERSCORE(x) x //no extra underscore for Linux* OS symbols
@@ -92,6 +103,7 @@ KMP_PREFIX_UNDERSCORE($0):
         .globl KMP_PREFIX_UNDERSCORE(\proc)
 KMP_PREFIX_UNDERSCORE(\proc):
 	.cfi_startproc
+	_CET_ENDBR
 .endm
 .macro KMP_CFI_DEF_OFFSET sz
 	.cfi_def_cfa_offset	\sz



More information about the Openmp-commits mailing list