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-2001, 2004, 2005, 2006 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       _LINK_H
00022 #define       _LINK_H       1
00023 
00024 #include <features.h>
00025 #include <elf.h>
00026 #include <dlfcn.h>
00027 #include <sys/types.h>
00028 
00029 /* We use this macro to refer to ELF types independent of the native wordsize.
00030    `ElfW(TYPE)' is used in place of `Elf32_TYPE' or `Elf64_TYPE'.  */
00031 #define ElfW(type)   _ElfW (Elf, __ELF_NATIVE_CLASS, type)
00032 #define _ElfW(e,w,t) _ElfW_1 (e, w, _##t)
00033 #define _ElfW_1(e,w,t)      e##w##t
00034 
00035 #include <bits/elfclass.h>         /* Defines __ELF_NATIVE_CLASS.  */
00036 #include <bits/link.h>
00037 
00038 /* Rendezvous structure used by the run-time dynamic linker to communicate
00039    details of shared object loading to the debugger.  If the executable's
00040    dynamic section has a DT_DEBUG element, the run-time linker sets that
00041    element's value to the address where this structure can be found.  */
00042 
00043 struct r_debug
00044   {
00045     int r_version;          /* Version number for this protocol.  */
00046 
00047     struct link_map *r_map; /* Head of the chain of loaded objects.  */
00048 
00049     /* This is the address of a function internal to the run-time linker,
00050        that will always be called when the linker begins to map in a
00051        library or unmap it, and again when the mapping change is complete.
00052        The debugger can set a breakpoint at this address if it wants to
00053        notice shared object mapping changes.  */
00054     ElfW(Addr) r_brk;
00055     enum
00056       {
00057        /* This state value describes the mapping change taking place when
00058           the `r_brk' address is called.  */
00059        RT_CONSISTENT,              /* Mapping change is complete.  */
00060        RT_ADD,                     /* Beginning to add a new object.  */
00061        RT_DELETE            /* Beginning to remove an object mapping.  */
00062       } r_state;
00063 
00064     ElfW(Addr) r_ldbase;    /* Base address the linker is loaded at.  */
00065   };
00066 
00067 /* This is the instance of that structure used by the dynamic linker.  */
00068 extern struct r_debug _r_debug;
00069 
00070 /* This symbol refers to the "dynamic structure" in the `.dynamic' section
00071    of whatever module refers to `_DYNAMIC'.  So, to find its own
00072    `struct r_debug', a program could do:
00073      for (dyn = _DYNAMIC; dyn->d_tag != DT_NULL; ++dyn)
00074        if (dyn->d_tag == DT_DEBUG)
00075         r_debug = (struct r_debug *) dyn->d_un.d_ptr;
00076    */
00077 extern ElfW(Dyn) _DYNAMIC[];
00078 
00079 /* Structure describing a loaded shared object.  The `l_next' and `l_prev'
00080    members form a chain of all the shared objects loaded at startup.
00081 
00082    These data structures exist in space used by the run-time dynamic linker;
00083    modifying them may have disastrous results.  */
00084 
00085 struct link_map
00086   {
00087     /* These first few members are part of the protocol with the debugger.
00088        This is the same format used in SVR4.  */
00089 
00090     ElfW(Addr) l_addr;             /* Base address shared object is loaded at.  */
00091     char *l_name;           /* Absolute file name object was found in.  */
00092     ElfW(Dyn) *l_ld;        /* Dynamic section of the shared object.  */
00093     struct link_map *l_next, *l_prev; /* Chain of loaded objects.  */
00094   };
00095 
00096 #ifdef __USE_GNU
00097 
00098 /* Version numbers for la_version handshake interface.  */
00099 #define LAV_CURRENT  1
00100 
00101 /* Activity types signaled through la_activity.  */
00102 enum
00103   {
00104     LA_ACT_CONSISTENT,             /* Link map consistent again.  */
00105     LA_ACT_ADD,                    /* New object will be added.  */
00106     LA_ACT_DELETE           /* Objects will be removed.  */
00107   };
00108 
00109 /* Values representing origin of name for dynamic loading.  */
00110 enum
00111   {
00112     LA_SER_ORIG = 0x01,            /* Original name.  */
00113     LA_SER_LIBPATH = 0x02,  /* Directory from LD_LIBRARY_PATH.  */
00114     LA_SER_RUNPATH = 0x04,  /* Directory from RPATH/RUNPATH.  */
00115     LA_SER_CONFIG = 0x08,   /* Found through ldconfig.  */
00116     LA_SER_DEFAULT = 0x40,  /* Default directory.  */
00117     LA_SER_SECURE = 0x80    /* Unused.  */
00118   };
00119 
00120 /* Values for la_objopen return value.  */
00121 enum
00122   {
00123     LA_FLG_BINDTO = 0x01,   /* Audit symbols bound to this object.  */
00124     LA_FLG_BINDFROM = 0x02  /* Audit symbols bound from this object.  */
00125   };
00126 
00127 /* Values for la_symbind flags parameter.  */
00128 enum
00129   {
00130     LA_SYMB_NOPLTENTER = 0x01,     /* la_pltenter will not be called.  */
00131     LA_SYMB_NOPLTEXIT = 0x02,      /* la_pltexit will not be called.  */
00132     LA_SYMB_STRUCTCALL = 0x04,     /* Return value is a structure.  */
00133     LA_SYMB_DLSYM = 0x08,   /* Binding due to dlsym call.  */
00134     LA_SYMB_ALTVALUE = 0x10 /* Value has been changed by a previous
00135                                la_symbind call.  */
00136   };
00137 
00138 struct dl_phdr_info
00139   {
00140     ElfW(Addr) dlpi_addr;
00141     const char *dlpi_name;
00142     const ElfW(Phdr) *dlpi_phdr;
00143     ElfW(Half) dlpi_phnum;
00144 
00145     /* Note: Following members were introduced after the first
00146        version of this structure was available.  Check the SIZE
00147        argument passed to the dl_iterate_phdr callback to determine
00148        whether or not each later member is available.  */
00149 
00150     /* Incremented when a new object may have been added.  */
00151     unsigned long long int dlpi_adds;
00152     /* Incremented when an object may have been removed.  */
00153     unsigned long long int dlpi_subs;
00154 
00155     /* If there is a PT_TLS segment, its module ID as used in
00156        TLS relocations, else zero.  */
00157     size_t dlpi_tls_modid;
00158 
00159     /* The address of the calling thread's instance of this module's
00160        PT_TLS segment, if it has one and it has been allocated
00161        in the calling thread, otherwise a null pointer.  */
00162     void *dlpi_tls_data;
00163   };
00164 
00165 __BEGIN_DECLS
00166 
00167 extern int dl_iterate_phdr (int (*__callback) (struct dl_phdr_info *,
00168                                           size_t, void *),
00169                          void *__data);
00170 
00171 
00172 /* Prototypes for the ld.so auditing interfaces.  These are not
00173    defined anywhere in ld.so but instead have to be provided by the
00174    auditing DSO.  */
00175 extern unsigned int la_version (unsigned int __version);
00176 extern void la_activity (uintptr_t *__cookie, unsigned int __flag);
00177 extern char *la_objsearch (const char *__name, uintptr_t *__cookie,
00178                         unsigned int __flag);
00179 extern unsigned int la_objopen (struct link_map *__map, Lmid_t __lmid,
00180                             uintptr_t *__cookie);
00181 extern void la_preinit (uintptr_t *__cookie);
00182 extern uintptr_t la_symbind32 (Elf32_Sym *__sym, unsigned int __ndx,
00183                             uintptr_t *__refcook, uintptr_t *__defcook,
00184                             unsigned int *__flags, const char *__symname);
00185 extern uintptr_t la_symbind64 (Elf64_Sym *__sym, unsigned int __ndx,
00186                             uintptr_t *__refcook, uintptr_t *__defcook,
00187                             unsigned int *__flags, const char *__symname);
00188 extern unsigned int la_objclose (uintptr_t *__cookie);
00189 
00190 __END_DECLS
00191 
00192 #endif
00193 
00194 #endif /* link.h */