dl-sysdep.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Various assembly language/system dependent hacks that are required
  3. * so that we can minimize the amount of platform specific code.
  4. * Copyright (C) 2000-2004 by Erik Andersen <andersen@codepoet.org>
  5. * Copyright (C) 2019 by Waldemar Brodkorb <wbx@uclibc-ng.org>
  6. * Ported from GNU C Library
  7. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  8. */
  9. /* Copyright (C) 2011-2019 Free Software Foundation, Inc.
  10. The GNU C Library is free software; you can redistribute it and/or
  11. modify it under the terms of the GNU Lesser General Public License as
  12. published by the Free Software Foundation; either version 2.1 of the
  13. License, or (at your option) any later version.
  14. The GNU C Library is distributed in the hope that it will be useful,
  15. but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. Lesser General Public License for more details.
  18. You should have received a copy of the GNU Lesser General Public
  19. License along with the GNU C Library; if not, see
  20. <https://www.gnu.org/licenses/>. */
  21. /* Define this if the system uses RELOCA. */
  22. #define ELF_USES_RELOCA
  23. #include <elf.h>
  24. #include <link.h>
  25. /* Initialization sequence for the GOT. */
  26. #define INIT_GOT(GOT_BASE,MODULE) \
  27. { \
  28. GOT_BASE[2] = (unsigned long) _dl_linux_resolve; \
  29. GOT_BASE[1] = (unsigned long) MODULE; \
  30. }
  31. /* Here we define the magic numbers that this dynamic loader should accept */
  32. #define MAGIC1 EM_RISCV
  33. #undef MAGIC2
  34. /* Used for error messages */
  35. #define ELF_TARGET "RISC-V"
  36. struct elf_resolve;
  37. unsigned long _dl_linux_resolver(struct elf_resolve * tpnt, int reloc_entry);
  38. #define ELF_MACHINE_JMP_SLOT R_RISCV_JUMP_SLOT
  39. #define elf_machine_type_class(type) \
  40. ((ELF_RTYPE_CLASS_PLT * ((type) == ELF_MACHINE_JMP_SLOT \
  41. || (__WORDSIZE == 32 && (type) == R_RISCV_TLS_DTPREL32) \
  42. || (__WORDSIZE == 32 && (type) == R_RISCV_TLS_DTPMOD32) \
  43. || (__WORDSIZE == 32 && (type) == R_RISCV_TLS_TPREL32) \
  44. || (__WORDSIZE == 64 && (type) == R_RISCV_TLS_DTPREL64) \
  45. || (__WORDSIZE == 64 && (type) == R_RISCV_TLS_DTPMOD64) \
  46. || (__WORDSIZE == 64 && (type) == R_RISCV_TLS_TPREL64))) \
  47. | (ELF_RTYPE_CLASS_COPY * ((type) == R_RISCV_COPY)))
  48. /* Return the link-time address of _DYNAMIC. */
  49. static inline ElfW(Addr)
  50. elf_machine_dynamic (void)
  51. {
  52. extern ElfW(Addr) _GLOBAL_OFFSET_TABLE_ __attribute__ ((visibility ("hidden")));
  53. return _GLOBAL_OFFSET_TABLE_;
  54. }
  55. /* Return the run-time load address of the shared object. */
  56. static __always_inline ElfW(Addr) __attribute__ ((unused))
  57. elf_machine_load_address (void)
  58. {
  59. ElfW(Addr) load_addr;
  60. __asm__ ("lla %0, _DYNAMIC" : "=r" (load_addr));
  61. return load_addr - elf_machine_dynamic ();
  62. }
  63. static __always_inline void
  64. elf_machine_relative(Elf64_Addr load_off, const Elf64_Addr rel_addr,
  65. Elf64_Word relative_count)
  66. {
  67. Elf64_Rela *rpnt = (Elf64_Rela*)rel_addr;
  68. --rpnt;
  69. do {
  70. Elf64_Addr *const reloc_addr = (Elf64_Addr*)(load_off + (++rpnt)->r_offset);
  71. *reloc_addr = load_off + rpnt->r_addend;
  72. } while (--relative_count);
  73. }