dl-sysdep.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. * Ported from GNU C Library
  7. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  8. */
  9. /* Copyright (C) 1995-2017 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. <http://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_AARCH64
  33. #undef MAGIC2
  34. /* Used for error messages */
  35. #define ELF_TARGET "aarch64"
  36. struct elf_resolve;
  37. unsigned long _dl_linux_resolver(struct elf_resolve * tpnt, int reloc_entry);
  38. #define elf_machine_type_class(type) \
  39. ((((type) == R_AARCH64_JUMP_SLOT \
  40. || (type) == R_AARCH64_TLS_DTPMOD \
  41. || (type) == R_AARCH64_TLS_DTPREL \
  42. || (type) == R_AARCH64_TLS_TPREL \
  43. || (type) == R_AARCH64_TLSDESC) * ELF_RTYPE_CLASS_PLT) \
  44. | (((type) == R_AARCH64_COPY) * ELF_RTYPE_CLASS_COPY))
  45. /* Return the link-time address of _DYNAMIC. Conveniently, this is the
  46. first element of the GOT. */
  47. extern const ElfW(Addr) _GLOBAL_OFFSET_TABLE_[] attribute_hidden;
  48. static __always_inline ElfW(Addr) __attribute__ ((unused))
  49. elf_machine_dynamic (void)
  50. {
  51. return _GLOBAL_OFFSET_TABLE_[0];
  52. }
  53. /* Return the run-time load address of the shared object. */
  54. static __always_inline ElfW(Addr) __attribute__ ((unused))
  55. elf_machine_load_address (void)
  56. {
  57. /* To figure out the load address we use the definition that for any symbol:
  58. dynamic_addr(symbol) = static_addr(symbol) + load_addr
  59. _DYNAMIC sysmbol is used here as its link-time address stored in
  60. the special unrelocated first GOT entry. */
  61. extern ElfW(Dyn) _DYNAMIC[] attribute_hidden;
  62. return (ElfW(Addr)) &_DYNAMIC - elf_machine_dynamic ();
  63. }
  64. static __always_inline void
  65. elf_machine_relative(Elf64_Addr load_off, const Elf64_Addr rel_addr,
  66. Elf64_Word relative_count)
  67. {
  68. Elf64_Rela *rpnt = (Elf64_Rela*)rel_addr;
  69. --rpnt;
  70. do {
  71. Elf64_Addr *const reloc_addr = (Elf64_Addr*)(load_off + (++rpnt)->r_offset);
  72. *reloc_addr = load_off + rpnt->r_addend;
  73. } while (--relative_count);
  74. }