tst-gnu2-tls2mod1.S 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /* Check if TLSDESC relocation preserves %rdi, %rsi and %rbx.
  2. Copyright (C) 2024-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. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <http://www.gnu.org/licenses/>. */
  15. #include <sysdep.h>
  16. /* On AVX512 machines, OFFSET == 40 caused _dl_tlsdesc_dynamic_xsavec
  17. to clobber %rdi, %rsi and %rbx. On Intel AVX CPUs, the state size
  18. is 960 bytes and this test didn't fail. It may be due to the unused
  19. last 128 bytes. On AMD AVX CPUs, the state size is 832 bytes and
  20. this test might fail without the fix. */
  21. #ifndef OFFSET
  22. # define OFFSET 40
  23. #endif
  24. .text
  25. .p2align 4
  26. .globl apply_tls
  27. .type apply_tls, @function
  28. apply_tls:
  29. cfi_startproc
  30. _CET_ENDBR
  31. pushq %rbp
  32. cfi_def_cfa_offset (16)
  33. cfi_offset (6, -16)
  34. movdqu (%RDI_LP), %xmm0
  35. lea tls_var1@TLSDESC(%rip), %RAX_LP
  36. mov %RSP_LP, %RBP_LP
  37. cfi_def_cfa_register (6)
  38. /* Align stack to 64 bytes. */
  39. and $-64, %RSP_LP
  40. sub $OFFSET, %RSP_LP
  41. pushq %rbx
  42. /* Set %ebx to 0xbadbeef. */
  43. movl $0xbadbeef, %ebx
  44. movl $0xbadbeef, %esi
  45. movq %rdi, saved_rdi(%rip)
  46. movq %rsi, saved_rsi(%rip)
  47. call *tls_var1@TLSCALL(%RAX_LP)
  48. /* Check if _dl_tlsdesc_dynamic preserves %rdi, %rsi and %rbx. */
  49. cmpq saved_rdi(%rip), %rdi
  50. jne L(hlt)
  51. cmpq saved_rsi(%rip), %rsi
  52. jne L(hlt)
  53. cmpl $0xbadbeef, %ebx
  54. jne L(hlt)
  55. add %fs:0, %RAX_LP
  56. movups %xmm0, 32(%RAX_LP)
  57. movdqu 16(%RDI_LP), %xmm1
  58. mov %RAX_LP, %RBX_LP
  59. movups %xmm1, 48(%RAX_LP)
  60. lea 32(%RBX_LP), %RAX_LP
  61. pop %rbx
  62. leave
  63. cfi_def_cfa (7, 8)
  64. ret
  65. L(hlt):
  66. hlt
  67. cfi_endproc
  68. .size apply_tls, .-apply_tls
  69. .hidden tls_var1
  70. .globl tls_var1
  71. .section .tbss,"awT",@nobits
  72. .align 16
  73. .type tls_var1, @object
  74. .size tls_var1, 3200
  75. tls_var1:
  76. .zero 3200
  77. .local saved_rdi
  78. .comm saved_rdi,8,8
  79. .local saved_rsi
  80. .comm saved_rsi,8,8
  81. .section .note.GNU-stack,"",@progbits