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