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/>. */
28 #include <sys/types.h>
31 /* This file is to be compiled into crt object files, to enable
32 executables to easily self-relocate. */
34 /* Compute the runtime address of pointer in the range [p,e), and then
35 map the pointer pointed by it. */
36 static __always_inline void ***
37 reloc_range_indirect (void ***p, void ***e,
38 const struct elf32_fdpic_loadmap *map)
42 void *ptr = __reloc_pointer (*p, map);
47 __builtin_memcpy(&pt, ptr, sizeof(pt));
50 pt = __reloc_pointer (pt, map);
52 __builtin_memcpy(ptr, &pt, sizeof(pt));
61 /* Call __reloc_range_indirect for the given range except for the last
62 entry, whose contents are only relocated. It's expected to hold
64 void* attribute_hidden
65 __self_reloc (const struct elf32_fdpic_loadmap *map,
68 p = reloc_range_indirect (p, e-1, map);
73 return __reloc_pointer (*p, map);
77 /* These are other functions that might be useful, but that we don't
80 /* Remap pointers in [p,e). */
81 static __always_inline void**
82 reloc_range (void **p, void **e,
83 const struct elf32_fdpic_loadmap *map)
87 *p = __reloc_pointer (*p, map);
93 /* Remap p, adjust e by the same offset, then map the pointers in the
94 range determined by them. */
96 __reloc_range (const struct elf32_fdpic_loadmap *map,
101 p = __reloc_pointer (p, map);
103 reloc_range (p, e, map);
106 /* Remap p, adjust e by the same offset, then map pointers referenced
107 by the (unadjusted) pointers in the range. Return the relocated
108 value of the last pointer in the range. */
109 void* attribute_hidden
110 __reloc_range_indirect (const struct elf32_fdpic_loadmap *map,
111 void ***p, void ***e)
115 p = __reloc_pointer (p, map);
117 return reloc_range_indirect (p, e, map);