cpp-d1064d
[cross.git] / i686-linux-gnu-4.7 / usr / include / link.h
1 /* Data structure for communication from the run-time dynamic linker for
2    loaded ELF shared objects.
3    Copyright (C) 1995-2018 Free Software Foundation, Inc.
4    This file is part of the GNU C Library.
5
6    The GNU C Library is free software; you can redistribute it and/or
7    modify it under the terms of the GNU Lesser General Public
8    License as published by the Free Software Foundation; either
9    version 2.1 of the License, or (at your option) any later version.
10
11    The GNU C Library is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14    Lesser General Public License for more details.
15
16    You should have received a copy of the GNU Lesser General Public
17    License along with the GNU C Library; if not, see
18    <http://www.gnu.org/licenses/>.  */
19
20 #ifndef _LINK_H
21 #define _LINK_H 1
22
23 #include <features.h>
24 #include <elf.h>
25 #include <dlfcn.h>
26 #include <sys/types.h>
27
28 /* We use this macro to refer to ELF types independent of the native wordsize.
29    `ElfW(TYPE)' is used in place of `Elf32_TYPE' or `Elf64_TYPE'.  */
30 #define ElfW(type)      _ElfW (Elf, __ELF_NATIVE_CLASS, type)
31 #define _ElfW(e,w,t)    _ElfW_1 (e, w, _##t)
32 #define _ElfW_1(e,w,t)  e##w##t
33
34 #include <bits/elfclass.h>              /* Defines __ELF_NATIVE_CLASS.  */
35 #include <bits/link.h>
36
37 /* Rendezvous structure used by the run-time dynamic linker to communicate
38    details of shared object loading to the debugger.  If the executable's
39    dynamic section has a DT_DEBUG element, the run-time linker sets that
40    element's value to the address where this structure can be found.  */
41
42 struct r_debug
43   {
44     int r_version;              /* Version number for this protocol.  */
45
46     struct link_map *r_map;     /* Head of the chain of loaded objects.  */
47
48     /* This is the address of a function internal to the run-time linker,
49        that will always be called when the linker begins to map in a
50        library or unmap it, and again when the mapping change is complete.
51        The debugger can set a breakpoint at this address if it wants to
52        notice shared object mapping changes.  */
53     ElfW(Addr) r_brk;
54     enum
55       {
56         /* This state value describes the mapping change taking place when
57            the `r_brk' address is called.  */
58         RT_CONSISTENT,          /* Mapping change is complete.  */
59         RT_ADD,                 /* Beginning to add a new object.  */
60         RT_DELETE               /* Beginning to remove an object mapping.  */
61       } r_state;
62
63     ElfW(Addr) r_ldbase;        /* Base address the linker is loaded at.  */
64   };
65
66 /* This is the instance of that structure used by the dynamic linker.  */
67 extern struct r_debug _r_debug;
68
69 /* This symbol refers to the "dynamic structure" in the `.dynamic' section
70    of whatever module refers to `_DYNAMIC'.  So, to find its own
71    `struct r_debug', a program could do:
72      for (dyn = _DYNAMIC; dyn->d_tag != DT_NULL; ++dyn)
73        if (dyn->d_tag == DT_DEBUG)
74          r_debug = (struct r_debug *) dyn->d_un.d_ptr;
75    */
76 extern ElfW(Dyn) _DYNAMIC[];
77
78 /* Structure describing a loaded shared object.  The `l_next' and `l_prev'
79    members form a chain of all the shared objects loaded at startup.
80
81    These data structures exist in space used by the run-time dynamic linker;
82    modifying them may have disastrous results.  */
83
84 struct link_map
85   {
86     /* These first few members are part of the protocol with the debugger.
87        This is the same format used in SVR4.  */
88
89     ElfW(Addr) l_addr;          /* Difference between the address in the ELF
90                                    file and the addresses in memory.  */
91     char *l_name;               /* Absolute file name object was found in.  */
92     ElfW(Dyn) *l_ld;            /* Dynamic section of the shared object.  */
93     struct link_map *l_next, *l_prev; /* Chain of loaded objects.  */
94   };
95
96 #ifdef __USE_GNU
97
98 /* Version numbers for la_version handshake interface.  */
99 #define LAV_CURRENT     1
100
101 /* Activity types signaled through la_activity.  */
102 enum
103   {
104     LA_ACT_CONSISTENT,          /* Link map consistent again.  */
105     LA_ACT_ADD,                 /* New object will be added.  */
106     LA_ACT_DELETE               /* Objects will be removed.  */
107   };
108
109 /* Values representing origin of name for dynamic loading.  */
110 enum
111   {
112     LA_SER_ORIG = 0x01,         /* Original name.  */
113     LA_SER_LIBPATH = 0x02,      /* Directory from LD_LIBRARY_PATH.  */
114     LA_SER_RUNPATH = 0x04,      /* Directory from RPATH/RUNPATH.  */
115     LA_SER_CONFIG = 0x08,       /* Found through ldconfig.  */
116     LA_SER_DEFAULT = 0x40,      /* Default directory.  */
117     LA_SER_SECURE = 0x80        /* Unused.  */
118   };
119
120 /* Values for la_objopen return value.  */
121 enum
122   {
123     LA_FLG_BINDTO = 0x01,       /* Audit symbols bound to this object.  */
124     LA_FLG_BINDFROM = 0x02      /* Audit symbols bound from this object.  */
125   };
126
127 /* Values for la_symbind flags parameter.  */
128 enum
129   {
130     LA_SYMB_NOPLTENTER = 0x01,  /* la_pltenter will not be called.  */
131     LA_SYMB_NOPLTEXIT = 0x02,   /* la_pltexit will not be called.  */
132     LA_SYMB_STRUCTCALL = 0x04,  /* Return value is a structure.  */
133     LA_SYMB_DLSYM = 0x08,       /* Binding due to dlsym call.  */
134     LA_SYMB_ALTVALUE = 0x10     /* Value has been changed by a previous
135                                    la_symbind call.  */
136   };
137
138 struct dl_phdr_info
139   {
140     ElfW(Addr) dlpi_addr;
141     const char *dlpi_name;
142     const ElfW(Phdr) *dlpi_phdr;
143     ElfW(Half) dlpi_phnum;
144
145     /* Note: Following members were introduced after the first
146        version of this structure was available.  Check the SIZE
147        argument passed to the dl_iterate_phdr callback to determine
148        whether or not each later member is available.  */
149
150     /* Incremented when a new object may have been added.  */
151     __extension__ unsigned long long int dlpi_adds;
152     /* Incremented when an object may have been removed.  */
153     __extension__ unsigned long long int dlpi_subs;
154
155     /* If there is a PT_TLS segment, its module ID as used in
156        TLS relocations, else zero.  */
157     size_t dlpi_tls_modid;
158
159     /* The address of the calling thread's instance of this module's
160        PT_TLS segment, if it has one and it has been allocated
161        in the calling thread, otherwise a null pointer.  */
162     void *dlpi_tls_data;
163   };
164
165 __BEGIN_DECLS
166
167 extern int dl_iterate_phdr (int (*__callback) (struct dl_phdr_info *,
168                                                size_t, void *),
169                             void *__data);
170
171
172 /* Prototypes for the ld.so auditing interfaces.  These are not
173    defined anywhere in ld.so but instead have to be provided by the
174    auditing DSO.  */
175 extern unsigned int la_version (unsigned int __version);
176 extern void la_activity (uintptr_t *__cookie, unsigned int __flag);
177 extern char *la_objsearch (const char *__name, uintptr_t *__cookie,
178                            unsigned int __flag);
179 extern unsigned int la_objopen (struct link_map *__map, Lmid_t __lmid,
180                                 uintptr_t *__cookie);
181 extern void la_preinit (uintptr_t *__cookie);
182 extern uintptr_t la_symbind32 (Elf32_Sym *__sym, unsigned int __ndx,
183                                uintptr_t *__refcook, uintptr_t *__defcook,
184                                unsigned int *__flags, const char *__symname);
185 extern uintptr_t la_symbind64 (Elf64_Sym *__sym, unsigned int __ndx,
186                                uintptr_t *__refcook, uintptr_t *__defcook,
187                                unsigned int *__flags, const char *__symname);
188 extern unsigned int la_objclose (uintptr_t *__cookie);
189
190 __END_DECLS
191
192 #endif
193
194 #endif /* link.h */