crtreloc.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /* Copyright (C) 2003, 2004 Free Software Foundation, Inc.
  2. written by Alexandre Oliva <aoliva@redhat.com>
  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 License as
  6. published by the Free Software Foundation; either version 2.1 of the
  7. License, or (at your option) any later version.
  8. In addition to the permissions in the GNU Lesser General Public
  9. License, the Free Software Foundation gives you unlimited
  10. permission to link the compiled version of this file with other
  11. programs, and to distribute those programs without any restriction
  12. coming from the use of this file. (The GNU Lesser General Public
  13. License restrictions do apply in other respects; for example, they
  14. cover modification of the file, and distribution when not linked
  15. into another program.)
  16. The GNU C Library is distributed in the hope that it will be useful,
  17. but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. Library General Public License for more details.
  20. You should have received a copy of the GNU Lesser General Public
  21. License along with the GNU C Library; see the file COPYING.LIB. If
  22. not, see <http://www.gnu.org/licenses/>. */
  23. #ifdef __FRV_FDPIC__
  24. #include <sys/types.h>
  25. #include <link.h>
  26. /* This file is to be compiled into crt object files, to enable
  27. executables to easily self-relocate. */
  28. /* Compute the runtime address of pointer in the range [p,e), and then
  29. map the pointer pointed by it. */
  30. static __always_inline void ***
  31. reloc_range_indirect (void ***p, void ***e,
  32. const struct elf32_fdpic_loadmap *map)
  33. {
  34. while (p < e)
  35. {
  36. void *ptr = __reloc_pointer (*p, map);
  37. if (ptr)
  38. {
  39. void *pt;
  40. if ((long)ptr & 3)
  41. __builtin_memcpy(&pt, ptr, sizeof(pt));
  42. else
  43. pt = *(void**)ptr;
  44. pt = __reloc_pointer (pt, map);
  45. if ((long)ptr & 3)
  46. __builtin_memcpy(ptr, &pt, sizeof(pt));
  47. else
  48. *(void**)ptr = pt;
  49. }
  50. p++;
  51. }
  52. return p;
  53. }
  54. /* Call __reloc_range_indirect for the given range except for the last
  55. entry, whose contents are only relocated. It's expected to hold
  56. the GOT value. */
  57. attribute_hidden void*
  58. __self_reloc (const struct elf32_fdpic_loadmap *map,
  59. void ***p, void ***e)
  60. {
  61. p = reloc_range_indirect (p, e-1, map);
  62. if (p >= e)
  63. return (void*)-1;
  64. return __reloc_pointer (*p, map);
  65. }
  66. #endif /* __FRV_FDPIC__ */