tls_get_addr.S 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* Stack-aligning implementation of __tls_get_addr. x86-64 version.
  2. Copyright (C) 2017-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. <https://www.gnu.org/licenses/>. */
  15. #ifdef SHARED
  16. # include <sysdep.h>
  17. # include "tlsdesc.h"
  18. # include "rtld-offsets.h"
  19. /* See __tls_get_addr and __tls_get_addr_slow in dl-tls.c. This function
  20. call __tls_get_addr_slow on both slow paths. It realigns the stack
  21. before the call to work around GCC PR58066. */
  22. ENTRY (__tls_get_addr)
  23. mov %fs:DTV_OFFSET, %RDX_LP
  24. mov GL_TLS_GENERATION_OFFSET+_rtld_local(%rip), %RAX_LP
  25. /* GL(dl_tls_generation) == dtv[0].counter */
  26. cmp %RAX_LP, (%rdx)
  27. jne 1f
  28. mov TI_MODULE_OFFSET(%rdi), %RAX_LP
  29. /* dtv[ti->ti_module] */
  30. # ifdef __LP64__
  31. salq $4, %rax
  32. movq (%rdx,%rax), %rax
  33. # else
  34. movl (%rdx,%rax, 8), %eax
  35. # endif
  36. cmp $-1, %RAX_LP
  37. je 1f
  38. add TI_OFFSET_OFFSET(%rdi), %RAX_LP
  39. ret
  40. 1:
  41. /* On the slow path, align the stack. */
  42. pushq %rbp
  43. cfi_def_cfa_offset (16)
  44. cfi_offset (%rbp, -16)
  45. mov %RSP_LP, %RBP_LP
  46. cfi_def_cfa_register (%rbp)
  47. and $-16, %RSP_LP
  48. call __tls_get_addr_slow
  49. mov %RBP_LP, %RSP_LP
  50. popq %rbp
  51. cfi_def_cfa (%rsp, 8)
  52. ret
  53. END (__tls_get_addr)
  54. #endif /* SHARED */