1/* Check ISA level on shared object in glibc-hwcaps subdirectories.
2 Copyright (C) 2021-2024 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
18
19#include <stdbool.h>
20#include <stdlib.h>
21#include <stdio.h>
22#include <elf.h>
23#include <get-isa-level.h>
24#include <support/check.h>
25#include <support/test-driver.h>
26
27extern int dso_isa_level (void);
28
29static int
30do_test (void)
31{
32 const struct cpu_features *cpu_features = __get_cpu_features ();
33 unsigned int isa_level = get_isa_level (cpu_features);
34 bool has_isa_baseline = ((isa_level & GNU_PROPERTY_X86_ISA_1_BASELINE)
35 == GNU_PROPERTY_X86_ISA_1_BASELINE);
36 bool has_isa_v2 = ((isa_level & GNU_PROPERTY_X86_ISA_1_V2)
37 == GNU_PROPERTY_X86_ISA_1_V2);
38 bool has_isa_v3 = ((isa_level & GNU_PROPERTY_X86_ISA_1_V3)
39 == GNU_PROPERTY_X86_ISA_1_V3);
40 bool has_isa_v4 = ((isa_level & GNU_PROPERTY_X86_ISA_1_V4)
41 == GNU_PROPERTY_X86_ISA_1_V4);
42
43 if (!has_isa_baseline)
44 return EXIT_FAILURE;
45
46 int level = dso_isa_level ();
47 int ret;
48 switch (level)
49 {
50 case 1:
51 case 2:
52 /* The default libx86-64-isa-level.so is used. */
53 printf (format: "The default shared library is used.\n");
54 if (has_isa_v3 || has_isa_v4 || (!has_isa_v2 && level == 2))
55 ret = EXIT_FAILURE;
56 else
57 ret = EXIT_SUCCESS;
58 break;
59 case 3:
60 /* libx86-64-isa-level.so marked as x86-64 ISA level 3 needed in
61 x86-64-v2 should be ignored on lesser CPU. */
62 printf (format: "x86-64 ISA level 3 shared library is used.\n");
63 if (has_isa_v4 || !has_isa_v3)
64 ret = EXIT_FAILURE;
65 else
66 ret = EXIT_SUCCESS;
67 break;
68 case 4:
69 /* libx86-64-isa-level.so marked as x86-64 ISA level 4 needed in
70 x86-64-v3 should be ignored on lesser CPU. */
71 printf (format: "x86-64 ISA level 4 shared library is used.\n");
72 if (has_isa_v4)
73 ret = EXIT_SUCCESS;
74 else
75 ret = EXIT_FAILURE;
76 break;
77 default:
78 abort ();
79 }
80 return ret;
81}
82
83#include <support/test-driver.c>
84

source code of glibc/sysdeps/unix/sysv/linux/x86_64/tst-glibc-hwcaps-2.c