Blame include/link.h

Packit 6c4009
/* Data structure for communication from the run-time dynamic linker for
Packit 6c4009
   loaded ELF shared objects.
Packit 6c4009
   Copyright (C) 1995-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library; if not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
#ifndef	_PRIVATE_LINK_H
Packit 6c4009
#define	_PRIVATE_LINK_H	1
Packit 6c4009
Packit 6c4009
#ifdef _LINK_H
Packit 6c4009
# error this should be impossible
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
# ifndef _ISOMAC
Packit 6c4009
/* Get most of the contents from the public header, but we define a
Packit 6c4009
   different `struct link_map' type for private use.  The la_objopen
Packit 6c4009
   prototype uses the type, so we have to declare it separately.  */
Packit 6c4009
#  define link_map	link_map_public
Packit 6c4009
#  define la_objopen	la_objopen_wrongproto
Packit 6c4009
# endif
Packit 6c4009
Packit 6c4009
#include <elf/link.h>
Packit 6c4009
Packit 6c4009
# ifndef _ISOMAC
Packit 6c4009
Packit 6c4009
#undef	link_map
Packit 6c4009
#undef	la_objopen
Packit 6c4009
Packit 6c4009
struct link_map;
Packit 6c4009
extern unsigned int la_objopen (struct link_map *__map, Lmid_t __lmid,
Packit 6c4009
				uintptr_t *__cookie);
Packit 6c4009
Packit 6c4009
#include <stdint.h>
Packit 6c4009
#include <stddef.h>
Packit 6c4009
#include <linkmap.h>
Packit 6c4009
#include <dl-fileid.h>
Packit 6c4009
#include <dl-lookupcfg.h>
Packit 6c4009
#include <tls.h>
Packit 6c4009
#include <libc-lock.h>
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Some internal data structures of the dynamic linker used in the
Packit 6c4009
   linker map.  We only provide forward declarations.  */
Packit 6c4009
struct libname_list;
Packit 6c4009
struct r_found_version;
Packit 6c4009
struct r_search_path_elem;
Packit 6c4009
Packit 6c4009
/* Forward declaration.  */
Packit 6c4009
struct link_map;
Packit 6c4009
Packit 6c4009
/* Structure to describe a single list of scope elements.  The lookup
Packit 6c4009
   functions get passed an array of pointers to such structures.  */
Packit 6c4009
struct r_scope_elem
Packit 6c4009
{
Packit 6c4009
  /* Array of maps for the scope.  */
Packit 6c4009
  struct link_map **r_list;
Packit 6c4009
  /* Number of entries in the scope.  */
Packit 6c4009
  unsigned int r_nlist;
Packit 6c4009
};
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Structure to record search path and allocation mechanism.  */
Packit 6c4009
struct r_search_path_struct
Packit 6c4009
  {
Packit 6c4009
    struct r_search_path_elem **dirs;
Packit 6c4009
    int malloced;
Packit 6c4009
  };
Packit 6c4009
Packit Service d4bcbe
Packit 6c4009
/* Structure describing a loaded shared object.  The `l_next' and `l_prev'
Packit 6c4009
   members form a chain of all the shared objects loaded at startup.
Packit 6c4009
Packit 6c4009
   These data structures exist in space used by the run-time dynamic linker;
Packit 6c4009
   modifying them may have disastrous results.
Packit 6c4009
Packit 6c4009
   This data structure might change in future, if necessary.  User-level
Packit 6c4009
   programs must avoid defining objects of this type.  */
