isa-level.c 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /* ELF program property for x86 ISA level.
  2. Copyright (C) 2020-2026 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. In addition to the permissions in the GNU Lesser General Public
  9. License, the Free Software Foundation gives you unlimited
  10. permission to link the compiled version of this file with other
  11. programs, and to distribute those programs without any restriction
  12. coming from the use of this file. (The Lesser General Public
  13. License restrictions do apply in other respects; for example, they
  14. cover modification of the file, and distribution when not linked
  15. into another program.)
  16. The GNU C Library is distributed in the hope that it will be useful,
  17. but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. Lesser General Public License for more details.
  20. You should have received a copy of the GNU Lesser General Public
  21. License along with the GNU C Library; if not, see
  22. <https://www.gnu.org/licenses/>. */
  23. #include <elf.h>
  24. #include <sysdeps/x86/isa-level.h>
  25. /* ELF program property for x86 ISA level. */
  26. #ifdef INCLUDE_X86_ISA_LEVEL
  27. # if MINIMUM_X86_ISA_LEVEL >= 1
  28. /* NB: ISAs, excluding MMX, in x86-64 ISA level baseline are used. */
  29. # define ISA_BASELINE GNU_PROPERTY_X86_ISA_1_BASELINE
  30. # else
  31. # define ISA_BASELINE 0
  32. # endif
  33. # if MINIMUM_X86_ISA_LEVEL >= 2
  34. /* NB: ISAs in x86-64 ISA level v2 are used. */
  35. # define ISA_V2 GNU_PROPERTY_X86_ISA_1_V2
  36. # else
  37. # define ISA_V2 0
  38. # endif
  39. # if MINIMUM_X86_ISA_LEVEL >= 3
  40. /* NB: ISAs in x86-64 ISA level v3 are used. */
  41. # define ISA_V3 GNU_PROPERTY_X86_ISA_1_V3
  42. # else
  43. # define ISA_V3 0
  44. # endif
  45. # if MINIMUM_X86_ISA_LEVEL >= 4
  46. /* NB: ISAs in x86-64 ISA level v4 are used. */
  47. # define ISA_V4 GNU_PROPERTY_X86_ISA_1_V4
  48. # else
  49. # define ISA_V4 0
  50. # endif
  51. # ifndef ISA_LEVEL
  52. # define ISA_LEVEL (ISA_BASELINE | ISA_V2 | ISA_V3 | ISA_V4)
  53. # endif
  54. # if ISA_LEVEL
  55. # ifdef __LP64__
  56. # define PROPERTY_ALIGN 3
  57. # else
  58. # define PROPERTY_ALIGN 2
  59. # endif
  60. # define note_stringify(arg) note_stringify_1(arg)
  61. # define note_stringify_1(arg) #arg
  62. asm(".pushsection \".note.gnu.property\",\"a\",@note\n"
  63. " .p2align " note_stringify (PROPERTY_ALIGN)
  64. /* name length. */
  65. "\n .long 1f - 0f\n"
  66. /* data length. */
  67. " .long 4f - 1f\n"
  68. /* note type: NT_GNU_PROPERTY_TYPE_0. */
  69. " .long " note_stringify (NT_GNU_PROPERTY_TYPE_0)
  70. /* vendor name. */
  71. "\n0: .asciz \"GNU\"\n"
  72. "1: .p2align " note_stringify (PROPERTY_ALIGN)
  73. /* pr_type: GNU_PROPERTY_X86_ISA_1_NEEDED. */
  74. "\n .long " note_stringify (GNU_PROPERTY_X86_ISA_1_NEEDED)
  75. /* pr_datasz. */
  76. "\n .long 3f - 2f\n"
  77. /* GNU_PROPERTY_X86_ISA_1_V[234]. */
  78. "2:\n .long " note_stringify (ISA_LEVEL)
  79. "\n3:\n .p2align " note_stringify (PROPERTY_ALIGN)
  80. "\n4:\n .popsection");
  81. # endif /* ISA_LEVEL */
  82. #endif /* INCLUDE_X86_ISA_LEVEL */