1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-08-01 10:06:57 +03:00

x86: Set minimum x86-64 level marker [BZ #27318]

Since the full ISA set used in an ELF binary is unknown to compiler,
an x86-64 ISA level marker indicates the minimum, not maximum, ISA set
required to run such an ELF binary.  We never guarantee a library with
an x86-64 ISA level v3 marker doesn't contain other ISAs beyond x86-64
ISA level v3, like AVX VNNI.  We check the x86-64 ISA level marker for
the minimum ISA set.  Since -march=sandybridge enables only some ISAs
in x86-64 ISA level v3, we should set the needed ISA marker to v2.
Otherwise, libc is compiled with -march=sandybridge will fail to run on
Sandy Bridge:

$ ./elf/ld.so ./libc.so
./libc.so: (p) CPU ISA level is lower than required: needed: 7; got: 3

Set the minimum, instead of maximum, x86-64 ISA level marker should have
no impact on the glibc-hwcaps directory assignment logic in ldconfig nor
ld.so.
This commit is contained in:
H.J. Lu
2021-02-02 13:45:58 -08:00
parent 3c66792667
commit 339bf918ea
4 changed files with 64 additions and 11 deletions

View File

@ -29,32 +29,35 @@
/* ELF program property for x86 ISA level. */
#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__
/* NB: ISAs, excluding MMX, in x86-64 ISA level baseline are used. */
# define ISA_BASELINE GNU_PROPERTY_X86_ISA_1_BASELINE
# else
# define ISA_BASELINE 0
# endif
# 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__
# if ISA_BASELINE && defined __GCC_HAVE_SYNC_COMPARE_AND_SWAP_16 \
&& defined HAVE_X86_LAHF_SAHF && defined __POPCNT__ \
&& defined __SSE3__ && defined __SSSE3__ && defined __SSE4_1__ \
&& defined __SSE4_2__
/* NB: ISAs in x86-64 ISA level v2 are used. */
# define ISA_V2 GNU_PROPERTY_X86_ISA_1_V2
# else
# define ISA_V2 0
# endif
# if defined __AVX__ || defined __AVX2__ || defined __F16C__ \
|| defined __FMA__ || defined __LZCNT__ || defined __MOVBE__ \
|| defined __XSAVE__
# if ISA_V2 && defined __AVX__ && defined __AVX2__ && defined __F16C__ \
&& defined __FMA__ && defined __LZCNT__ && defined HAVE_X86_MOVBE
/* NB: ISAs in x86-64 ISA level v3 are used. */
# define ISA_V3 GNU_PROPERTY_X86_ISA_1_V3
# else
# define ISA_V3 0
# endif
# if defined __AVX512F__ || defined __AVX512BW__ || defined __AVX512CD__ \
|| defined __AVX512DQ__ || defined __AVX512VL__
# if ISA_V3 && defined __AVX512F__ && defined __AVX512BW__ \
&& defined __AVX512CD__ && defined __AVX512DQ__ \
&& defined __AVX512VL__
/* NB: ISAs in x86-64 ISA level v4 are used. */
# define ISA_V4 GNU_PROPERTY_X86_ISA_1_V4
# else
# define ISA_V4 0