Packit 6c4009
Packit 6c4009
struct link_map
Packit 6c4009
  {
Packit 6c4009
    /* These first few members are part of the protocol with the debugger.
Packit 6c4009
       This is the same format used in SVR4.  */
Packit 6c4009
Packit 6c4009
    ElfW(Addr) l_addr;		/* Difference between the address in the ELF
Packit 6c4009
				   file and the addresses in memory.  */
Packit 6c4009
    char *l_name;		/* Absolute file name object was found in.  */
Packit 6c4009
    ElfW(Dyn) *l_ld;		/* Dynamic section of the shared object.  */
Packit 6c4009
    struct link_map *l_next, *l_prev; /* Chain of loaded objects.  */
Packit 6c4009
Packit 6c4009
    /* All following members are internal to the dynamic linker.
Packit 6c4009
       They may change without notice.  */
Packit 6c4009
Packit 6c4009
    /* This is an element which is only ever different from a pointer to
Packit 6c4009
       the very same copy of this type for ld.so when it is used in more
Packit 6c4009
       than one namespace.  */
Packit 6c4009
    struct link_map *l_real;
Packit 6c4009
Packit 6c4009
    /* Number of the namespace this link map belongs to.  */
Packit 6c4009
    Lmid_t l_ns;
Packit 6c4009
Packit 6c4009
    struct libname_list *l_libname;
Packit 6c4009
    /* Indexed pointers to dynamic section.
Packit 6c4009
       [0,DT_NUM) are indexed by the processor-independent tags.
Packit 6c4009
       [DT_NUM,DT_NUM+DT_THISPROCNUM) are indexed by the tag minus DT_LOPROC.
Packit 6c4009
       [DT_NUM+DT_THISPROCNUM,DT_NUM+DT_THISPROCNUM+DT_VERSIONTAGNUM) are
Packit 6c4009
       indexed by DT_VERSIONTAGIDX(tagvalue).
Packit 6c4009
       [DT_NUM+DT_THISPROCNUM+DT_VERSIONTAGNUM,
Packit 6c4009
	DT_NUM+DT_THISPROCNUM+DT_VERSIONTAGNUM+DT_EXTRANUM) are indexed by
Packit 6c4009
       DT_EXTRATAGIDX(tagvalue).
Packit 6c4009
       [DT_NUM+DT_THISPROCNUM+DT_VERSIONTAGNUM+DT_EXTRANUM,
Packit 6c4009
	DT_NUM+DT_THISPROCNUM+DT_VERSIONTAGNUM+DT_EXTRANUM+DT_VALNUM) are
Packit 6c4009
       indexed by DT_VALTAGIDX(tagvalue) and
Packit 6c4009
       [DT_NUM+DT_THISPROCNUM+DT_VERSIONTAGNUM+DT_EXTRANUM+DT_VALNUM,
Packit 6c4009
	DT_NUM+DT_THISPROCNUM+DT_VERSIONTAGNUM+DT_EXTRANUM+DT_VALNUM+DT_ADDRNUM)
Packit 6c4009
       are indexed by DT_ADDRTAGIDX(tagvalue), see <elf.h>.  */
Packit 6c4009
Packit 6c4009
    ElfW(Dyn) *l_info[DT_NUM + DT_THISPROCNUM + DT_VERSIONTAGNUM
Packit 6c4009
		      + DT_EXTRANUM + DT_VALNUM + DT_ADDRNUM];
Packit 6c4009
    const ElfW(Phdr) *l_phdr;	/* Pointer to program header table in core.  */
Packit 6c4009
    ElfW(Addr) l_entry;		/* Entry point location.  */
Packit 6c4009
    ElfW(Half) l_phnum;		/* Number of program header entries.  */
Packit 6c4009
    ElfW(Half) l_ldnum;		/* Number of dynamic segment entries.  */
Packit 6c4009
Packit 6c4009
    /* Array of DT_NEEDED dependencies and their dependencies, in
Packit 6c4009
       dependency order for symbol lookup (with and without
Packit 6c4009
       duplicates).  There is no entry before the dependencies have
Packit 6c4009
       been loaded.  */
Packit 6c4009
    struct r_scope_elem l_searchlist;
Packit 6c4009
Packit 6c4009
    /* We need a special searchlist to process objects marked with
Packit 6c4009
       DT_SYMBOLIC.  */
Packit 6c4009
    struct r_scope_elem l_symbolic_searchlist;
Packit 6c4009
Packit 6c4009
    /* Dependent object that first caused this object to be loaded.  */
Packit 6c4009
    struct link_map *l_loader;
Packit 6c4009
Packit 6c4009
    /* Array with version names.  */
Packit 6c4009
    struct r_found_version *l_versions;
Packit 6c4009
    unsigned int l_nversions;
Packit 6c4009
Packit 6c4009
    /* Symbol hash table.  */
Packit 6c4009
    Elf_Symndx l_nbuckets;
Packit 6c4009
    Elf32_Word l_gnu_bitmask_idxbits;
Packit 6c4009
    Elf32_Word l_gnu_shift;
Packit 6c4009
    const ElfW(Addr) *l_gnu_bitmask;
Packit 6c4009
    union
Packit 6c4009
    {
Packit 6c4009
      const Elf32_Word *l_gnu_buckets;
Packit 6c4009
      const Elf_Symndx *l_chain;
Packit 6c4009
    };
Packit 6c4009
    union
Packit 6c4009
    {
Packit 6c4009
      const Elf32_Word *l_gnu_chain_zero;
Packit 6c4009
      const Elf_Symndx *l_buckets;
Packit 6c4009
    };
Packit 6c4009
Packit 6c4009
    unsigned int l_direct_opencount; /* Reference count for dlopen/dlclose.  */
Packit 6c4009
    enum			/* Where this object came from.  */
Packit 6c4009
      {
Packit 6c4009
	lt_executable,		/* The main executable program.  */
Packit 6c4009
	lt_library,		/* Library needed by main executable.  */
Packit 6c4009
	lt_loaded		/* Extra run-time loaded shared object.  */
Packit 6c4009
      } l_type:2;
Packit 6c4009
    unsigned int l_relocated:1;	/* Nonzero if object's relocations done.  */
Packit 6c4009
    unsigned int l_init_called:1; /* Nonzero if DT_INIT function called.  */
Packit 6c4009
    unsigned int l_global:1;	/* Nonzero if object in _dl_global_scope.  */
Packit 6c4009
    unsigned int l_reserved:2;	/* Reserved for internal use.  */
Packit 6c4009
    unsigned int l_phdr_allocated:1; /* Nonzero if the data structure pointed
Packit 6c4009
					to by `l_phdr' is allocated.  */
Packit 6c4009
    unsigned int l_soname_added:1; /* Nonzero if the SONAME is for sure in
Packit 6c4009
				      the l_libname list.  */
Packit 6c4009
    unsigned int l_faked:1;	/* Nonzero if this is a faked descriptor
Packit 6c4009
				   without associated file.  */
Packit 6c4009
    unsigned int l_need_tls_init:1; /* Nonzero if GL(dl_init_static_tls)
Packit 6c4009
				       should be called on this link map
Packit 6c4009
				       when relocation finishes.  */
Packit 6c4009
    unsigned int l_auditing:1;	/* Nonzero if the DSO is used in auditing.  */
Packit 6c4009
    unsigned int l_audit_any_plt:1; /* Nonzero if at least one audit module
Packit 6c4009
				       is interested in the PLT interception.*/
Packit 6c4009
    unsigned int l_removed:1;	/* Nozero if the object cannot be used anymore
Packit 6c4009
				   since it is removed.  */
Packit 6c4009
    unsigned int l_contiguous:1; /* Nonzero if inter-segment holes are
Packit 6c4009
				    mprotected or if no holes are present at
Packit 6c4009
				    all.  */
Packit 6c4009
    unsigned int l_symbolic_in_local_scope:1; /* Nonzero if l_local_scope
Packit 6c4009
						 during LD_TRACE_PRELINKING=1
Packit 6c4009
						 contains any DT_SYMBOLIC
Packit 6c4009
						 libraries.  */
Packit 6c4009
    unsigned int l_free_initfini:1; /* Nonzero if l_initfini can be
Packit 6c4009
				       freed, ie. not allocated with
Packit 6c4009
				       the dummy malloc in ld.so.  */
Packit 6c4009
Packit 6c4009
#include <link_map.h>
Packit 6c4009
Packit 6c4009
    /* Collected information about own RPATH directories.  */
Packit 6c4009
    struct r_search_path_struct l_rpath_dirs;
Packit 6c4009
Packit 6c4009
    /* Collected results of relocation while profiling.  */
Packit 6c4009
    struct reloc_result
Packit 6c4009
    {
Packit 6c4009
      DL_FIXUP_VALUE_TYPE addr;
Packit 6c4009
      struct link_map *bound;
Packit 6c4009
      unsigned int boundndx;
Packit 6c4009
      uint32_t enterexit;
Packit 6c4009
      unsigned int flags;
Packit 6c4009
    } *l_reloc_result;
Packit 6c4009
Packit 6c4009
    /* Pointer to the version information if available.  */
Packit 6c4009
    ElfW(Versym) *l_versyms;
Packit 6c4009
Packit 6c4009
    /* String specifying the path where this object was found.  */
Packit 6c4009
    const char *l_origin;
Packit 6c4009
Packit 6c4009
    /* Start and finish of memory map for this object.  l_map_start
Packit 6c4009
       need not be the same as l_addr.  */
Packit 6c4009
    ElfW(Addr) l_map_start, l_map_end;
Packit 6c4009
    /* End of the executable part of the mapping.  */
Packit 6c4009
    ElfW(Addr) l_text_end;
Packit 6c4009
Packit 6c4009
    /* Default array for 'l_scope'.  */
Packit 6c4009
    struct r_scope_elem *l_scope_mem[4];
Packit 6c4009
    /* Size of array allocated for 'l_scope'.  */
Packit 6c4009
    size_t l_scope_max;
Packit 6c4009
    /* This is an array defining the lookup scope for this link map.
Packit 6c4009
       There are initially at most three different scope lists.  */
Packit 6c4009
    struct r_scope_elem **l_scope;
Packit 6c4009
Packit 6c4009
    /* A similar array, this time only with the local scope.  This is
Packit 6c4009
       used occasionally.  */
Packit 6c4009
    struct r_scope_elem *l_local_scope[2];
Packit 6c4009
Packit 6c4009
    /* This information is kept to check for sure whether a shared
Packit 6c4009
       object is the same as one already loaded.  */
Packit 6c4009
    struct r_file_id l_file_id;
Packit 6c4009
Packit 6c4009
    /* Collected information about own RUNPATH directories.  */
Packit 6c4009
    struct r_search_path_struct l_runpath_dirs;
Packit 6c4009
Packit 6c4009
    /* List of object in order of the init and fini calls.  */
Packit 6c4009
    struct link_map **l_initfini;
Packit 6c4009
Packit 6c4009
    /* List of the dependencies introduced through symbol binding.  */
Packit 6c4009
    struct link_map_reldeps
Packit 6c4009
      {
Packit 6c4009
	unsigned int act;
Packit 6c4009
	struct link_map *list[];
Packit 6c4009
      } *l_reldeps;
Packit 6c4009
    unsigned int l_reldepsmax;
Packit 6c4009
Packit 6c4009
    /* Nonzero if the DSO is used.  */
Packit 6c4009
    unsigned int l_used;
Packit 6c4009
Packit 6c4009
    /* Various flag words.  */
Packit 6c4009
    ElfW(Word) l_feature_1;
Packit 6c4009
    ElfW(Word) l_flags_1;
Packit 6c4009
    ElfW(Word) l_flags;
Packit 6c4009
Packit 6c4009
    /* Temporarily used in `dl_close'.  */
Packit 6c4009
    int l_idx;
Packit 6c4009
Packit 6c4009
    struct link_map_machine l_mach;
Packit 6c4009
Packit 6c4009
    struct
Packit 6c4009
    {
Packit 6c4009
      const ElfW(Sym) *sym;
Packit 6c4009
      int type_class;
Packit 6c4009
      struct link_map *value;
Packit 6c4009
      const ElfW(Sym) *ret;
Packit 6c4009
    } l_lookup_cache;
Packit 6c4009
Packit 6c4009
    /* Thread-local storage related info.  */
Packit 6c4009
Packit 6c4009
    /* Start of the initialization image.  */
Packit 6c4009
    void *l_tls_initimage;
Packit 6c4009
    /* Size of the initialization image.  */
Packit 6c4009
    size_t l_tls_initimage_size;
Packit 6c4009
    /* Size of the TLS block.  */
Packit 6c4009
    size_t l_tls_blocksize;
Packit 6c4009
    /* Alignment requirement of the TLS block.  */
Packit 6c4009
    size_t l_tls_align;
Packit 6c4009
    /* Offset of first byte module alignment.  */
Packit 6c4009
    size_t l_tls_firstbyte_offset;
Packit 6c4009
#ifndef NO_TLS_OFFSET
Packit 6c4009
# define NO_TLS_OFFSET	0
Packit 6c4009
#endif
Packit 6c4009
#ifndef FORCED_DYNAMIC_TLS_OFFSET
Packit 6c4009
# if NO_TLS_OFFSET == 0
Packit 6c4009
#  define FORCED_DYNAMIC_TLS_OFFSET -1
Packit 6c4009
# elif NO_TLS_OFFSET == -1
Packit 6c4009
#  define FORCED_DYNAMIC_TLS_OFFSET -2
Packit 6c4009
# else
Packit 6c4009
#  error "FORCED_DYNAMIC_TLS_OFFSET is not defined"
Packit 6c4009
# endif
Packit 6c4009
#endif
Packit 6c4009
    /* For objects present at startup time: offset in the static TLS block.  */
Packit 6c4009
    ptrdiff_t l_tls_offset;
Packit 6c4009
    /* Index of the module in the dtv array.  */
Packit 6c4009
    size_t l_tls_modid;
Packit 6c4009
Packit 6c4009
    /* Number of thread_local objects constructed by this DSO.  This is
Packit 6c4009
       atomically accessed and modified and is not always protected by the load
Packit 6c4009
       lock.  See also: CONCURRENCY NOTES in cxa_thread_atexit_impl.c.  */
Packit 6c4009
    size_t l_tls_dtor_count;
Packit 6c4009
Packit 6c4009
    /* Information used to change permission after the relocations are
Packit 6c4009
       done.  */
Packit 6c4009
    ElfW(Addr) l_relro_addr;
Packit 6c4009
    size_t l_relro_size;
Packit 6c4009
Packit 6c4009
    unsigned long long int l_serial;
Packit 6c4009
Packit 6c4009
    /* Audit information.  This array apparent must be the last in the
Packit 6c4009
       structure.  Never add something after it.  */
Packit 6c4009
    struct auditstate
Packit 6c4009
    {
Packit 6c4009
      uintptr_t cookie;
Packit 6c4009
      unsigned int bindflags;
Packit 6c4009
    } l_audit[0];
Packit 6c4009
  };
Packit 6c4009
Packit 6c4009
Packit 6c4009
#if __ELF_NATIVE_CLASS == 32
Packit 6c4009
# define symbind symbind32
Packit 6c4009
#elif __ELF_NATIVE_CLASS == 64
Packit 6c4009
# define symbind symbind64
Packit 6c4009
#else
Packit 6c4009
# error "__ELF_NATIVE_CLASS must be defined"
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
extern int __dl_iterate_phdr (int (*callback) (struct dl_phdr_info *info,
Packit 6c4009
					       size_t size, void *data),
Packit 6c4009
			      void *data);
Packit 6c4009
hidden_proto (__dl_iterate_phdr)
Packit 6c4009
Packit 6c4009
/* We use this macro to refer to ELF macros independent of the native
Packit 6c4009
   wordsize.  `ELFW(R_TYPE)' is used in place of `ELF32_R_TYPE' or
Packit 6c4009
   `ELF64_R_TYPE'.  */
Packit 6c4009
#define ELFW(type)	_ElfW (ELF, __ELF_NATIVE_CLASS, type)
Packit 6c4009
Packit 6c4009
# endif /* !_ISOMAC */
Packit 6c4009
#endif /* include/link.h */