1 From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2 From: Moritz Sanft <58110325+msanft@users.noreply.github.com>
3 Date: Fri, 20 Dec 2024 16:34:50 +0100
4 Subject: [PATCH] ldcache: don't use ldcache
6 This patch hinders libnvidia-container from using the loader cache, which doesn't get used on NixOS.
8 src/ldcache.c | 46 +++++++++++++++++-----------------------------
10 src/nvc_info.c | 8 ++------
11 src/nvc_ldcache.c | 2 +-
12 4 files changed, 21 insertions(+), 37 deletions(-)
14 diff --git a/src/ldcache.c b/src/ldcache.c
15 index 38bab0553208f66b2866ccea6cdb0faca4357f19..1c4acd52b622be4ca6accdc80da5a6fcf9ae67dd 100644
18 @@ -108,40 +108,28 @@ ldcache_close(struct ldcache *ctx)
21 ldcache_resolve(struct ldcache *ctx, uint32_t arch, const char *root, const char * const libs[],
22 - char *paths[], size_t size, ldcache_select_fn select, void *select_ctx)
23 + char *paths[], size_t size, const char* version)
26 - struct header_libc6 *h;
31 - h = (struct header_libc6 *)ctx->ptr;
32 memset(paths, 0, size * sizeof(*paths));
34 - for (uint32_t i = 0; i < h->nlibs; ++i) {
35 - int32_t flags = h->libs[i].flags;
36 - char *key = (char *)ctx->ptr + h->libs[i].key;
37 - char *value = (char *)ctx->ptr + h->libs[i].value;
39 - if (!(flags & LD_ELF) || (flags & LD_ARCH_MASK) != arch)
42 - for (size_t j = 0; j < size; ++j) {
43 - if (!str_has_prefix(key, libs[j]))
45 - if (path_resolve(ctx->err, path, root, value) < 0)
47 - if (paths[j] != NULL && str_equal(paths[j], path))
49 - if ((override = select(ctx->err, select_ctx, root, paths[j], path)) < 0)
53 - paths[j] = xstrdup(ctx->err, path);
54 - if (paths[j] == NULL)
59 + for (size_t j = 0; j < size; ++j) {
60 + snprintf(dir, 100, "@driverLink@/lib");
62 + if (!strncmp(libs[j], "libvdpau_nvidia.so", 100))
63 + strcat(dir, "/vdpau");
64 + snprintf(lib, 100, "%s/%s.%s", dir, libs[j], version);
65 + if (path_resolve_full(ctx->err, path, "/", lib) < 0)
67 + if (!file_exists(ctx->err, path))
70 + paths[j] = xstrdup(ctx->err, path);
71 + if (paths[j] == NULL)
76 diff --git a/src/ldcache.h b/src/ldcache.h
77 index 33d78dd7e21f65eb696535c115bbd2839a6c67ca..2b087dbca1a6a2946cd495e676a61e956212e3dc 100644
80 @@ -50,6 +50,6 @@ void ldcache_init(struct ldcache *, struct error *, const char *);
81 int ldcache_open(struct ldcache *);
82 int ldcache_close(struct ldcache *);
83 int ldcache_resolve(struct ldcache *, uint32_t, const char *, const char * const [],
84 - char *[], size_t, ldcache_select_fn, void *);
85 + char *[], size_t, const char*);
87 #endif /* HEADER_LDCACHE_H */
88 diff --git a/src/nvc_info.c b/src/nvc_info.c
89 index b7b8adfa7c79c326a1acb481a06a05d1463e810f..cf4b1905fd2127c28ee16649501be122d3be5261 100644
92 @@ -217,15 +217,13 @@ find_library_paths(struct error *err, struct dxcore_context *dxcore, struct nvc_
93 if (path_resolve_full(err, path, root, ldcache) < 0)
95 ldcache_init(&ld, err, path);
96 - if (ldcache_open(&ld) < 0)
100 info->libs = array_new(err, size);
101 if (info->libs == NULL)
103 if (ldcache_resolve(&ld, LIB_ARCH, root, libs,
104 - info->libs, info->nlibs, select_libraries_fn, info) < 0)
105 + info->libs, info->nlibs, info->nvrm_version) < 0)
108 info->nlibs32 = size;
109 @@ -233,13 +231,11 @@ find_library_paths(struct error *err, struct dxcore_context *dxcore, struct nvc_
110 if (info->libs32 == NULL)
112 if (ldcache_resolve(&ld, LIB32_ARCH, root, libs,
113 - info->libs32, info->nlibs32, select_libraries_fn, info) < 0)
114 + info->libs32, info->nlibs32, info->nvrm_version) < 0)
119 - if (ldcache_close(&ld) < 0)
124 diff --git a/src/nvc_ldcache.c b/src/nvc_ldcache.c
125 index db3b2f69692270e9058b2e26f18eb31677909d05..ae5def43b4cb3973af3aad55361265173ca938a7 100644
126 --- a/src/nvc_ldcache.c
127 +++ b/src/nvc_ldcache.c
128 @@ -367,7 +367,7 @@ nvc_ldcache_update(struct nvc_context *ctx, const struct nvc_container *cnt)
129 if (validate_args(ctx, cnt != NULL) < 0)
132 - argv = (char * []){cnt->cfg.ldconfig, "-f", "/etc/ld.so.conf", "-C", "/etc/ld.so.cache", cnt->cfg.libs_dir, cnt->cfg.libs32_dir, NULL};
133 + argv = (char * []){cnt->cfg.ldconfig, "-f", "/tmp/ld.so.conf.nvidia-host", "-C", "/tmp/ld.so.cache.nvidia-host", cnt->cfg.libs_dir, cnt->cfg.libs32_dir, NULL};
134 if (*argv[0] == '@') {
136 * We treat this path specially to be relative to the host filesystem.