dlinfo(3c) 맨 페이지 - 윈디하나의 솔라나라

개요

섹션
맨 페이지 이름
검색(S)

dlinfo(3c)

Standard C Library Functions                                        dlinfo(3C)



NAME
       dlinfo - dynamic load information

SYNOPSIS
       #include <dlfcn.h>
       #include <link.h>
       #include <limits.h>
       #include <sys/mman.h>

       int dlinfo(void *handle, int request, void *p);

DESCRIPTION
       The  dlinfo()  function  sets  or extracts information from the runtime
       linker ld.so.1(1). This function is loosely modeled after the  ioctl(2)
       function. The request argument and a third argument of varying type are
       passed to dlinfo(). The action taken by dlinfo() depends on  the  value
       of the request that is provided.


       The  handle  argument  is  either  the  value  that  is returned from a
       dlopen(3C) or dlmopen() call, or the special handle RTLD_SELF. A handle
       argument  is  required  for  all requests except RTLD_DI_GETSIGNAL, and
       RTLD_DI_SETSIGNAL. If handle is the  value  that  is  returned  from  a
       dlopen()  or  dlmopen()  call, the information returned by the dlinfo()
       call pertains to the specified object. If handle is the special  handle
       RTLD_SELF,  the  information  returned by the dlinfo() call pertains to
       the caller.


       The request argument can take the following values:

       RTLD_DI_ARGSINFO

           Obtain process argument information. The p argument  is  a  pointer
           (Dl_argsinfo_t  *p). The following elements from this structure are
           initialized:


           dla_argc    The number of arguments passed to the process.


           dla_argv    The argument array passed to the process.


           dla_envp    The active environment variable array that is available
                       to  the  process.  This element initially points to the
                       environment variable array that is  made  available  to
                       exec(2). This element can be updated should an alterna‐
                       tive environment be established  by  the  process.  See
                       putenv(3C).


           dla_auxv    The auxiliary vector array passed to the process.

           A  process  can  be  established  from executing the runtime linker
           directly from the command line. See ld.so.1(1).  The  Dl_argsinfo_t
           information  reflects the information that is made available to the
           application regardless of how the runtime linker has been invoked.


       RTLD_DI_LINKMAP

           Obtain the Link_map for the handle that is specified. The  p  argu‐
           ment  points to a Link_map pointer (Link_map **p). The actual stor‐
           age for the Link_map structure is maintained by ld.so.1.

           The Link_map structure includes the following members:

             unsigned long l_addr;      /* base address */
             char          *l_name;     /* object name */
             Elf32_Dyn     *l_ld;       /* .dynamic section */
             Link_map      *l_next;     /* next link object */
             Link_map      *l_prev;     /* previous link object */
             char          *l_refname;  /* filter reference name */


           l_addr       The base address of the object loaded into memory.


           l_name       The full name of the loaded object. This full name  is
                        the filename of the object as referenced by ld.so.1.


           l_ld         Points to the SHT_DYNAMIC structure.


           l_next       The  next Link_map on the link-map list. Other objects
                        on the same link-map list as the current object can be
                        examined by following the l_next and l_prev members.


           l_prev       The previous Link_map on the link-map list.


           l_refname    If  the  object  that  is referenced is a filter, this
                        member points to the name of  the  object  being  fil‐
                        tered.  If  the object is not a filter, this member is
                        0. See Shared Objects as  Filters  in  Oracle  Solaris
                        11.4 Linkers and Libraries Guide.



       RTLD_DI_LMID

           Obtain  the  ID  for  the  link-map  list  upon which the handle is
           loaded. The p argument is a Lmid_t pointer (Lmid_t *p).


       RTLD_DI_MMAPCNT

           Determine the number of segment mappings for  the  handle  that  is
           specified,  for use in a RTLD_DI_MMAPS request. The p argument is a
           uint_t pointer  (uint_t  *p).  On  return  from  a  RTLD_DI_MMAPCNT
           request, the uint_t value that is pointed to by p contains the num‐
           ber of segment mappings that the associated object uses.

           To obtain  the  complete  mapping  information  for  an  object,  a
           mmapobj_result_t  array  for  RTLD_DI_MMAPCNT  entries must be pro‐
           vided. This array is assigned to the dlm_maps member, and the  num‐
           ber  of entries available in the array are assigned to the dlm_acnt
           member.  This  initialized  structure   is   then   passed   to   a
           RTLD_DI_MMAPS request. See EXAMPLES.


       RTLD_DI_MMAPS

           Obtain  segment  mapping  information for the handle that is speci‐
           fied. The p argument is a Dl_mapinfo_t pointer  (Dl_mapinfo_t  *p).
           This  structure  can be initialized from the mapping count obtained
           from a previous RTLD_DI_MMAPCNT request.

           Segment  mapping  information  is   provided   in   an   array   of
           mmapobj_result_t  structures  that originate from the mmapobj(2) of
           the associated object. The dlm_acnt member,  typically  initialized
           from  a  previous  RTLD_DI_MMAPCNT request, indicates the number of
           entries in a mmapobj_result_t array. This array is assigned to  the
           dlm_maps  member.  This  initialized  structure is then passed to a
           RTLD_DI_MMAPS request, where the  segment  mapping  information  is
           copied to the mmapobj_result_t array. The dlm_rcnt member indicates
           the number of mmapobj_result_t element entries that  are  returned.
           See EXAMPLES.


       RTLD_DI_SERINFO

           Obtain  the  library search paths for the handle that is specified.
           The p argument is a Dl_serinfo_t pointer (Dl_serinfo_t *p). A  user
           must   first   initialize   the   Dl_serinfo_t   structure  with  a
           RTLD_DI_SERINFOSIZE request. See EXAMPLES.

           The returned Dl_serinfo_t structure contains dls_cnt   Dl_serpath_t
           entries.  Each  entry's  dlp_name member points to the search path.
           The corresponding dlp_info member contains one of more flags  indi‐
           cating  the  origin  of  the  path. See the LA_SER_* flags that are
           defined in <link.h>.


       RTLD_DI_SERINFOSIZE

           Initialize a Dl_serinfo_t structure for the handle that  is  speci‐
           fied,  for  use  in a RTLD_DI_SERINFO request. Both the dls_cnt and
           dls_size members are returned. The  dls_cnt  member  indicates  the
           number  of  search  paths  that  are  applicable to the handle. The
           dls_size member indicates the total size of a  Dl_serinfo_t  buffer
           required  to  hold dls_cnt  Dl_serpath_t entries and the associated
           search path strings. The  p  argument  is  a  Dl_serinfo_t  pointer
           (Dl_serinfo_t *p).

           To  obtain the complete path information, a new Dl_serinfo_t buffer
           of size dls_size should be allocated. This  new  buffer  should  be
           initialized  with the dls_cnt and dls_size entries. The initialized
           buffer is then passed to a RTLD_DI_SERINFO request. See EXAMPLES.


       RTLD_DI_ORIGIN

           Obtain the origin of the dynamic object that is associated with the
           handle. The p argument is a char pointer (char *p). The dirname(3C)
           of the associated object's realpath(3C), which  can  be  no  larger
           than {PATH_MAX}, is copied to the pointer p.


       RTLD_DI_GETSIGNAL

           Obtain the numeric signal number used by the runtime linker to kill
           the process in the event of a fatal runtime error. The  p  argument
           is  an  int  pointer  (int  *p). The signal number is copied to the
           pointer p.

           By default, the signal used by the runtime linker  to  terminate  a
           process  is  SIGKILL. See thr_kill(3C). This default can be changed
           by calling dlinfo() with RTLD_DI_SETSIGNAL or by setting the  envi‐
           ronment variable LD_SIGNAL. See ld.so.1(1).


       RTLD_DI_SETSIGNAL

           Provide  a numeric signal number used by the runtime linker to kill
           the process in the event of a fatal runtime error. The  p  argument
           is  an  int  pointer  (int *p). The value pointed to by p is estab‐
           lished as the terminating signal value.

           The current signal number used by the runtime linker to terminate a
           process  can be obtained from dlinfo() using RTLD_DI_GETSIGNAL. Use
           of the RTLD_DI_SETSIGNAL option is equivalent to setting the  envi‐
           ronment variable LD_SIGNAL. See ld.so.1(1).


       RTLD_DI_DEFERRED

           Assign  a  new  dependency name to an existing deferred dependency.
           The p argument is  a  Dl_definfo_t  pointer  (Dl_definfo  *p).  The
           dlv_refname field defines an existing dependency name. The dlv_dep‐
           name field defines the new dependency name.

           Dependency names are defined by DT_NEEDED  dynamic  entries,  which
           can  be  displayed  using  the  -d option of elfdump(1). Individual
           dependencies can be tagged as deferred. See the -z  deferred option
           of ld(1). Deferred dependencies are only loaded during process exe‐
           cution, when the first binding to a  deferred  reference  is  made.
           Prior  to  a  deferred dependency being loaded, the dependency name
           can    be    changed    with     RTLD_DI_DEFERRED.     See     also
           RTLD_DI_DEFERRED_SYM.

           Once  a  deferred  dependency  is loaded, any attempt to change the
           dependency name with dlinfo() results in an error return of −1.


       RTLD_DI_DEFERRED_SYM

           Assign a new dependency name to an existing deferred symbol,  using
           a symbol reference that exists to the dependency. The p argument is
           a Dl_definfo_t  pointer  (Dl_definfo  *p).  The  dlv_refname  field
           defines a symbol reference to the deferred dependency. The dlv_dep‐
           name field defines the new dependency name.

           RTLD_DI_DEFERRED_SYM provides an alternative means of  modifying  a
           deferred  dependency to using RTLD_DI_DEFERRED. One, or more symbol
           references  can  be  associated   with   a   deferred   dependency.
           RTLD_DI_DEFERRED_SYM allows one of these deferred symbol references
           to be used to select the associated deferred dependency. Prior to a
           deferred  dependency  being  loaded,  the  dependency  name  can be
           changed with RTLD_DI_DEFERRED_SYM. See EXAMPLES.

           Once a deferred dependency is loaded, any  attempt  to  change  the
           dependency name with dlinfo() results in an error return of −1.


       RTLD_DI_TLS_MODID

           Obtain  the  TLS  (thread-local  storage)  module ID of the dynamic
           object that is associated with the handle. If the object  does  not
           define  a  TLS  segment,  0 is returned. The p argument is a size_t
           pointer (size_t *p).


       RTLD_DI_TLS_DATA

           Obtain the address of the calling thread's TLS (thread-local  stor‐
           age)  block for the dynamic object that is associated with the han‐
           dle. If the object does not define a TLS segment, or if the  thread
           has  not yet allocated the TLS block, NULL is returned. The p argu‐
           ment is a void * pointer (void **p).


