~ubuntu-branches/ubuntu/trusty/eglibc/trusty

« back to all changes in this revision

Viewing changes to elf/get-dynamic-info.h

  • Committer: Package Import Robot
  • Author(s): Adam Conrad
  • Date: 2013-01-10 18:39:35 UTC
  • mfrom: (1.5.2) (4.4.24 experimental)
  • Revision ID: package-import@ubuntu.com-20130110183935-afsgfxkmg7wk5eaj
Tags: 2.17-0ubuntu1
* Merge with Debian, bringing in a new upstream and many small fixes:
  - patches/any/cvs-malloc-deadlock.diff: Dropped, merged upstream.
  - patches/ubuntu/lddebug-scopes.diff: Rebase for upstream changes.
  - patches/ubuntu/local-CVE-2012-3406.diff: Rebased against upstream.
  - patches/ubuntu/no-asm-mtune-i686.diff: Fixed in recent binutils.
* This upstream merge fixes a nasty hang in pulseaudio (LP: #1085342)
* Bump MIN_KERNEL_SUPPORTED to 2.6.32 on ARM, now that we no longer
  have to support shonky 2.6.31 kernels on imx51 babbage builders.
* Drop patches/ubuntu/local-disable-nscd-host-caching.diff, as these
  issues were apparently resolved upstream a while ago (LP: #613662)
* Fix the compiled-in bug URL to point to launchpad.net, not Debian.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Read the dynamic section at DYN and fill in INFO with indices DT_*.
 
2
   Copyright (C) 2012 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
 
7
   License as published by the Free Software Foundation; either
 
8
   version 2.1 of the 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; if not, see
 
17
   <http://www.gnu.org/licenses/>.  */
 
18
 
 
19
#include <assert.h>
 
20
 
 
21
#ifndef RESOLVE_MAP
 
22
static
 
23
#else
 
24
auto
 
25
#endif
 
26
inline void __attribute__ ((unused, always_inline))
 
27
elf_get_dynamic_info (struct link_map *l, ElfW(Dyn) *temp)
 
28
{
 
29
  ElfW(Dyn) *dyn = l->l_ld;
 
30
  ElfW(Dyn) **info;
 
31
#if __ELF_NATIVE_CLASS == 32
 
32
  typedef Elf32_Word d_tag_utype;
 
33
#elif __ELF_NATIVE_CLASS == 64
 
34
  typedef Elf64_Xword d_tag_utype;
 
35
#endif
 
36
 
 
37
#ifndef RTLD_BOOTSTRAP
 
38
  if (dyn == NULL)
 
39
    return;
 
40
#endif
 
41
 
 
42
  info = l->l_info;
 
43
 
 
44
  while (dyn->d_tag != DT_NULL)
 
45
    {
 
46
      if ((d_tag_utype) dyn->d_tag < DT_NUM)
 
47
        info[dyn->d_tag] = dyn;
 
48
      else if (dyn->d_tag >= DT_LOPROC &&
 
49
               dyn->d_tag < DT_LOPROC + DT_THISPROCNUM)
 
50
        info[dyn->d_tag - DT_LOPROC + DT_NUM] = dyn;
 
51
      else if ((d_tag_utype) DT_VERSIONTAGIDX (dyn->d_tag) < DT_VERSIONTAGNUM)
 
52
        info[VERSYMIDX (dyn->d_tag)] = dyn;
 
53
      else if ((d_tag_utype) DT_EXTRATAGIDX (dyn->d_tag) < DT_EXTRANUM)
 
54
        info[DT_EXTRATAGIDX (dyn->d_tag) + DT_NUM + DT_THISPROCNUM
 
55
             + DT_VERSIONTAGNUM] = dyn;
 
56
      else if ((d_tag_utype) DT_VALTAGIDX (dyn->d_tag) < DT_VALNUM)
 
57
        info[DT_VALTAGIDX (dyn->d_tag) + DT_NUM + DT_THISPROCNUM
 
58
             + DT_VERSIONTAGNUM + DT_EXTRANUM] = dyn;
 
59
      else if ((d_tag_utype) DT_ADDRTAGIDX (dyn->d_tag) < DT_ADDRNUM)
 
60
        info[DT_ADDRTAGIDX (dyn->d_tag) + DT_NUM + DT_THISPROCNUM
 
61
             + DT_VERSIONTAGNUM + DT_EXTRANUM + DT_VALNUM] = dyn;
 
62
      ++dyn;
 
63
    }
 
64
 
 
65
#define DL_RO_DYN_TEMP_CNT      8
 
66
 
 
67
#ifndef DL_RO_DYN_SECTION
 
68
  /* Don't adjust .dynamic unnecessarily.  */
 
69
  if (l->l_addr != 0)
 
70
    {
 
71
      ElfW(Addr) l_addr = l->l_addr;
 
72
      int cnt = 0;
 
73
 
 
74
# define ADJUST_DYN_INFO(tag) \
 
75
      do                                                                      \
 
76
        if (info[tag] != NULL)                                                \
 
77
          {                                                                   \
 
78
            if (temp)                                                         \
 
79
              {                                                               \
 
80
                temp[cnt].d_tag = info[tag]->d_tag;                           \
 
81
                temp[cnt].d_un.d_ptr = info[tag]->d_un.d_ptr + l_addr;        \
 
82
                info[tag] = temp + cnt++;                                     \
 
83
              }                                                               \
 
84
            else                                                              \
 
85
              info[tag]->d_un.d_ptr += l_addr;                                \
 
86
          }                                                                   \
 
87
      while (0)
 
88
 
 
89
      ADJUST_DYN_INFO (DT_HASH);
 
90
      ADJUST_DYN_INFO (DT_PLTGOT);
 
91
      ADJUST_DYN_INFO (DT_STRTAB);
 
92
      ADJUST_DYN_INFO (DT_SYMTAB);
 
93
# if ! ELF_MACHINE_NO_RELA
 
94
      ADJUST_DYN_INFO (DT_RELA);
 
95
# endif
 
96
# if ! ELF_MACHINE_NO_REL
 
97
      ADJUST_DYN_INFO (DT_REL);
 
98
# endif
 
99
      ADJUST_DYN_INFO (DT_JMPREL);
 
100
      ADJUST_DYN_INFO (VERSYMIDX (DT_VERSYM));
 
101
      ADJUST_DYN_INFO (DT_ADDRTAGIDX (DT_GNU_HASH) + DT_NUM + DT_THISPROCNUM
 
102
                       + DT_VERSIONTAGNUM + DT_EXTRANUM + DT_VALNUM);
 
103
# undef ADJUST_DYN_INFO
 
104
      assert (cnt <= DL_RO_DYN_TEMP_CNT);
 
105
    }
 
106
#endif
 
107
  if (info[DT_PLTREL] != NULL)
 
108
    {
 
109
#if ELF_MACHINE_NO_RELA
 
110
      assert (info[DT_PLTREL]->d_un.d_val == DT_REL);
 
111
#elif ELF_MACHINE_NO_REL
 
112
      assert (info[DT_PLTREL]->d_un.d_val == DT_RELA);
 
113
#else
 
114
      assert (info[DT_PLTREL]->d_un.d_val == DT_REL
 
115
              || info[DT_PLTREL]->d_un.d_val == DT_RELA);
 
116
#endif
 
117
    }
 
118
#if ! ELF_MACHINE_NO_RELA
 
119
  if (info[DT_RELA] != NULL)
 
120
    assert (info[DT_RELAENT]->d_un.d_val == sizeof (ElfW(Rela)));
 
121
# endif
 
122
# if ! ELF_MACHINE_NO_REL
 
123
  if (info[DT_REL] != NULL)
 
124
    assert (info[DT_RELENT]->d_un.d_val == sizeof (ElfW(Rel)));
 
125
#endif
 
126
#ifdef RTLD_BOOTSTRAP
 
127
  /* Only the bind now flags are allowed.  */
 
128
  assert (info[VERSYMIDX (DT_FLAGS_1)] == NULL
 
129
          || (info[VERSYMIDX (DT_FLAGS_1)]->d_un.d_val & ~DF_1_NOW) == 0);
 
130
  assert (info[DT_FLAGS] == NULL
 
131
          || (info[DT_FLAGS]->d_un.d_val & ~DF_BIND_NOW) == 0);
 
132
  /* Flags must not be set for ld.so.  */
 
133
  assert (info[DT_RUNPATH] == NULL);
 
134
  assert (info[DT_RPATH] == NULL);
 
135
#else
 
136
  if (info[DT_FLAGS] != NULL)
 
137
    {
 
138
      /* Flags are used.  Translate to the old form where available.
 
139
         Since these l_info entries are only tested for NULL pointers it
 
140
         is ok if they point to the DT_FLAGS entry.  */
 
141
      l->l_flags = info[DT_FLAGS]->d_un.d_val;
 
142
 
 
143
      if (l->l_flags & DF_SYMBOLIC)
 
144
        info[DT_SYMBOLIC] = info[DT_FLAGS];
 
145
      if (l->l_flags & DF_TEXTREL)
 
146
        info[DT_TEXTREL] = info[DT_FLAGS];
 
147
      if (l->l_flags & DF_BIND_NOW)
 
148
        info[DT_BIND_NOW] = info[DT_FLAGS];
 
149
    }
 
150
  if (info[VERSYMIDX (DT_FLAGS_1)] != NULL)
 
151
    {
 
152
      l->l_flags_1 = info[VERSYMIDX (DT_FLAGS_1)]->d_un.d_val;
 
153
 
 
154
      /* Only DT_1_SUPPORTED_MASK bits are supported, and we would like
 
155
         to assert this, but we can't. Users have been setting
 
156
         unsupported DF_1_* flags for a long time and glibc has ignored
 
157
         them. Therefore to avoid breaking existing applications the
 
158
         best we can do is add a warning during debugging with the
 
159
         intent of notifying the user of the problem.  */
 
160
      if (__builtin_expect (GLRO(dl_debug_mask) & DL_DEBUG_FILES, 0)
 
161
          && l->l_flags_1 & ~DT_1_SUPPORTED_MASK)
 
162
        _dl_debug_printf ("\nWARNING: Unsupported flag value(s) of 0x%x in DT_FLAGS_1.\n",
 
163
                          l->l_flags_1 & ~DT_1_SUPPORTED_MASK);
 
164
 
 
165
      if (l->l_flags_1 & DF_1_NOW)
 
166
        info[DT_BIND_NOW] = info[VERSYMIDX (DT_FLAGS_1)];
 
167
    }
 
168
  if (info[DT_RUNPATH] != NULL)
 
169
    /* If both RUNPATH and RPATH are given, the latter is ignored.  */
 
170
    info[DT_RPATH] = NULL;
 
171
#endif
 
172
}