FreeBSD/libexec/rtld-elf/rtld.c
/*
 * Find the library with the given name, and return its full pathname.
 * The returned string is dynamically allocated.  Generates an error
 * message and returns NULL if the library cannot be found.
 *
 * If the second argument is non-NULL, then it refers to an already-
 * loaded shared object, whose library search path will be searched.
 *
 * If a library is successfully located via LD_LIBRARY_PATH_FDS, its
 * descriptor (which is close-on-exec) will be passed out via the third
 * argument.
 *
 * The search order is:
 *   DT_RPATH in the referencing file _unless_ DT_RUNPATH is present (1)
 *   DT_RPATH of the main object if DSO without defined DT_RUNPATH (1)
 *   LD_LIBRARY_PATH
 *   DT_RUNPATH in the referencing file
 *   ldconfig hints (if -z nodefaultlib, filter out default library directories
 *	 from list)
 *   /lib:/usr/lib _unless_ the referencing file is linked with -z nodefaultlib
 *
 * (1) Handled in digest_dynamic2 - rpath left NULL if runpath defined.
 */
Find the library with the given name, and return its full pathname.
The returned string is dynamically allocated.  Generates an error
message and returns NULL if the library cannot be found.

If the second argument is non-NULL, then it refers to an already
loaded shared object, whose library search path will be searched.

If a library is successfully located via LD_LIBRARY_PATH_FDS, its
descriptor (which is close-on-exec) will be passed out via the third
argument.

The search order is:
DT_RPATH in the referencing file _unless_ DT_RUNPATH is present (1)
DT_RPATH of the main object if DSO without defined DT_RUNPATH (1)
LD_LIBRARY_PATH
DT_RUNPATH in the referencing file
ldconfig hints (if -z nodefaultlib, filter out default library directories
from list)
/lib:/usr/lib _unless_ the referencing file is linked with -z nodefaultlib

