tocopt6-inc.s 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. .macro start, sym
  2. .type \sym, @function
  3. .pushsection .opd, "aw"
  4. \sym: .quad .L.\sym, .TOC.@tocbase, 0
  5. .popsection
  6. .L.\sym:
  7. mflr 0
  8. std 31, -8(1)
  9. std 0, 16(1)
  10. stdu 1, -128(1)
  11. mr 31, 1
  12. .endm
  13. .macro end, sym
  14. addi 1,31,128
  15. ld 0, 16(1)
  16. mtlr 0
  17. ld 31, -8(1)
  18. blr
  19. .size \sym, . - .L.\sym
  20. .endm
  21. .macro forward, from, to
  22. start \from
  23. bl \to
  24. nop
  25. end \from
  26. .endm
  27. .macro usegot, sym
  28. .pushsection .data
  29. \sym\@: .quad \@
  30. .popsection
  31. .pushsection .toc, "aw"
  32. .LT\@: .tc \sym\@[TC], \sym\@
  33. .popsection
  34. ld 3,.LT\@@toc(2)
  35. .endm
  36. .macro in123
  37. .pushsection .toc, "aw"
  38. .LThello:
  39. .tc hello[TC],hello
  40. .popsection
  41. .pushsection .rodata
  42. hello: .asciz "Hello, world!\n"
  43. .popsection
  44. .pushsection .text.in123, "axG", @progbits, in123, comdat
  45. .weak in123
  46. start in123
  47. ld 3, .LThello@toc(2)
  48. #bl printf
  49. nop
  50. end in123
  51. .popsection
  52. .endm
  53. .macro in23
  54. .pushsection .text
  55. forward local, in123
  56. .popsection
  57. .pushsection .text.in23, "axG", @progbits, in23, comdat
  58. .weak in23
  59. forward in23, local
  60. .popsection
  61. .endm
  62. .macro gobblegot, sym
  63. .pushsection .text
  64. .globl \sym
  65. start \sym
  66. .rept 5000
  67. usegot a
  68. .endr
  69. end \sym
  70. .popsection
  71. .endm