Back to index

glibc  2.9
link.h
Go to the documentation of this file.
00001 /* Data structure for communication from the run-time dynamic linker for
00002    loaded ELF shared objects.
00003    Copyright (C) 1995-2006, 2007 Free Software Foundation, Inc.
00004    This file is part of the GNU C Library.
00005 
00006    The GNU C Library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Lesser General Public
00008    License as published by the Free Software Foundation; either
00009    version 2.1 of the License, or (at your option) any later version.
00010 
00011    The GNU C Library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Lesser General Public License for more details.
00015 
00016    You should have received a copy of the GNU Lesser General Public
00017    License along with the GNU C Library; if not, write to the Free
00018    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00019    02111-1307 USA.  */
00020 
00021 #ifndef       _PRIVATE_LINK_H
00022 #define       _PRIVATE_LINK_H      1
00023 
00024 #ifdef _LINK_H
00025 # error this should be impossible
00026 #endif
00027 
00028 /* Get most of the contents from the public header, but we define a
00029    different `struct link_map' type for private use.  The la_objopen
00030    prototype uses the type, so we have to declare it separately.  */
00031 #define link_map     link_map_public
00032 #define la_objopen   la_objopen_wrongproto
00033 #include <elf/link.h>
00034 #undef link_map
00035 #undef la_objopen
00036 
00037 struct link_map;
00038 extern unsigned int la_objopen (struct link_map *__map, Lmid_t __lmid,
00039                             uintptr_t *__cookie);
00040 
00041 
00042 #include <stddef.h>
00043 #include <bits/linkmap.h>
00044 #include <dl-lookupcfg.h>
00045 #include <tls.h>
00046 #include <bits/libc-lock.h>
00047 
00048 
00049 /* Some internal data structures of the dynamic linker used in the
00050    linker map.  We only provide forward declarations.  */
00051 struct libname_list;
00052 struct r_found_version;
00053 struct r_search_path_elem;
00054 
00055 /* Forward declaration.  */
00056 struct link_map;
00057 
00058 /* Structure to describe a single list of scope elements.  The lookup
00059    functions get passed an array of pointers to such structures.  */
00060 struct r_scope_elem
00061 {
00062   /* Array of maps for the scope.  */
00063   struct link_map **r_list;
00064   /* Number of entries in the scope.  */
00065   unsigned int r_nlist;
00066 };
00067 
00068 
00069 /* Structure to record search path and allocation mechanism.  */
00070 struct r_search_path_struct
00071   {
00072     struct r_search_path_elem **dirs;
00073     int malloced;
00074   };
00075 
00076 
00077 /* Structure describing a loaded shared object.  The `l_next' and `l_prev'
00078    members form a chain of all the shared objects loaded at startup.
00079 
00080    These data structures exist in space used by the run-time dynamic linker;
00081    modifying them may have disastrous results.
00082 
00083    This data structure might change in future, if necessary.  User-level
00084    programs must avoid defining objects of this type.  */
00085 
00086 struct link_map
00087   {
00088     /* These first few members are part of the protocol with the debugger.
00089        This is the same format used in SVR4.  */
00090 
00091     ElfW(Addr) l_addr;             /* Base address shared object is loaded at.  */
00092     char *l_name;           /* Absolute file name object was found in.  */
00093     ElfW(Dyn) *l_ld;        /* Dynamic section of the shared object.  */
00094     struct link_map *l_next, *l_prev; /* Chain of loaded objects.  */
00095 
00096     /* All following members are internal to the dynamic linker.
00097        They may change without notice.  */
00098 
00099     /* This is an element which is only ever different from a pointer to
00100        the very same copy of this type for ld.so when it is used in more
00101        than one namespace.  */
00102     struct link_map *l_real;
00103 
00104     /* Number of the namespace this link map belongs to.  */
00105     Lmid_t l_ns;
00106 
00107     struct libname_list *l_libname;
00108     /* Indexed pointers to dynamic section.
00109        [0,DT_NUM) are indexed by the processor-independent tags.
00110        [DT_NUM,DT_NUM+DT_THISPROCNUM) are indexed by the tag minus DT_LOPROC.
00111        [DT_NUM+DT_THISPROCNUM,DT_NUM+DT_THISPROCNUM+DT_VERSIONTAGNUM) are
00112        indexed by DT_VERSIONTAGIDX(tagvalue).
00113        [DT_NUM+DT_THISPROCNUM+DT_VERSIONTAGNUM,
00114        DT_NUM+DT_THISPROCNUM+DT_VERSIONTAGNUM+DT_EXTRANUM) are indexed by
00115        DT_EXTRATAGIDX(tagvalue).
00116        [DT_NUM+DT_THISPROCNUM+DT_VERSIONTAGNUM+DT_EXTRANUM,
00117        DT_NUM+DT_THISPROCNUM+DT_VERSIONTAGNUM+DT_EXTRANUM+DT_VALNUM) are
00118        indexed by DT_VALTAGIDX(tagvalue) and
00119        [DT_NUM+DT_THISPROCNUM+DT_VERSIONTAGNUM+DT_EXTRANUM+DT_VALNUM,
00120        DT_NUM+DT_THISPROCNUM+DT_VERSIONTAGNUM+DT_EXTRANUM+DT_VALNUM+DT_ADDRNUM)
00121        are indexed by DT_ADDRTAGIDX(tagvalue), see <elf.h>.  */
00122 
00123     ElfW(Dyn) *l_info[DT_NUM + DT_THISPROCNUM + DT_VERSIONTAGNUM
00124                     + DT_EXTRANUM + DT_VALNUM + DT_ADDRNUM];
00125     const ElfW(Phdr) *l_phdr;      /* Pointer to program header table in core.  */
00126     ElfW(Addr) l_entry;            /* Entry point location.  */
00127     ElfW(Half) l_phnum;            /* Number of program header entries.  */
00128     ElfW(Half) l_ldnum;            /* Number of dynamic segment entries.  */
00129 
00130     /* Array of DT_NEEDED dependencies and their dependencies, in
00131        dependency order for symbol lookup (with and without
00132        duplicates).  There is no entry before the dependencies have
00133        been loaded.  */
00134     struct r_scope_elem l_searchlist;
00135 
00136     /* We need a special searchlist to process objects marked with
00137        DT_SYMBOLIC.  */
00138     struct r_scope_elem l_symbolic_searchlist;
00139 
00140     /* Dependent object that first caused this object to be loaded.  */
00141     struct link_map *l_loader;
00142 
00143     /* Array with version names.  */
00144     struct r_found_version *l_versions;
00145     unsigned int l_nversions;
00146 
00147     /* Symbol hash table.  */
00148     Elf_Symndx l_nbuckets;
00149     Elf32_Word l_gnu_bitmask_idxbits;
00150     Elf32_Word l_gnu_shift;
00151     const ElfW(Addr) *l_gnu_bitmask;
00152     union
00153     {
00154       const Elf32_Word *l_gnu_buckets;
00155       const Elf_Symndx *l_chain;
00156     };
00157     union
00158     {
00159       const Elf32_Word *l_gnu_chain_zero;
00160       const Elf_Symndx *l_buckets;
00161     };
00162 
00163     unsigned int l_direct_opencount; /* Reference count for dlopen/dlclose.  */
00164     enum                    /* Where this object came from.  */
00165       {
00166        lt_executable,              /* The main executable program.  */
00167        lt_library,          /* Library needed by main executable.  */
00168        lt_loaded            /* Extra run-time loaded shared object.  */
00169       } l_type:2;
00170     unsigned int l_relocated:1;    /* Nonzero if object's relocations done.  */
00171     unsigned int l_init_called:1; /* Nonzero if DT_INIT function called.  */
00172     unsigned int l_global:1;       /* Nonzero if object in _dl_global_scope.  */
00173     unsigned int l_reserved:2;     /* Reserved for internal use.  */
00174     unsigned int l_phdr_allocated:1; /* Nonzero if the data structure pointed
00175                                    to by `l_phdr' is allocated.  */
00176     unsigned int l_soname_added:1; /* Nonzero if the SONAME is for sure in
00177                                   the l_libname list.  */
00178     unsigned int l_faked:1; /* Nonzero if this is a faked descriptor
00179                                without associated file.  */
00180     unsigned int l_need_tls_init:1; /* Nonzero if GL(dl_init_static_tls)
00181                                    should be called on this link map
00182                                    when relocation finishes.  */
00183     unsigned int l_used:1;  /* Nonzero if the DSO is used.  */
00184     unsigned int l_auditing:1;     /* Nonzero if the DSO is used in auditing.  */
00185     unsigned int l_audit_any_plt:1; /* Nonzero if at least one audit module
00186                                    is interested in the PLT interception.*/
00187     unsigned int l_removed:1;      /* Nozero if the object cannot be used anymore
00188                                since it is removed.  */
00189     unsigned int l_contiguous:1; /* Nonzero if inter-segment holes are
00190                                 mprotected or if no holes are present at
00191                                 all.  */
00192 
00193     /* Collected information about own RPATH directories.  */
00194     struct r_search_path_struct l_rpath_dirs;
00195 
00196     /* Collected results of relocation while profiling.  */
00197     struct reloc_result
00198     {
00199       DL_FIXUP_VALUE_TYPE addr;
00200       struct link_map *bound;
00201       unsigned int boundndx;
00202       uint32_t enterexit;
00203       unsigned int flags;
00204     } *l_reloc_result;
00205 
00206     /* Pointer to the version information if available.  */
00207     ElfW(Versym) *l_versyms;
00208 
00209     /* String specifying the path where this object was found.  */
00210     const char *l_origin;
00211 
00212     /* Start and finish of memory map for this object.  l_map_start
00213        need not be the same as l_addr.  */
00214     ElfW(Addr) l_map_start, l_map_end;
00215     /* End of the executable part of the mapping.  */
00216     ElfW(Addr) l_text_end;
00217 
00218     /* Default array for 'l_scope'.  */
00219     struct r_scope_elem *l_scope_mem[4];
00220     /* Size of array allocated for 'l_scope'.  */
00221     size_t l_scope_max;
00222     /* This is an array defining the lookup scope for this link map.
00223        There are initially at most three different scope lists.  */
00224     struct r_scope_elem **l_scope;
00225 
00226     /* A similar array, this time only with the local scope.  This is
00227        used occasionally.  */
00228     struct r_scope_elem *l_local_scope[2];
00229 
00230     /* This information is kept to check for sure whether a shared
00231        object is the same as one already loaded.  */
00232     dev_t l_dev;
00233     ino64_t l_ino;
00234 
00235     /* Collected information about own RUNPATH directories.  */
00236     struct r_search_path_struct l_runpath_dirs;
00237 
00238     /* List of object in order of the init and fini calls.  */
00239     struct link_map **l_initfini;
00240 
00241     /* List of the dependencies introduced through symbol binding.  */
00242     unsigned int l_reldepsmax;
00243     struct link_map_reldeps
00244       {
00245        unsigned int act;
00246        struct link_map *list[];
00247       } *l_reldeps;
00248 
00249     /* Various flag words.  */
00250     ElfW(Word) l_feature_1;
00251     ElfW(Word) l_flags_1;
00252     ElfW(Word) l_flags;
00253 
00254     /* Temporarily used in `dl_close'.  */
00255     int l_idx;
00256 
00257     struct link_map_machine l_mach;
00258 
00259     struct
00260     {
00261       const ElfW(Sym) *sym;
00262       int type_class;
00263       struct link_map *value;
00264       const ElfW(Sym) *ret;
00265     } l_lookup_cache;
00266 
00267     /* Thread-local storage related info.  */
00268 
00269     /* Start of the initialization image.  */
00270     void *l_tls_initimage;
00271     /* Size of the initialization image.  */
00272     size_t l_tls_initimage_size;
00273     /* Size of the TLS block.  */
00274     size_t l_tls_blocksize;
00275     /* Alignment requirement of the TLS block.  */
00276     size_t l_tls_align;
00277     /* Offset of first byte module alignment.  */
00278     size_t l_tls_firstbyte_offset;
00279 #ifndef NO_TLS_OFFSET
00280 # define NO_TLS_OFFSET      0
00281 #endif
00282 #ifndef FORCED_DYNAMIC_TLS_OFFSET
00283 # if NO_TLS_OFFSET == 0
00284 #  define FORCED_DYNAMIC_TLS_OFFSET 1
00285 # elif NO_TLS_OFFSET == -1
00286 #  define FORCED_DYNAMIC_TLS_OFFSET -2
00287 # else
00288 #  error "FORCED_DYNAMIC_TLS_OFFSET is not defined"
00289 # endif
00290 #endif
00291     /* For objects present at startup time: offset in the static TLS block.  */
00292     ptrdiff_t l_tls_offset;
00293     /* Index of the module in the dtv array.  */
00294     size_t l_tls_modid;
00295 
00296     /* Information used to change permission after the relocations are
00297        done.  */
00298     ElfW(Addr) l_relro_addr;
00299     size_t l_relro_size;
00300 
00301     unsigned long long int l_serial;
00302 
00303     /* Audit information.  This array apparent must be the last in the
00304        structure.  Never add something after it.  */
00305     struct auditstate
00306     {
00307       uintptr_t cookie;
00308       unsigned int bindflags;
00309     } l_audit[0];
00310   };
00311 
00312 
00313 #if __ELF_NATIVE_CLASS == 32
00314 # define symbind symbind32
00315 #elif __ELF_NATIVE_CLASS == 64
00316 # define symbind symbind64
00317 #else
00318 # error "__ELF_NATIVE_CLASS must be defined"
00319 #endif
00320 
00321 extern int __dl_iterate_phdr (int (*callback) (struct dl_phdr_info *info,
00322                                           size_t size, void *data),
00323                            void *data);
00324 
00325 #endif /* include/link.h */