64fa5793d24cce83c1441e38001b56fc19f5d822
[platform/upstream/glibc.git] / elf / dl-conflict.c
1 /* Resolve conflicts against already prelinked libraries.
2    Copyright (C) 2001-2021 Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
4
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.
9
10    The GNU C Library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Lesser General Public License for more details.
14
15    You should have received a copy of the GNU Lesser General Public
16    License along with the GNU C Library; see the file COPYING.LIB.  If
17    not, see <https://www.gnu.org/licenses/>.  */
18
19 #include <errno.h>
20 #include <libintl.h>
21 #include <stdlib.h>
22 #include <unistd.h>
23 #include <ldsodefs.h>
24 #include <sys/mman.h>
25 #include <sys/param.h>
26 #include <sys/types.h>
27 #include "dynamic-link.h"
28
29 void
30 _dl_resolve_conflicts (struct link_map *l, ElfW(Rela) *conflict,
31                        ElfW(Rela) *conflictend)
32 {
33 #if ! ELF_MACHINE_NO_RELA
34   if (__glibc_unlikely (GLRO(dl_debug_mask) & DL_DEBUG_RELOC))
35     _dl_debug_printf ("\nconflict processing: %s\n", DSO_FILENAME (l->l_name));
36
37   {
38     /* Do the conflict relocation of the object and library GOT and other
39        data.  */
40
41     /* This macro is used as a callback from the ELF_DYNAMIC_RELOCATE code.  */
42 #define RESOLVE_MAP(ref, version, flags) (*ref = NULL, NULL)
43 #define RESOLVE(ref, version, flags) (*ref = NULL, 0)
44 #define RESOLVE_CONFLICT_FIND_MAP(map, r_offset) \
45   do {                                                                        \
46     while ((resolve_conflict_map->l_map_end < (ElfW(Addr)) (r_offset))        \
47            || (resolve_conflict_map->l_map_start > (ElfW(Addr)) (r_offset)))  \
48       resolve_conflict_map = resolve_conflict_map->l_next;                    \
49                                                                               \
50     (map) = resolve_conflict_map;                                             \
51   } while (0)
52
53     /* Prelinking makes no sense for anything but the main namespace.  */
54     assert (l->l_ns == LM_ID_BASE);
55     struct link_map *resolve_conflict_map __attribute__ ((__unused__))
56       = GL(dl_ns)[LM_ID_BASE]._ns_loaded;
57
58 #include "dynamic-link.h"
59
60     /* Override these, defined in dynamic-link.h.  */
61 #undef CHECK_STATIC_TLS
62 #define CHECK_STATIC_TLS(ref_map, sym_map) ((void) 0)
63 #undef TRY_STATIC_TLS
64 #define TRY_STATIC_TLS(ref_map, sym_map) (0)
65
66     GL(dl_num_cache_relocations) += conflictend - conflict;
67
68     for (; conflict < conflictend; ++conflict)
69       elf_machine_rela (l, conflict, NULL, NULL, (void *) conflict->r_offset,
70                         0);
71   }
72 #endif
73 }