(1) Handled in digest_dynamic2 - rpath left NULL if runpath defined.
Find the library with the given name and return its full pathname . The returned string is dynamically allocated . Generates an error message and returns NULL if the library cannot be found . If the second argument is non - NULL then it refers to an already loaded shared object whose library search path will be searched . If a library is successfully located via LD_LIBRARY_PATH_FDS its descriptor ( which is close - on - exec ) will be passed out via the third argument . The search order is : DT_RPATH in the referencing file _unless_ DT_RUNPATH is present ( 1 ) DT_RPATH of the main object if DSO without defined DT_RUNPATH ( 1 ) LD_LIBRARY_PATH DT_RUNPATH in the referencing file ldconfig hints ( if - z nodefaultlib filter out default library directories from list ) / lib : / usr / lib _unless_ the referencing file is linked with - z nodefaultlib ( 1 ) Handled in digest_dynamic2 - rpath left NULL if runpath defined .
static char *
find_library(const char *xname, const Obj_Entry *refobj, int *fdp)
{
    char *pathname;
    char *name;
    bool nodeflib, objgiven;
    objgiven = refobj != NULL;
    if (strchr(xname, '/') != NULL) {	
	if (xname[0] != '/' && !trust) {
	    _rtld_error("Absolute pathname required for shared object \"%s\"",
	      xname);
	    return NULL;
	}
	return (origin_subst(__DECONST(Obj_Entry *, refobj),
	  __DECONST(char *, xname)));
    }
    if (libmap_disable || !objgiven ||
	(name = lm_find(refobj->path, xname)) == NULL)
	name = (char *)xname;
    dbg(" Searching for \"%s\"", name);
    if (objgiven && refobj->rpath != NULL && ld_library_path_rpath) {
	if ((pathname = search_library_path(name, ld_library_path)) != NULL ||
	  (refobj != NULL &&
	  (pathname = search_library_path(name, refobj->rpath)) != NULL) ||
	  (pathname = search_library_pathfds(name, ld_library_dirs, fdp)) != NULL ||
          (pathname = search_library_path(name, gethints(false))) != NULL ||
	  (pathname = search_library_path(name, ld_standard_library_path)) != NULL)
	    return (pathname);
    } else {
	nodeflib = objgiven ? refobj->z_nodeflib : false;
	if ((objgiven &&
	  (pathname = search_library_path(name, refobj->rpath)) != NULL) ||
	  (objgiven && refobj->runpath == NULL && refobj != obj_main &&
	  (pathname = search_library_path(name, obj_main->rpath)) != NULL) ||
	  (pathname = search_library_path(name, ld_library_path)) != NULL ||
	  (objgiven &&
	  (pathname = search_library_path(name, refobj->runpath)) != NULL) ||
	  (pathname = search_library_pathfds(name, ld_library_dirs, fdp)) != NULL ||
	  (pathname = search_library_path(name, gethints(nodeflib))) != NULL ||
	  (objgiven && !nodeflib &&
	  (pathname = search_library_path(name, ld_standard_library_path)) != NULL))
	    return (pathname);
    }
    if (objgiven && refobj->path != NULL) {
	_rtld_error("Shared object \"%s\" not found, required by \"%s\"",
	  name, basename(refobj->path));
    } else {
	_rtld_error("Shared object \"%s\" not found", name);
    }
    return NULL;
}
static char * find_library ( const char * xname , const Obj_Entry * refobj , int * fdp ) { char * pathname ; char * name ; bool nodeflib , objgiven ; objgiven = refobj != NULL ; if ( strchr ( xname , ' ' ) != NULL ) { if ( xname [ 0 ] != ' ' && ! trust ) { _rtld_error ( " \" \" " , xname ) ; return NULL ; } return ( origin_subst ( __DECONST ( Obj_Entry * , refobj ) , __DECONST ( char * , xname ) ) ) ; } if ( libmap_disable || ! objgiven || ( name = lm_find ( refobj -> path , xname ) ) == NULL ) name = ( char * ) xname ; dbg ( " \" \" " , name ) ; if ( objgiven && refobj -> rpath != NULL && ld_library_path_rpath ) { if ( ( pathname = search_library_path ( name , ld_library_path ) ) != NULL || ( refobj != NULL && ( pathname = search_library_path ( name , refobj -> rpath ) ) != NULL ) || ( pathname = search_library_pathfds ( name , ld_library_dirs , fdp ) ) != NULL || ( pathname = search_library_path ( name , gethints ( false ) ) ) != NULL || ( pathname = search_library_path ( name , ld_standard_library_path ) ) != NULL ) return ( pathname ) ; } else { nodeflib = objgiven ? refobj -> z_nodeflib : false ; if ( ( objgiven && ( pathname = search_library_path ( name , refobj -> rpath ) ) != NULL ) || ( objgiven && refobj -> runpath == NULL && refobj != obj_main && ( pathname = search_library_path ( name , obj_main -> rpath ) ) != NULL ) || ( pathname = search_library_path ( name , ld_library_path ) ) != NULL || ( objgiven && ( pathname = search_library_path ( name , refobj -> runpath ) ) != NULL ) || ( pathname = search_library_pathfds ( name , ld_library_dirs , fdp ) ) != NULL || ( pathname = search_library_path ( name , gethints ( nodeflib ) ) ) != NULL || ( objgiven && ! nodeflib && ( pathname = search_library_path ( name , ld_standard_library_path ) ) != NULL ) ) return ( pathname ) ; } if ( objgiven && refobj -> path != NULL ) { _rtld_error ( " \" \" \" \" " , name , basename ( refobj -> path ) ) ; } else { _rtld_error ( " \" \" " , name ) ; } return NULL ; }
Find the library with the given name, and return its full pathname.
Find the library with the given name and return its full pathname .
/* Hard coded pathname */ /*
     * If refobj->rpath != NULL, then refobj->runpath is NULL.  Fall
     * back to pre-conforming behaviour if user requested so with
     * LD_LIBRARY_PATH_RPATH environment variable and ignore -z
     * nodeflib.
     */