dl-machine.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /* Machine-dependent ELF dynamic relocation inline functions. Stub version.
  2. Copyright (C) 1995-2019 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. <http://www.gnu.org/licenses/>. */
  15. #define ELF_MACHINE_NAME "stub"
  16. #include <string.h>
  17. #include <link.h>
  18. /* Return nonzero iff ELF header is compatible with the running host. */
  19. static inline int
  20. elf_machine_matches_host (const Elf32_Ehdr *ehdr)
  21. {
  22. switch (ehdr->e_machine)
  23. {
  24. default:
  25. return 0;
  26. }
  27. }
  28. /* Return the link-time address of _DYNAMIC. */
  29. static inline Elf32_Addr
  30. elf_machine_dynamic (void)
  31. {
  32. #error "Damn, no _DYNAMIC"
  33. }
  34. /* Return the run-time load address of the shared object. */
  35. static inline Elf32_Addr
  36. elf_machine_load_address (void)
  37. {
  38. #error "Where am I?"
  39. }
  40. /* Fixup a PLT entry to bounce directly to the function at VALUE. */
  41. static inline ElfW(Addr)
  42. elf_machine_fixup_plt (struct link_map *map, lookup_t t,
  43. const ElfW(Sym) *refsym, const ElfW(Sym) *sym,
  44. const ElfW(Rel) *reloc,
  45. ElfW(Addr) *reloc_addr, ElfW(Addr) value)
  46. {
  47. return *reloc_addr = value;
  48. }
  49. /* Perform the relocation specified by RELOC and SYM (which is fully resolved).
  50. LOADADDR is the load address of the object; INFO is an array indexed
  51. by DT_* of the .dynamic section info. */
  52. auto inline void
  53. __attribute__ ((always_inline))
  54. elf_machine_rel (Elf32_Addr loadaddr, Elf32_Dyn *info[DT_NUM],
  55. const Elf32_Rel *reloc, const Elf32_Sym *sym,
  56. Elf32_Addr (*resolve) (const Elf32_Sym **ref,
  57. Elf32_Addr reloc_addr,
  58. int noplt))
  59. {
  60. Elf32_Addr *const reloc_addr = (Elf32_Addr *) reloc->r_offset;
  61. Elf32_Addr loadbase;
  62. switch (ELF32_R_TYPE (reloc->r_info))
  63. {
  64. case R_MACHINE_COPY:
  65. loadbase = (*resolve) (&sym, (Elf32_Addr) reloc_addr, 0);
  66. memcpy (reloc_addr, (void *) (loadbase + sym->st_value), sym->st_size);
  67. break;
  68. default:
  69. _dl_reloc_bad_type (map, ELF32_R_TYPE (reloc->r_info), 0);
  70. break;
  71. }
  72. }
  73. auto inline Elf32_Addr
  74. __attribute__ ((always_inline))
  75. elf_machine_rela (Elf32_Addr loadaddr, Elf32_Dyn *info[DT_NUM],
  76. const Elf32_Rel *reloc, const Elf32_Sym *sym,
  77. Elf32_Addr (*resolve) (const Elf32_Sym **ref,
  78. Elf32_Addr reloc_addr,
  79. int noplt))
  80. {
  81. _dl_signal_error (0, "Elf32_Rela relocation requested -- unused on "
  82. NULL, ELF_MACHINE_NAME);
  83. }
  84. /* Set up the loaded object described by L so its unrelocated PLT
  85. entries will jump to the on-demand fixup code in dl-runtime.c. */
  86. static inline int
  87. elf_machine_runtime_setup (struct link_map *l, int lazy)
  88. {
  89. extern void _dl_runtime_resolve (Elf32_Word);
  90. if (lazy)
  91. {
  92. /* The GOT entries for functions in the PLT have not yet been filled
  93. in. Their initial contents will arrange when called to push an
  94. offset into the .rel.plt section, push _GLOBAL_OFFSET_TABLE_[1],
  95. and then jump to _GLOBAL_OFFSET_TABLE[2]. */
  96. Elf32_Addr *got = (Elf32_Addr *) D_PTR (l, l_info[DT_PLTGOT]);
  97. got[1] = (Elf32_Addr) l; /* Identify this shared object. */
  98. /* This function will get called to fix up the GOT entry indicated by
  99. the offset on the stack, and then jump to the resolved address. */
  100. got[2] = (Elf32_Addr) &_dl_runtime_resolve;
  101. }
  102. return lazy;
  103. }
  104. /* Initial entry point code for the dynamic linker.
  105. The C function `_dl_start' is the real entry point;
  106. its return value is the user program's entry point. */
  107. #define RTLD_START #error need some startup code