a1cb606
From: H.J. Lu <hjl.tools@gmail.com>
a1cb606
Date: Wed, 23 Dec 2020 15:49:04 +0100 (06:49 -0800)
a1cb606
Subject: [PATCH] liblzma: Enable Intel CET in x86 CRC assembly codes
a1cb606
a1cb606
When Intel CET is enabled, we need to include <cet.h> in assembly codes
a1cb606
to mark Intel CET support and add _CET_ENDBR to indirect jump targets.
a1cb606
a1cb606
Tested on Intel Tiger Lake under CET enabled Linux.
a1cb606
---
a1cb606
 src/liblzma/check/crc32_x86.S | 9 +++++++++
a1cb606
 src/liblzma/check/crc64_x86.S | 9 +++++++++
a1cb606
 2 files changed, 18 insertions(+)
a1cb606
a1cb606
diff --git a/src/liblzma/check/crc32_x86.S b/src/liblzma/check/crc32_x86.S
a1cb606
index 67f68a4..e3745e6 100644
a1cb606
--- a/src/liblzma/check/crc32_x86.S
a1cb606
+++ b/src/liblzma/check/crc32_x86.S
a1cb606
@@ -51,6 +51,14 @@ init_table(void)
a1cb606
  * extern uint32_t lzma_crc32(const uint8_t *buf, size_t size, uint32_t crc);
a1cb606
  */
a1cb606
 
a1cb606
+/* When Intel CET is enabled, include <cet.h> in assembly code to mark
a1cb606
+   Intel CET support.  */
a1cb606
+#ifdef __CET__
a1cb606
+# include <cet.h>
a1cb606
+#else
a1cb606
+# define _CET_ENDBR
a1cb606
+#endif
a1cb606
+
a1cb606
 /*
a1cb606
  * On some systems, the functions need to be prefixed. The prefix is
a1cb606
  * usually an underscore.
a1cb606
@@ -83,6 +91,7 @@ init_table(void)
a1cb606
 
a1cb606
 	ALIGN(4, 16)
a1cb606
 LZMA_CRC32:
a1cb606
+	_CET_ENDBR
a1cb606
 	/*
a1cb606
 	 * Register usage:
a1cb606
 	 * %eax crc
a1cb606
diff --git a/src/liblzma/check/crc64_x86.S b/src/liblzma/check/crc64_x86.S
a1cb606
index f5bb84b..7ee08f6 100644
a1cb606
--- a/src/liblzma/check/crc64_x86.S
a1cb606
+++ b/src/liblzma/check/crc64_x86.S
a1cb606
@@ -41,6 +41,14 @@ init_table(void)
a1cb606
  * extern uint64_t lzma_crc64(const uint8_t *buf, size_t size, uint64_t crc);
a1cb606
  */
a1cb606
 
a1cb606
+/* When Intel CET is enabled, include <cet.h> in assembly code to mark
a1cb606
+   Intel CET support.  */
a1cb606
+#ifdef __CET__
a1cb606
+# include <cet.h>
a1cb606
+#else
a1cb606
+# define _CET_ENDBR
a1cb606
+#endif
a1cb606
+
a1cb606
 /*
a1cb606
  * On some systems, the functions need to be prefixed. The prefix is
a1cb606
  * usually an underscore.
a1cb606
@@ -73,6 +81,7 @@ init_table(void)
a1cb606
 
a1cb606
 	ALIGN(4, 16)
a1cb606
 LZMA_CRC64:
a1cb606
+	_CET_ENDBR
a1cb606
 	/*
a1cb606
 	 * Register usage:
a1cb606
 	 * %eax crc LSB
a1cb606
-- 
a1cb606
2.26.0
a1cb606