dl-sysdep.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. /*
  29. * Initialization sequence for a GOT. Copy the resolver function
  30. * descriptor and the pointer to the elf_resolve/link_map data
  31. * structure. Initialize the got_value in the module while at that.
  32. */
  33. #define INIT_GOT(GOT_BASE,MODULE) \
  34. { \
  35. (MODULE)->loadaddr.got_value = (GOT_BASE); \
  36. GOT_BASE[0] = ((unsigned long *)&_dl_linux_resolve)[0]; \
  37. GOT_BASE[1] = ((unsigned long *)&_dl_linux_resolve)[1]; \
  38. GOT_BASE[2] = (unsigned long) MODULE; \
  39. }
  40. /* Here we define the magic numbers that this dynamic loader should accept */
  41. #define MAGIC1 EM_CYGNUS_FRV
  42. #undef MAGIC2
  43. /* Used for error messages */
  44. #define ELF_TARGET "FR-V"
  45. struct elf_resolve;
  46. struct funcdesc_value
  47. {
  48. void *entry_point;
  49. void *got_value;
  50. } __attribute__((__aligned__(8)));
  51. extern int _dl_linux_resolve(void) __attribute__((__visibility__("hidden")));
  52. #define do_rem(result, n, base) ((result) = (n) % (base))
  53. /* 16KiB page alignment. Should perhaps be made dynamic using
  54. getpagesize(), based on AT_PAGESZ from auxvt? */
  55. #define PAGE_ALIGN 0xffffc000
  56. #define ADDR_ALIGN 0x3fff
  57. #define OFFS_ALIGN 0x7fffc000
  58. struct funcdesc_ht;
  59. /* We must force strings used early in the bootstrap into the data
  60. segment, such that they are referenced with GOTOFF instead of
  61. GPREL, because GPREL needs the GOT to have already been
  62. relocated. */
  63. #undef SEND_EARLY_STDERR
  64. #define SEND_EARLY_STDERR(S) \
  65. do { static char __s[] = (S); SEND_STDERR (__s); } while (0)
  66. #define DL_LOADADDR_TYPE struct elf32_fdpic_loadaddr
  67. #define DL_RELOC_ADDR(ADDR, LOADADDR) \
  68. (__reloc_pointer ((void*)(ADDR), (LOADADDR).map))
  69. #define DL_ADDR_TO_FUNC_PTR(ADDR, LOADADDR) \
  70. ((void(*)(void)) _dl_funcdesc_for ((void*)(ADDR), (LOADADDR).got_value))
  71. #define _dl_stabilize_funcdesc(val) \
  72. ({ asm ("" : "+m" (*(val))); (val); })
  73. #define DL_CALL_FUNC_AT_ADDR(ADDR, LOADADDR, SIGNATURE, ...) \
  74. ({ struct funcdesc_value fd = { (void*)(ADDR), (LOADADDR).got_value }; \
  75. void (*pf)(void) = (void*) _dl_stabilize_funcdesc (&fd); \
  76. (* SIGNATURE pf)(__VA_ARGS__); })
  77. #define DL_INIT_LOADADDR_BOOT(LOADADDR, BASEADDR) \
  78. (__dl_init_loadaddr_map (&(LOADADDR), dl_boot_got_pointer, \
  79. dl_boot_ldsomap ?: dl_boot_progmap))
  80. #define DL_INIT_LOADADDR_PROG(LOADADDR, BASEADDR) \
  81. (__dl_init_loadaddr_map (&(LOADADDR), 0, dl_boot_progmap))
  82. #define DL_INIT_LOADADDR_EXTRA_DECLS \
  83. int dl_init_loadaddr_load_count;
  84. #define DL_INIT_LOADADDR(LOADADDR, BASEADDR, PHDR, PHDRCNT) \
  85. (dl_init_loadaddr_load_count = \
  86. __dl_init_loadaddr (&(LOADADDR), (PHDR), (PHDRCNT)))
  87. #define DL_INIT_LOADADDR_HDR(LOADADDR, ADDR, PHDR) \
  88. (__dl_init_loadaddr_hdr ((LOADADDR), (ADDR), (PHDR), \
  89. dl_init_loadaddr_load_count))
  90. #define DL_LOADADDR_UNMAP(LOADADDR, LEN) \
  91. (__dl_loadaddr_unmap ((LOADADDR), (NULL)))
  92. #define DL_LIB_UNMAP(LIB, LEN) \
  93. (__dl_loadaddr_unmap ((LIB)->loadaddr, (LIB)->funcdesc_ht))
  94. #define DL_LOADADDR_BASE(LOADADDR) \
  95. ((LOADADDR).got_value)
  96. /* This is called from dladdr(), such that we map a function
  97. descriptor's address to the function's entry point before trying to
  98. find in which library it's defined. */
  99. #define DL_LOOKUP_ADDRESS(ADDRESS) (_dl_lookup_address (ADDRESS))
  100. #define DL_ADDR_IN_LOADADDR(ADDR, TPNT, TFROM) \
  101. (! (TFROM) && __dl_addr_in_loadaddr ((void*)(ADDR), (TPNT)->loadaddr))
  102. /* We only support loading FDPIC independently-relocatable shared
  103. libraries. It probably wouldn't be too hard to support loading
  104. shared libraries that require relocation by the same amount, but we
  105. don't know that they exist or would be useful, and the dynamic
  106. loader code could leak the whole-library map unless we keeping a
  107. bit more state for DL_LOADADDR_UNMAP and DL_LIB_UNMAP, so let's
  108. keep things simple for now. */
  109. #define DL_CHECK_LIB_TYPE(epnt, piclib, _dl_progname, libname) \
  110. do \
  111. { \
  112. if (((epnt)->e_flags & EF_FRV_FDPIC) && ! ((epnt)->e_flags & EF_FRV_PIC)) \
  113. (piclib) = 2; \
  114. else \
  115. { \
  116. _dl_internal_error_number = LD_ERROR_NOTDYN; \
  117. _dl_dprintf(2, "%s: '%s' is not an FDPIC shared library" \
  118. "\n", (_dl_progname), (libname)); \
  119. _dl_close(infile); \
  120. return NULL; \
  121. } \
  122. } \
  123. while (0)
  124. /* We want want to apply all relocations in the interpreter during
  125. bootstrap. Because of this, we have to skip the interpreter
  126. relocations in _dl_parse_relocation_information(), see
  127. elfinterp.c. */
  128. #define DL_SKIP_BOOTSTRAP_RELOC(SYMTAB, INDEX, STRTAB) 0
  129. #ifdef __NR_pread
  130. #define _DL_PREAD(FD, BUF, SIZE, OFFSET) \
  131. (_dl_pread((FD), (BUF), (SIZE), (OFFSET)))
  132. #endif
  133. /* We want to return to dlsym() a function descriptor if the symbol
  134. turns out to be a function. */
  135. #define DL_FIND_HASH_VALUE(TPNT, TYPE_CLASS, SYM) \
  136. (((TYPE_CLASS) & ELF_RTYPE_CLASS_DLSYM) \
  137. && ELF32_ST_TYPE((SYM)->st_info) == STT_FUNC \
  138. ? _dl_funcdesc_for (DL_RELOC_ADDR ((SYM)->st_value, (TPNT)->loadaddr), \
  139. (TPNT)->loadaddr.got_value) \
  140. : DL_RELOC_ADDR ((SYM)->st_value, (TPNT)->loadaddr))
  141. #ifdef __USE_GNU
  142. # include <link.h>
  143. #else
  144. # define __USE_GNU
  145. # include <link.h>
  146. # undef __USE_GNU
  147. #endif