uClibc-0.9.29-load-got-pointer-at-the-beginning-of-init-and-fini.patch 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. From: Haavard Skinnemoen <hskinnemoen@atmel.com>
  2. Date: Wed, 19 Sep 2007 10:03:35 +0200
  3. Subject: [Avr-gnu-toolchain] [uClibc PATCH] Load GOT pointer at the
  4. beginning of .init and .fini
  5. I don't know why this seems to have worked before, but the .init and
  6. .fini sections typically consist of a bunch of mcalls using r6 as the
  7. base pointer. This can cause "interesting" behaviour when r6 hasn't
  8. been initialized to point to the GOT.
  9. Signed-off-by: Haavard Skinnemoen <hskinnemoen@atmel.com>
  10. ---
  11. libc/sysdeps/linux/avr32/crti.S | 15 ++++++++++++---
  12. libc/sysdeps/linux/avr32/crtn.S | 4 ++--
  13. 2 files changed, 14 insertions(+), 5 deletions(-)
  14. diff --git a/libc/sysdeps/linux/avr32/crti.S b/libc/sysdeps/linux/avr32/crti.S
  15. index 3e132d0..660f47c 100644
  16. --- a/libc/sysdeps/linux/avr32/crti.S
  17. +++ b/libc/sysdeps/linux/avr32/crti.S
  18. @@ -4,14 +4,23 @@
  19. .global _init
  20. .type _init, @function
  21. _init:
  22. - /* Use a four-byte instruction to avoid NOPs */
  23. - stm --sp, r0-r7,lr
  24. + stm --sp, r6, lr
  25. + lddpc r6, 2f
  26. +1: rsub r6, pc
  27. + rjmp 3f
  28. .align 2
  29. +2: .long 1b - _GLOBAL_OFFSET_TABLE_
  30. +3:
  31. .section .fini
  32. .align 2
  33. .global _fini
  34. .type _fini, @function
  35. _fini:
  36. - stm --sp, r0-r7,lr
  37. + stm --sp, r6, lr
  38. + lddpc r6, 2f
  39. +1: rsub r6, pc
  40. + rjmp 3f
  41. .align 2
  42. +2: .long 1b - _GLOBAL_OFFSET_TABLE_
  43. +3:
  44. diff --git a/libc/sysdeps/linux/avr32/crtn.S b/libc/sysdeps/linux/avr32/crtn.S
  45. index 577adcc..f7d1040 100644
  46. --- a/libc/sysdeps/linux/avr32/crtn.S
  47. +++ b/libc/sysdeps/linux/avr32/crtn.S
  48. @@ -3,12 +3,12 @@
  49. .align 2
  50. .global _init
  51. .type _init, @function
  52. - ldm sp++, r0-r7,pc
  53. + ldm sp++, r6, pc
  54. .size _init, . - _init
  55. .section .fini
  56. .align 2
  57. .global _fini
  58. .type _fini, @function
  59. - ldm sp++, r0-r7,pc
  60. + ldm sp++, r6, pc
  61. .size _fini, . - _fini
  62. --
  63. 1.5.3.1