arm-mcount.S 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /* Implementation of profiling support. ARM EABI version.
  2. Copyright (C) 2008-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. /* Don't call mcount when calling mcount... */
  16. #undef PROF
  17. #include <sysdep.h>
  18. #undef mcount
  19. #ifdef __thumb2__
  20. .thumb
  21. #endif
  22. .syntax unified
  23. /* Use an assembly stub with a special ABI. The calling lr has been
  24. pushed to the stack (which will be misaligned). We should preserve
  25. all registers except ip and pop a word off the stack.
  26. NOTE: This assumes mcount_internal does not clobber any non-core
  27. (coprocessor) registers. Currently this is true, but may require
  28. additional attention in the future.
  29. The calling sequence looks something like:
  30. func:
  31. push {lr}
  32. bl __gnu_mcount_nc
  33. <function body>
  34. */
  35. ENTRY(__gnu_mcount_nc)
  36. push {r0, r1, r2, r3, lr}
  37. cfi_adjust_cfa_offset (20)
  38. cfi_rel_offset (r0, 0)
  39. cfi_rel_offset (r1, 4)
  40. cfi_rel_offset (r2, 8)
  41. cfi_rel_offset (r3, 12)
  42. cfi_rel_offset (lr, 16)
  43. bic r1, lr, #1
  44. ldr r0, [sp, #20]
  45. bl __mcount_internal
  46. pop {r0, r1, r2, r3, ip, lr}
  47. cfi_adjust_cfa_offset (-24)
  48. cfi_restore (r0)
  49. cfi_restore (r1)
  50. cfi_restore (r2)
  51. cfi_restore (r3)
  52. cfi_register (lr, ip)
  53. bx ip
  54. END(__gnu_mcount_nc)
  55. #include <gcc-compat.h>
  56. #include <shlib-compat.h>
  57. /* The new __gnu_mcount_nc entry point was introduced in 4.4, so the
  58. static library needs the old one only to support older compilers.
  59. Even in a configuration that only cares about newer compilers, the
  60. shared library might need it only for strict ABI compatibility. */
  61. #if GCC_COMPAT (4, 3) || SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_19)
  62. /* Provide old mcount for backwards compatibility. This requires
  63. code be compiled with APCS frame pointers. */
  64. ENTRY(__mcount_arm_compat)
  65. push {r0, r1, r2, r3, fp, lr}
  66. cfi_adjust_cfa_offset (24)
  67. cfi_rel_offset (r0, 0)
  68. cfi_rel_offset (r1, 4)
  69. cfi_rel_offset (r2, 8)
  70. cfi_rel_offset (r3, 12)
  71. cfi_rel_offset (fp, 16)
  72. cfi_rel_offset (lr, 20)
  73. movs r0, fp
  74. ittt ne
  75. ldrne r0, [r0, #-4]
  76. movsne r1, lr
  77. blne __mcount_internal
  78. # if defined (__ARM_ARCH_4T__) && defined (__THUMB_INTERWORK__)
  79. pop {r0, r1, r2, r3, fp, lr}
  80. cfi_adjust_cfa_offset (-24)
  81. cfi_restore (r0)
  82. cfi_restore (r1)
  83. cfi_restore (r2)
  84. cfi_restore (r3)
  85. cfi_restore (fp)
  86. cfi_restore (lr)
  87. bx lr
  88. # else
  89. pop {r0, r1, r2, r3, fp, pc}
  90. # endif
  91. END(__mcount_arm_compat)
  92. #endif
  93. #if GCC_COMPAT (4, 3)
  94. strong_alias (__mcount_arm_compat, _mcount)
  95. /* The canonical name for the function is `_mcount' in both C and asm,
  96. but some old asm code might assume it's `mcount'. */
  97. weak_alias (_mcount, mcount)
  98. #elif SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_19)
  99. compat_symbol (libc, __mcount_arm_compat, _mcount, GLIBC_2_0)
  100. strong_alias (__mcount_arm_compat, __mcount_arm_compat_1)
  101. compat_symbol (libc, __mcount_arm_compat_1, mcount, GLIBC_2_0)
  102. #endif