cet.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /* ELF program property for Intel CET.
  2. Copyright (C) 2017-2019 Free Software Foundation, Inc.
  3. This file is free software; you can redistribute it and/or modify it
  4. under the terms of the GNU General Public License as published by the
  5. Free Software Foundation; either version 3, or (at your option) any
  6. later version.
  7. This file is distributed in the hope that it will be useful, but
  8. WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. General Public License for more details.
  11. Under Section 7 of GPL version 3, you are granted additional
  12. permissions described in the GCC Runtime Library Exception, version
  13. 3.1, as published by the Free Software Foundation.
  14. You should have received a copy of the GNU General Public License and
  15. a copy of the GCC Runtime Library Exception along with this program;
  16. see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  17. <http://www.gnu.org/licenses/>.
  18. */
  19. /* Add x86 feature with IBT and/or SHSTK bits to ELF program property
  20. if they are enabled. Otherwise, contents in this header file are
  21. unused. Define _CET_ENDBR for assembly codes. _CET_ENDBR should be
  22. placed unconditionally at the entrance of a function whose address
  23. may be taken. */
  24. #ifndef _CET_H_INCLUDED
  25. #define _CET_H_INCLUDED
  26. #ifdef __ASSEMBLER__
  27. # if defined __CET__ && (__CET__ & 1) != 0
  28. # ifdef __x86_64__
  29. # define _CET_ENDBR endbr64
  30. # else
  31. # define _CET_ENDBR endbr32
  32. # endif
  33. # else
  34. # define _CET_ENDBR
  35. # endif
  36. # ifdef __ELF__
  37. # ifdef __CET__
  38. # if (__CET__ & 1) != 0
  39. /* GNU_PROPERTY_X86_FEATURE_1_IBT. */
  40. # define __PROPERTY_IBT 0x1
  41. # else
  42. # define __PROPERTY_IBT 0x0
  43. # endif
  44. # if (__CET__ & 2) != 0
  45. /* GNU_PROPERTY_X86_FEATURE_1_SHSTK. */
  46. # define __PROPERTY_SHSTK 0x2
  47. # else
  48. # define __PROPERTY_SHSTK 0x0
  49. # endif
  50. # define __PROPERTY_BITS (__PROPERTY_IBT | __PROPERTY_SHSTK)
  51. # ifdef __LP64__
  52. # define __PROPERTY_ALIGN 3
  53. # else
  54. # define __PROPERTY_ALIGN 2
  55. # endif
  56. .pushsection ".note.gnu.property", "a"
  57. .p2align __PROPERTY_ALIGN
  58. .long 1f - 0f /* name length. */
  59. .long 4f - 1f /* data length. */
  60. /* NT_GNU_PROPERTY_TYPE_0. */
  61. .long 5 /* note type. */
  62. 0:
  63. .asciz "GNU" /* vendor name. */
  64. 1:
  65. .p2align __PROPERTY_ALIGN
  66. /* GNU_PROPERTY_X86_FEATURE_1_AND. */
  67. .long 0xc0000002 /* pr_type. */
  68. .long 3f - 2f /* pr_datasz. */
  69. 2:
  70. /* GNU_PROPERTY_X86_FEATURE_1_XXX. */
  71. .long __PROPERTY_BITS
  72. 3:
  73. .p2align __PROPERTY_ALIGN
  74. 4:
  75. .popsection
  76. # endif /* __CET__ */
  77. # endif /* __ELF__ */
  78. #endif /* __ASSEMBLER__ */
  79. #endif /* _CET_H_INCLUDED */