dl-sysdep.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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) 2017-2018 by Waldemar Brodkorb <wbx@uclibc-ng.org>
  6. * Copyright (C) 2018 Kalray Inc.
  7. * Ported from GNU C Library
  8. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  9. */
  10. /* Copyright (C) 1995-2017 Free Software Foundation, Inc.
  11. The GNU C Library is free software; you can redistribute it and/or
  12. modify it under the terms of the GNU Lesser General Public License as
  13. published by the Free Software Foundation; either version 2.1 of the
  14. License, or (at your option) any later version.
  15. The GNU C Library is distributed in the hope that it will be useful,
  16. but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. Lesser General Public License for more details.
  19. You should have received a copy of the GNU Lesser General Public
  20. License along with the GNU C Library; if not, see
  21. <http://www.gnu.org/licenses/>. */
  22. /* Defines that this system uses RELOCA. */
  23. #define ELF_USES_RELOCA
  24. #include <elf.h>
  25. #include <link.h>
  26. /* Initialization sequence for the GOT. */
  27. #define INIT_GOT(GOT_BASE,MODULE) \
  28. { \
  29. GOT_BASE[2] = (unsigned long) _dl_linux_resolve; \
  30. GOT_BASE[1] = (unsigned long) MODULE; \
  31. }
  32. /* Here we define the magic numbers that this dynamic loader should accept */
  33. #define MAGIC1 EM_KVX
  34. #undef MAGIC2
  35. /* Used for error messages */
  36. #define ELF_TARGET "kvx"
  37. #define ARCH_NEEDS_BOOTSTRAP_RELOCS
  38. struct elf_resolve;
  39. unsigned long _dl_linux_resolver(struct elf_resolve * tpnt, int reloc_entry);
  40. #define elf_machine_type_class(type) \
  41. ((((type) == R_KVX_JMP_SLOT || (type) == R_KVX_64_DTPMOD || \
  42. (type) == R_KVX_64_DTPOFF \
  43. || (type) == R_KVX_64_TPOFF) \
  44. * ELF_RTYPE_CLASS_PLT) \
  45. | (((type) == R_KVX_COPY) * ELF_RTYPE_CLASS_COPY))
  46. /* Return the link-time address of _DYNAMIC. Conveniently, this is the
  47. first element of the GOT. */
  48. extern const ElfW(Addr) _GLOBAL_OFFSET_TABLE_[] attribute_hidden;
  49. static __always_inline ElfW(Addr) __attribute__ ((unused))
  50. elf_machine_dynamic (void)
  51. {
  52. unsigned long *ptr;
  53. __asm__("\n"
  54. "pcrel %0 = @gotaddr()\n"
  55. ";;\n" : "=r"(ptr) :: );
  56. return *ptr;
  57. }
  58. /* Return the run-time load address of the shared object. */
  59. static __always_inline ElfW(Addr) __attribute__ ((unused))
  60. elf_machine_load_address (void)
  61. {
  62. /* To figure out the load address we use the definition that for any symbol:
  63. dynamic_addr(symbol) = static_addr(symbol) + load_addr
  64. _DYNAMIC sysmbol is used here as its link-time address stored in
  65. the special unrelocated first GOT entry. */
  66. extern ElfW(Dyn) _DYNAMIC[] attribute_hidden;
  67. return (ElfW(Addr)) &_DYNAMIC - elf_machine_dynamic ();
  68. }
  69. static __always_inline void
  70. elf_machine_relative(Elf64_Addr load_off, const Elf64_Addr rel_addr,
  71. Elf64_Word relative_count)
  72. {
  73. Elf64_Rela *rpnt = (Elf64_Rela*)rel_addr;
  74. --rpnt;
  75. do {
  76. Elf64_Addr *const reloc_addr = (Elf64_Addr*)(load_off + (++rpnt)->r_offset);
  77. *reloc_addr = load_off + rpnt->r_addend;
  78. } while (--relative_count);
  79. }