1 /* Copyright (C) 2003, 2004 Free Software Foundation, Inc.
2 written by Alexandre Oliva <aoliva@redhat.com>
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it 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.
10 In addition to the permissions in the GNU Lesser General Public
11 License, the Free Software Foundation gives you unlimited
12 permission to link the compiled version of this file with other
13 programs, and to distribute those programs without any restriction
14 coming from the use of this file. (The GNU Lesser General Public
15 License restrictions do apply in other respects; for example, they
16 cover modification of the file, and distribution when not linked
17 into another program.)
19 The GNU C Library is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 Library General Public License for more details.
24 You should have received a copy of the GNU Lesser General Public
25 License along with the GNU C Library; see the file COPYING.LIB. If
26 not, see <http://www.gnu.org/licenses/>. */
30 #include <sys/types.h>
33 /* This file is to be compiled into crt object files, to enable
34 executables to easily self-relocate. */
41 /* Compute the runtime address of pointer in the range [p,e), and then
42 map the pointer pointed by it. */
43 static __always_inline void ***
44 reloc_range_indirect (void ***p, void ***e,
45 const struct elf32_fdpic_loadmap *map)
49 if (*p != (void **)-1)
51 void *ptr = __reloc_pointer (*p, map);
52 if (ptr != (void *)-1)
57 unsigned char *c = ptr;
60 for (i = 0; i < 4; i++)
66 pt = __reloc_pointer (pt, map);
69 unsigned char *c = ptr;
71 unsigned long v = (unsigned long)pt;
72 for (i = 0; i < 4; i++, v >>= 8)
84 /* Call __reloc_range_indirect for the given range except for the last
85 entry, whose contents are only relocated. It's expected to hold
87 attribute_hidden void*
88 __self_reloc (const struct elf32_fdpic_loadmap *map,
91 p = reloc_range_indirect (p, e-1, map);
96 return __reloc_pointer (*p, map);
100 /* These are other functions that might be useful, but that we don't
103 /* Remap pointers in [p,e). */
104 static __always_inline void**
105 reloc_range (void **p, void **e,
106 const struct elf32_fdpic_loadmap *map)
110 *p = __reloc_pointer (*p, map);
116 /* Remap p, adjust e by the same offset, then map the pointers in the
117 range determined by them. */
118 void attribute_hidden
119 __reloc_range (const struct elf32_fdpic_loadmap *map,
124 p = __reloc_pointer (p, map);
126 reloc_range (p, e, map);
129 /* Remap p, adjust e by the same offset, then map pointers referenced
130 by the (unadjusted) pointers in the range. Return the relocated
131 value of the last pointer in the range. */
132 void* attribute_hidden
133 __reloc_range_indirect (const struct elf32_fdpic_loadmap *map,
134 void ***p, void ***e)
138 p = __reloc_pointer (p, map);
140 return reloc_range_indirect (p, e, map);
144 #endif /* __BFIN_FDPIC__ */