[PATCH] x86: Require full ISA support for x86-64 level marker [BZ #27318]
H.J. Lu
hjl.tools@gmail.com
Tue Feb 2 21:51:12 GMT 2021
Since -march=sandybridge enables ISAs in x86-64 ISA level v3, the v3
marker is set in libc.so. We couldn't set the needed ISA marker to v2
since this libc won't run on all v2 machines. Technically, the v3 marker
is correct. But the resulting libc.so won't run on Sandy Brigde, which
is a v2 machine, even when libc is compiled with -march=sandybridge:
$ ./elf/ld.so ./libc.so
./libc.so: (p) CPU ISA level is lower than required: needed: 7; got: 3
Instead, we should require full ISA support for x86-64 level marker to
detect such case:
In file included from ../sysdeps/x86/abi-note.c:28:
../sysdeps/x86/isa-level.c:62:5: error: #error "Invalid ISAs for x86-64 ISA level v3"
62 | # error "Invalid ISAs for x86-64 ISA level v3"
| ^~~~~
---
sysdeps/x86/isa-level.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/sysdeps/x86/isa-level.c b/sysdeps/x86/isa-level.c
index aaf524cb56..cbd3526406 100644
--- a/sysdeps/x86/isa-level.c
+++ b/sysdeps/x86/isa-level.c
@@ -31,6 +31,9 @@
#ifdef INCLUDE_X86_ISA_LEVEL
# if defined __x86_64__ || defined __FXSR__ || !defined _SOFT_FLOAT \
|| defined __MMX__ || defined __SSE__ || defined __SSE2__
+# if !defined __SSE__ || !defined __SSE2__
+# error "Invalid ISAs for x86-64 ISA level baseline"
+# endif
# define ISA_BASELINE GNU_PROPERTY_X86_ISA_1_BASELINE
# else
# define ISA_BASELINE 0
@@ -40,6 +43,12 @@
|| (defined __x86_64__ && defined __LAHF_SAHF__) \
|| defined __POPCNT__ || defined __SSE3__ \
|| defined __SSSE3__ || defined __SSE4_1__ || defined __SSE4_2__
+# if !defined __GCC_HAVE_SYNC_COMPARE_AND_SWAP_16 \
+ || (defined __x86_64__ && !defined __LAHF_SAHF__) \
+ || !defined __POPCNT__ || !defined __SSE3__ \
+ || !defined __SSSE3__ || !defined __SSE4_1__ || !defined __SSE4_2__
+# error "Invalid ISAs for x86-64 ISA level v2"
+# endif
# define ISA_V2 GNU_PROPERTY_X86_ISA_1_V2
# else
# define ISA_V2 0
@@ -48,6 +57,10 @@
# if defined __AVX__ || defined __AVX2__ || defined __F16C__ \
|| defined __FMA__ || defined __LZCNT__ || defined __MOVBE__ \
|| defined __XSAVE__
+# if !defined __AVX__ || !defined __AVX2__ || !defined __F16C__ \
+ || !defined __FMA__ || !defined __LZCNT__ || !defined __MOVBE__
+# error "Invalid ISAs for x86-64 ISA level v3"
+# endif
# define ISA_V3 GNU_PROPERTY_X86_ISA_1_V3
# else
# define ISA_V3 0
@@ -55,6 +68,11 @@
# if defined __AVX512F__ || defined __AVX512BW__ || defined __AVX512CD__ \
|| defined __AVX512DQ__ || defined __AVX512VL__
+# if !defined __AVX512F__ || !defined __AVX512BW__ \
+ || !defined __AVX512CD__ || !defined __AVX512DQ__ \
+ || !defined __AVX512VL__
+# error "Invalid ISAs for x86-64 ISA level v4"
+# endif
# define ISA_V4 GNU_PROPERTY_X86_ISA_1_V4
# else
# define ISA_V4 0
--
2.29.2
More information about the Libc-alpha
mailing list