1 /* vi: set sw=4 ts=4: */
3 * Various assembly language/system dependent hacks that are required
4 * so that we can minimize the amount of platform specific code.
5 * Copyright (C) 2000-2004 by Erik Andersen <andersen@codepoet.org>
8 #ifndef _ARCH_DL_SYSDEP
9 #define _ARCH_DL_SYSDEP
11 /* Define this if the system uses RELOCA. */
12 #undef ELF_USES_RELOCA
14 /* Initialization sequence for the GOT. */
15 #define INIT_GOT(GOT_BASE,MODULE) \
17 GOT_BASE[2] = (unsigned long) _dl_linux_resolve; \
18 GOT_BASE[1] = (unsigned long) MODULE; \
21 static __always_inline unsigned long arm_modulus(unsigned long m, unsigned long p)
23 unsigned long i,t,inc;
25 while (!(i&(1<<31))) {
30 for (inc=t;inc>2;inc--) {
48 #define do_rem(result, n, base) ((result) = arm_modulus(n, base))
49 #define do_div_10(result, remain) ((result) = (((result) - (remain)) / 2) * -(-1ul / 5ul))
51 /* Here we define the magic numbers that this dynamic loader should accept */
55 /* Used for error messages */
56 #define ELF_TARGET "ARM"
59 unsigned long _dl_linux_resolver(struct elf_resolve * tpnt, int reloc_entry);
61 /* ELF_RTYPE_CLASS_PLT iff TYPE describes relocation of a PLT entry or
62 TLS variable, so undefined references should not be allowed to
65 ELF_RTYPE_CLASS_NOCOPY iff TYPE should not be allowed to resolve to one
66 of the main executable's symbols, as for a COPY reloc. */
67 #define elf_machine_type_class(type) \
68 ((((type) == R_ARM_JUMP_SLOT || (type) == R_ARM_TLS_DTPMOD32 \
69 || (type) == R_ARM_TLS_DTPOFF32 || (type) == R_ARM_TLS_TPOFF32) \
70 * ELF_RTYPE_CLASS_PLT) \
71 | (((type) == R_ARM_COPY) * ELF_RTYPE_CLASS_COPY))
73 /* Return the link-time address of _DYNAMIC. Conveniently, this is the
74 first element of the GOT. We used to use the PIC register to do this
75 without a constant pool reference, but GCC 4.2 will use a pseudo-register
76 for the PIC base, so it may not be in r10. */
77 static __always_inline Elf32_Addr __attribute__ ((unused))
78 elf_machine_dynamic (void)
81 #if !defined __thumb__
82 __asm__ ("ldr %0, 2f\n"
83 "1: ldr %0, [pc, %0]\n"
85 "2: .word _GLOBAL_OFFSET_TABLE_ - (1b+8)\n"
86 "3:" : "=r" (dynamic));
94 "1: ldr %0, [pc, %0]\n"
96 "2: .word _GLOBAL_OFFSET_TABLE_ - (1b+8)\n"
102 : "=r" (dynamic), "=&r" (tmp));
108 extern /*void*/ int __dl_start __asm__ ("_dl_start");
110 /* Return the run-time load address of the shared object. */
111 static __always_inline Elf32_Addr __attribute__ ((unused))
112 elf_machine_load_address (void)
114 Elf32_Addr got_addr = (Elf32_Addr) &__dl_start;
115 Elf32_Addr pcrel_addr;
116 #if defined __OPTIMIZE__ && !defined __thumb__
117 __asm__ ("adr %0, _dl_start" : "=r" (pcrel_addr));
119 /* A simple adr does not work in Thumb mode because the offset is
120 negative, and for debug builds may be too large. */
122 __asm__ ("adr %1, 1f\n\t"
127 "1: .word _dl_start - 1b\n\t"
129 : "=r" (pcrel_addr), "=r" (tmp));
131 return pcrel_addr - got_addr;
134 static __always_inline void
135 elf_machine_relative (Elf32_Addr load_off, const Elf32_Addr rel_addr,
136 Elf32_Word relative_count)
138 Elf32_Rel * rpnt = (void *) rel_addr;
141 Elf32_Addr *const reloc_addr = (void *) (load_off + (++rpnt)->r_offset);
143 *reloc_addr += load_off;
144 } while (--relative_count);
146 #endif /* !_ARCH_DL_SYSDEP */
149 #define DL_MALLOC_ALIGN 8 /* EABI needs 8 byte alignment for STRD LDRD */