dl-sysdep.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. /* Copyright (C) 2003, 2004 Red Hat, Inc.
  2. Contributed by Alexandre Oliva <aoliva@redhat.com>
  3. Based on ../i386/dl-sysdep.h
  4. This file is part of uClibc.
  5. uClibc is free software; you can redistribute it and/or modify it
  6. under the terms of the GNU Lesser General Public License as
  7. published by the Free Software Foundation; either version 2.1 of the
  8. License, or (at your option) any later version.
  9. uClibc is distributed in the hope that it will be useful, but WITHOUT
  10. ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Library General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with uClibc; see the file COPYING.LIB. If not, write to
  15. the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
  16. USA. */
  17. /*
  18. * Various assembly language/system dependent hacks that are required
  19. * so that we can minimize the amount of platform specific code.
  20. */
  21. /*
  22. * Define this if the system uses RELOCA.
  23. */
  24. #undef ELF_USES_RELOCA
  25. /* JMPREL relocs are inside the DT_RELA table. */
  26. #define ELF_MACHINE_PLTREL_OVERLAP
  27. #define DL_NO_COPY_RELOCS
  28. #define HAVE_DL_INLINES_H
  29. /*
  30. * Initialization sequence for a GOT. Copy the resolver function
  31. * descriptor and the pointer to the elf_resolve/link_map data
  32. * structure. Initialize the got_value in the module while at that.
  33. */
  34. #define INIT_GOT(GOT_BASE,MODULE) \
  35. { \
  36. (MODULE)->loadaddr.got_value = (GOT_BASE); \
  37. GOT_BASE[0] = ((unsigned long *)&_dl_linux_resolve)[0]; \
  38. GOT_BASE[1] = ((unsigned long *)&_dl_linux_resolve)[1]; \
  39. GOT_BASE[2] = (unsigned long) MODULE; \
  40. }
  41. /* Here we define the magic numbers that this dynamic loader should accept */
  42. #define MAGIC1 EM_BLACKFIN
  43. #undef MAGIC2
  44. /* Used for error messages */
  45. #define ELF_TARGET "BFIN"
  46. /* Need bootstrap relocations */
  47. #define ARCH_NEEDS_BOOTSTRAP_RELOCS
  48. struct elf_resolve;
  49. struct funcdesc_value
  50. {
  51. void *entry_point;
  52. void *got_value;
  53. } __attribute__((__aligned__(8)));
  54. extern int _dl_linux_resolve(void) __attribute__((__visibility__("hidden")));
  55. struct funcdesc_ht;
  56. #undef SEND_EARLY_STDERR
  57. #define SEND_EARLY_STDERR(S) \
  58. do { \
  59. static const char __attribute__((section(".text"))) __s[] = (S); \
  60. const char *__p, *__scratch; \
  61. __asm__ ("call 1f;\n1:\n\t" \
  62. "%1 = RETS;\n\t" \
  63. "%0 = [%3 + 1b@GOT17M4];\n\t" \
  64. "%1 = %1 - %0;\n\t" \
  65. "%1 = %1 + %2;\n\t" \
  66. : "=&d" (__scratch), "=&d" (__p) \
  67. : "d" (__s), "a" (dl_boot_got_pointer) : "RETS"); \
  68. SEND_STDERR (__p); \
  69. { int __t; \
  70. for (__t = 0; __t < 0x1000000; __t++) __asm__ __volatile__ (""); } \
  71. } while (0)
  72. #define DL_LOADADDR_TYPE struct elf32_fdpic_loadaddr
  73. #define DL_RELOC_ADDR(LOADADDR, ADDR) \
  74. ((ElfW(Addr))__reloc_pointer ((void*)(ADDR), (LOADADDR).map))
  75. #define DL_ADDR_TO_FUNC_PTR(ADDR, LOADADDR) \
  76. ((void(*)(void)) _dl_funcdesc_for ((void*)(ADDR), (LOADADDR).got_value))
  77. #define _dl_stabilize_funcdesc(val) \
  78. ({ __asm__ ("" : "+m" (*(val))); (val); })
  79. #define DL_CALL_FUNC_AT_ADDR(ADDR, LOADADDR, SIGNATURE, ...) \
  80. ({ struct funcdesc_value fd = { (void*)(ADDR), (LOADADDR).got_value }; \
  81. void (*pf)(void) = (void*) _dl_stabilize_funcdesc (&fd); \
  82. (* SIGNATURE pf)(__VA_ARGS__); })
  83. #define DL_INIT_LOADADDR_BOOT(LOADADDR, BASEADDR) \
  84. (__dl_init_loadaddr_map (&(LOADADDR), dl_boot_got_pointer, \
  85. dl_boot_ldsomap ?: dl_boot_progmap))
  86. #define DL_INIT_LOADADDR_PROG(LOADADDR, BASEADDR) \
  87. (__dl_init_loadaddr_map (&(LOADADDR), 0, dl_boot_progmap))
  88. #define DL_INIT_LOADADDR_EXTRA_DECLS \
  89. int dl_init_loadaddr_load_count;
  90. #define DL_INIT_LOADADDR(LOADADDR, BASEADDR, PHDR, PHDRCNT) \
  91. (dl_init_loadaddr_load_count = \
  92. __dl_init_loadaddr (&(LOADADDR), (PHDR), (PHDRCNT)))
  93. #define DL_INIT_LOADADDR_HDR(LOADADDR, ADDR, PHDR) \
  94. (__dl_init_loadaddr_hdr ((LOADADDR), (ADDR), (PHDR), \
  95. dl_init_loadaddr_load_count))
  96. #define DL_LOADADDR_UNMAP(LOADADDR, LEN) \
  97. (__dl_loadaddr_unmap ((LOADADDR), (NULL)))
  98. #define DL_LIB_UNMAP(LIB, LEN) \
  99. (__dl_loadaddr_unmap ((LIB)->loadaddr, (LIB)->funcdesc_ht))
  100. #define DL_LOADADDR_BASE(LOADADDR) \
  101. ((LOADADDR).got_value)
  102. /* This is called from dladdr(), such that we map a function
  103. descriptor's address to the function's entry point before trying to
  104. find in which library it's defined. */
  105. #define DL_LOOKUP_ADDRESS(ADDRESS) (_dl_lookup_address (ADDRESS))
  106. #define DL_ADDR_IN_LOADADDR(ADDR, TPNT, TFROM) \
  107. (! (TFROM) && __dl_addr_in_loadaddr ((void*)(ADDR), (TPNT)->loadaddr))
  108. /*
  109. * Compute the GOT address. On several platforms, we use assembly
  110. * here. on FR-V FDPIC, there's no way to compute the GOT address,
  111. * since the offset between text and data is not fixed, so we arrange
  112. * for the assembly _dl_boot to pass this value as an argument to
  113. * _dl_boot. */
  114. #define DL_BOOT_COMPUTE_GOT(got) ((got) = dl_boot_got_pointer)
  115. #define DL_BOOT_COMPUTE_DYN(dpnt, got, load_addr) \
  116. ((dpnt) = dl_boot_ldso_dyn_pointer)
  117. /* We only support loading FDPIC independently-relocatable shared
  118. libraries. It probably wouldn't be too hard to support loading
  119. shared libraries that require relocation by the same amount, but we
  120. don't know that they exist or would be useful, and the dynamic
  121. loader code could leak the whole-library map unless we keeping a
  122. bit more state for DL_LOADADDR_UNMAP and DL_LIB_UNMAP, so let's
  123. keep things simple for now. */
  124. #define DL_CHECK_LIB_TYPE(epnt, piclib, _dl_progname, libname) \
  125. do \
  126. { \
  127. if (((epnt)->e_flags & EF_BFIN_FDPIC) && ! ((epnt)->e_flags & EF_BFIN_PIC)) \
  128. (piclib) = 2; \
  129. else \
  130. { \
  131. _dl_internal_error_number = LD_ERROR_NOTDYN; \
  132. _dl_dprintf(2, "%s: '%s' is not an FDPIC shared library" \
  133. "\n", (_dl_progname), (libname)); \
  134. _dl_close(infile); \
  135. return NULL; \
  136. } \
  137. \
  138. } \
  139. while (0)
  140. /* We want want to apply all relocations in the interpreter during
  141. bootstrap. Because of this, we have to skip the interpreter
  142. relocations in _dl_parse_relocation_information(), see
  143. elfinterp.c. */
  144. #define DL_SKIP_BOOTSTRAP_RELOC(SYMTAB, INDEX, STRTAB) 0
  145. #ifdef __NR_pread
  146. #define _DL_PREAD(FD, BUF, SIZE, OFFSET) \
  147. (_dl_pread((FD), (BUF), (SIZE), (OFFSET)))
  148. #endif
  149. /* We want to return to dlsym() a function descriptor if the symbol
  150. turns out to be a function. */
  151. #define DL_FIND_HASH_VALUE(TPNT, TYPE_CLASS, SYM) \
  152. (((TYPE_CLASS) & ELF_RTYPE_CLASS_DLSYM) \
  153. && ELF32_ST_TYPE((SYM)->st_info) == STT_FUNC \
  154. ? _dl_funcdesc_for ((void *)DL_RELOC_ADDR ((TPNT)->loadaddr, (SYM)->st_value), \
  155. (TPNT)->loadaddr.got_value) \
  156. : DL_RELOC_ADDR ((TPNT)->loadaddr, (SYM)->st_value))
  157. #define DL_IS_SPECIAL_SEGMENT(EPNT, PPNT) \
  158. __dl_is_special_segment(EPNT, PPNT)
  159. #define DL_MAP_SEGMENT(EPNT, PPNT, INFILE, FLAGS) \
  160. __dl_map_segment (EPNT, PPNT, INFILE, FLAGS)
  161. #define DL_GET_READY_TO_RUN_EXTRA_PARMS \
  162. , struct elf32_fdpic_loadmap *dl_boot_progmap, Elf32_Addr dl_boot_got_pointer
  163. #define DL_GET_READY_TO_RUN_EXTRA_ARGS \
  164. , dl_boot_progmap, dl_boot_got_pointer
  165. #ifdef __USE_GNU
  166. # include <link.h>
  167. #else
  168. # define __USE_GNU
  169. # include <link.h>
  170. # undef __USE_GNU
  171. #endif
  172. #include <elf.h>
  173. static __always_inline void
  174. elf_machine_relative (DL_LOADADDR_TYPE load_off, const Elf32_Addr rel_addr,
  175. Elf32_Word relative_count)
  176. {
  177. #if 0
  178. Elf32_Rel * rpnt = (void *) rel_addr;
  179. --rpnt;
  180. do {
  181. Elf32_Addr *const reloc_addr = (void *) (load_off + (++rpnt)->r_offset);
  182. *reloc_addr = DL_RELOC_ADDR (load_off, *reloc_addr);
  183. } while (--relative_count);
  184. #endif
  185. }