RETURN VALUES
       The dlinfo() function returns −1 if the request is invalid, the parame‐
       ter  p  is  NULL,  or the Dl_serinfo_t structure is uninitialized for a
       RTLD_DI_SERINFO request. dlinfo() also returns −1 if the  handle  argu‐
       ment does not refer to a valid object opened by dlopen(), or is not the
       special handle RTLD_SELF. Detailed diagnostic information is  available
       with dlerror(3C).

EXAMPLES
       Example 1 Use dlinfo() to obtain library search paths.



       The following example demonstrates how a dynamic object can inspect the
       library search paths that would be used to  locate  a  simple  filename
       with dlopen(). For simplicity, error checking has been omitted.


         Dl_serinfo_t   _info, *info = &_info;
         Dl_serpath_t   *path;
         uint_t         cnt;

         /* determine search path count and required buffer size */
         dlinfo(RTLD_SELF, RTLD_DI_SERINFOSIZE, info);

         /* allocate new buffer and initialize */
         info = malloc(_info.dls_size);
         info->dls_size = _info.dls_size;
         info->dls_cnt = _info.dls_cnt;

         /* obtain search path information */
         dlinfo(RTLD_SELF, RTLD_DI_SERINFO, info);

         path = &info->dls_serpath[0];

         for (cnt = 1; cnt <= info->dls_cnt; cnt++, path++) {
             (void) printf("%2d: %s\n", cnt, path->dls_name);
         }


       Example 2 Use dlinfo() to obtain segment information.



       The following example demonstrates how a dynamic object can inspect its
       segment mapping information. For simplicity, error  checking  has  been
       omitted


         Dl_mapinfo_t   mi;
         uint_t         cnt;

         /* determine the number of segment mappings */
         dlinfo(RTLD_SELF, RTLD_DI_MMAPCNT, &mi.dlm_acnt);

         /* allocate the appropriate mapping array */
         mi.dlm_maps = malloc(mi.dlm_acnt *
             sizeof (mmapobj_result_t));

         /* obtain the mapping information */
         dlinfo(RTLD_SELF, RTLD_DI_MMAPS, &mi);

         for (cnt = 0; cnt < mi.dlm_rcnt; cnt++) {
             (void) printf("addr=%x - memory size=%x\n",
                 mi.dlm_maps[cnt].mr_addr,
                 mi.dlm_maps[cnt].mr_msize);
         }


       Example 3 Use dlinfo() to change a deferred dependency.



       The  following  program  defines  a deferred dependency, foo.so, and an
       associated deferred symbol reference, foo().


         $ elfdump -d main | egrep "NEEDED|POSFLAG
             [0]  POSFLAG_1       0x5            [ LAZY DEFERRED ]
             [1]  NEEDED          0x17e          foo.so
         $ elfdump -y main | fgrep foo
             [12]  DBLP           [1] foo.so     foo




       The program probes the existence of the symbol foo() to verify that  an
       associated  deferred  dependency  exists.  If  the  dependency does not
       exist, and hence the symbol can not be found, the program exchanges the
       deferred  dependency  associated  with  the symbol for a new dependency
       named bar.so. Following this exchange, the program once more probes for
       the existence of the symbol foo() to verify that the new dependency can
       be loaded, and the symbol can be found.

         if (dlsym(RTLD_PROBE, "foo") == NULL) {
             Dl_definfo_t    info;

             info.dld_refname = "foo";
             info.dld_depname = "bar.so";

             if (dlinfo(RTLD_SELF, RTLD_DI_DEFERRED_SYM,
                 &info) == -1)
                     return (1);
             if (dlsym(RTLD_PROBE, "foo") == NULL)
                     return (1);
         }
         foo();



       A deferred dependency can only be exchanged before  the  dependency  is
       loaded. If the dependency exists, then any probe would cause the depen‐
       dency to be loaded, and any following exchange attempts would fail.  To
       successfully  exchange a deferred dependency that is expected to exist,
       a program must not probe for the symbol before making the exchange.

         Dl_definfo_t    info;

         info.dld_refname = "foo";
         info.dld_depname = "bar.so";

         if (dlinfo(RTLD_SELF, RTLD_DI_DEFERRED_SYM, &info) == -1)
             (void) printf("Using original dependency\n");
         else
             (void) printf("Using new dependency: bar.so\n");


USAGE
       The dlinfo() function is one of a family of  functions  that  give  the
       user  direct access to the dynamic linking facilities. These facilities
       are available to dynamically-linked  processes  only.  See  the  Oracle
       Solaris 11.4 Linkers and Libraries Guide.

ATTRIBUTES
       See attributes(7) for descriptions of the following attributes:


       tab()  box; cw(2.75i) |cw(2.75i) lw(2.75i) |lw(2.75i) ATTRIBUTE TYPEAT‐
       TRIBUTE VALUE _ Interface StabilityCommitted _ MT-LevelMT-Safe


SEE ALSO
       elfdump(1),   ld(1),   ld.so.1(1),   exec(2),   ioctl(2),   mmapobj(2),
       dirname(3C), dl_iterate_phdr(3C), dlclose(3C), dldump(3C), dlerror(3C),
       dlopen(3C),   dlsym(3C),   putenv(3C),   realpath(3C),    thr_kill(3C),
       attributes(7).


       Oracle Solaris 11.4 Linkers and Libraries Guide



Oracle Solaris 11.4               23 Jul 2020                       dlinfo(3C)
맨 페이지 내용의 저작권은 맨 페이지 작성자에게 있습니다.
RSS ATOM XHTML 5 CSS3