(root: str = "/", prefix: str = "")
return ldpaths
Load linker paths from common locations

    This parses the ld.so.conf and LD_LIBRARY_PATH env var.

    Parameters
    ----------
    root
        The root tree to prepend to paths
    prefix
        The path under ``root`` to search

    Returns
    -------
    dict containing library paths to search
Load linker paths from common locations
Load linker paths from common locations
def load_ld_paths(root: str = "/", prefix: str = "") -> Dict[str, List[str]]:
    """Load linker paths from common locations

    This parses the ld.so.conf and LD_LIBRARY_PATH env var.

    Parameters
    ----------
    root
        The root tree to prepend to paths
    prefix
        The path under ``root`` to search

    Returns
    -------
    dict containing library paths to search
    """
    ldpaths = {"conf": [], "env": [], "interp": []}  # type: Dict

    # Load up $LD_LIBRARY_PATH.
    env_ldpath = os.environ.get("LD_LIBRARY_PATH")
    if env_ldpath is not None:
        if root != "/":
            log.warning("ignoring LD_LIBRARY_PATH due to ROOT usage")
        else:
            # XXX: If this contains $ORIGIN, we probably have to parse this
            # on a per-ELF basis so it can get turned into the right thing.
            ldpaths["env"] = parse_ld_paths(env_ldpath, path="")

    libc = get_libc()
    if libc == Libc.MUSL:
        # from https://git.musl-libc.org/cgit/musl/tree/ldso
        # /dynlink.c?id=3f701faace7addc75d16dea8a6cd769fa5b3f260#n1063
        root_prefix = Path(root) / prefix
        ld_musl = list((root_prefix / "etc").glob("ld-musl-*.path"))
        assert len(ld_musl) <= 1
        if len(ld_musl) == 0:
            ldpaths["conf"] = [
                root + "/lib",
                root + "/usr/local/lib",
                root + "/usr/lib",
            ]
        else:
            ldpaths["conf"] = []
            for ldpath in ld_musl[0].read_text().split(":"):
                ldpath_stripped = ldpath.strip()
                if ldpath_stripped == "":
                    continue
                ldpaths["conf"].append(root + ldpath_stripped)
    else:
        # Load up /etc/ld.so.conf.
        ldpaths["conf"] = parse_ld_so_conf(root + prefix + "/etc/ld.so.conf", root=root)
        # the trusted directories are not necessarily in ld.so.conf
        ldpaths["conf"].extend(["/lib", "/lib64/", "/usr/lib", "/usr/lib64"])
    log.debug("linker ldpaths: %s", ldpaths)
    return ldpaths
def load_ld_paths ( root : str = "/" , prefix : str = "" ) -> Dict [ str , List [ str ] ] : ldpaths = { "conf" : [ ] , "env" : [ ] , "interp" : [ ] } # type: Dict # Load up $LD_LIBRARY_PATH. env_ldpath = os . environ . get ( "LD_LIBRARY_PATH" ) if env_ldpath is not None : if root != "/" : log . warning ( "ignoring LD_LIBRARY_PATH due to ROOT usage" ) else : # XXX: If this contains $ORIGIN, we probably have to parse this # on a per-ELF basis so it can get turned into the right thing. ldpaths [ "env" ] = parse_ld_paths ( env_ldpath , path = "" ) libc = get_libc ( ) if libc == Libc . MUSL : # from https://git.musl-libc.org/cgit/musl/tree/ldso # /dynlink.c?id=3f701faace7addc75d16dea8a6cd769fa5b3f260#n1063 root_prefix = Path ( root ) / prefix ld_musl = list ( ( root_prefix / "etc" ) . glob ( "ld-musl-*.path" ) ) assert len ( ld_musl ) <= 1 if len ( ld_musl ) == 0 : ldpaths [ "conf" ] = [ root + "/lib" , root + "/usr/local/lib" , root + "/usr/lib" , ] else : ldpaths [ "conf" ] = [ ] for ldpath in ld_musl [ 0 ] . read_text ( ) . split ( ":" ) : ldpath_stripped = ldpath . strip ( ) if ldpath_stripped == "" : continue ldpaths [ "conf" ] . append ( root + ldpath_stripped ) else : # Load up /etc/ld.so.conf. ldpaths [ "conf" ] = parse_ld_so_conf ( root + prefix + "/etc/ld.so.conf" , root = root ) # the trusted directories are not necessarily in ld.so.conf ldpaths [ "conf" ] . extend ( [ "/lib" , "/lib64/" , "/usr/lib" , "/usr/lib64" ] ) log . debug ( "linker ldpaths: %s" , ldpaths ) return ldpaths