frame-inlined-in-outer-frame.S 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /* Copyright 2020-2022 Free Software Foundation, Inc.
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation; either version 3 of the License, or
  5. (at your option) any later version.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  12. #include <asm/unistd.h>
  13. /* Define these for each architecture:
  14. 1) RETURN_ADDRESS_REGNO: The register number representing the return
  15. address in the DWARF CFI. It can be easily be looked up using
  16. `readelf --debug-dump=frames-interp` on an existing binary of that
  17. architecture, where it says `ra=X`.
  18. 2) exit_0: a sequence of instruction to execute the exit syscall with
  19. argument 0. */
  20. #if defined(__x86_64__)
  21. # define RETURN_ADDRESS_REGNO 16
  22. .macro exit_0
  23. mov $__NR_exit, %rax
  24. mov $0, %rdi
  25. syscall
  26. .endm
  27. #elif defined(__i386__)
  28. # define RETURN_ADDRESS_REGNO 8
  29. .macro exit_0
  30. mov $__NR_exit, %eax
  31. mov $0, %ebx
  32. int $0x80
  33. .endm
  34. #elif defined(__aarch64__)
  35. # define RETURN_ADDRESS_REGNO 30
  36. .macro exit_0
  37. mov x0, #0
  38. mov x8, #__NR_exit
  39. svc #0
  40. .endm
  41. #elif defined(__arm__)
  42. # define RETURN_ADDRESS_REGNO 14
  43. .macro exit_0
  44. ldr r7, =__NR_exit
  45. ldr r0, =0
  46. swi 0x0
  47. .endm
  48. #elif defined __powerpc64__
  49. # define RETURN_ADDRESS_REGNO 65
  50. .macro exit_0
  51. li 0, __NR_exit /* r0 - contains system call number */
  52. li 3, 0 /* r3 - contains first argument for sys call */
  53. sc
  54. .endm
  55. #else
  56. # error "Unsupported architecture"
  57. #endif
  58. /* The following assembly program mimics this pseudo C program, where
  59. everything has been inlined:
  60. 1 void bar(void) {
  61. 2 nop;
  62. 3 }
  63. 4
  64. 5 void foo(void) {
  65. 6 nop;
  66. 7 bar();
  67. 8 nop;
  68. 9 }
  69. 10
  70. 11 void _start(void) {
  71. 12 nop;
  72. 13 foo();
  73. 14 nop;
  74. 15 exit(0);
  75. 16 }
  76. */
  77. #if defined __powerpc64__
  78. # if _CALL_ELF == 2
  79. .abiversion 2 /* Tell gdb what ELF version to use. */
  80. .global _start
  81. _start:
  82. # else
  83. .abiversion 1 /* Tell gdb what ELF version to use. */
  84. .align 2
  85. .global _start
  86. .section ".opd", "aw"
  87. .align 3
  88. _start:
  89. .quad ._start,.TOC.@tocbase,0
  90. .previous
  91. .type ._start,@function
  92. ._start:
  93. # endif
  94. #else
  95. .global _start
  96. _start:
  97. #endif
  98. .cfi_startproc
  99. /* State that the return address for this frame is undefined. */
  100. .cfi_undefined RETURN_ADDRESS_REGNO
  101. .global __cu_low_pc
  102. __cu_low_pc:
  103. .global __start_low_pc
  104. __start_low_pc:
  105. /* Line 12 */
  106. nop
  107. .global __foo_low_pc
  108. __foo_low_pc:
  109. /* Line 6 */
  110. nop
  111. .global __bar_low_pc
  112. __bar_low_pc:
  113. /* Line 2 */
  114. nop
  115. .global __bar_high_pc
  116. __bar_high_pc:
  117. /* Line 8 */
  118. nop
  119. .global __foo_high_pc
  120. __foo_high_pc:
  121. /* Line 14 */
  122. nop
  123. /* Line 15 */
  124. exit_0
  125. .cfi_endproc
  126. .global __start_high_pc
  127. __start_high_pc:
  128. .global __cu_high_pc
  129. __cu_high_pc: