python312Packages.llama-index: 0.12.9 -> 0.12.9.post1 (#371957)
[NixPkgs.git] / pkgs / by-name / li / libnvidia-container / 0001-ldcache-don-t-use-ldcache.patch
blob1a26140b8beebadf382a43aa6baf56f46e11af33
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.
7 ---
8 src/ldcache.c | 46 +++++++++++++++++-----------------------------
9 src/ldcache.h | 2 +-
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
16 --- a/src/ldcache.c
17 +++ b/src/ldcache.c
18 @@ -108,40 +108,28 @@ ldcache_close(struct ldcache *ctx)
20 int
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)
25 char path[PATH_MAX];
26 - struct header_libc6 *h;
27 - int override;
28 + char dir[PATH_MAX];
29 + char lib[PATH_MAX];
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)
40 - continue;
42 - for (size_t j = 0; j < size; ++j) {
43 - if (!str_has_prefix(key, libs[j]))
44 - continue;
45 - if (path_resolve(ctx->err, path, root, value) < 0)
46 - return (-1);
47 - if (paths[j] != NULL && str_equal(paths[j], path))
48 - continue;
49 - if ((override = select(ctx->err, select_ctx, root, paths[j], path)) < 0)
50 - return (-1);
51 - if (override) {
52 - free(paths[j]);
53 - paths[j] = xstrdup(ctx->err, path);
54 - if (paths[j] == NULL)
55 - return (-1);
56 - }
57 - break;
58 - }
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)
66 + return (-1);
67 + if (!file_exists(ctx->err, path))
68 + continue;
70 + paths[j] = xstrdup(ctx->err, path);
71 + if (paths[j] == NULL)
72 + return (-1);
74 return (0);
76 diff --git a/src/ldcache.h b/src/ldcache.h
77 index 33d78dd7e21f65eb696535c115bbd2839a6c67ca..2b087dbca1a6a2946cd495e676a61e956212e3dc 100644
78 --- a/src/ldcache.h
79 +++ b/src/ldcache.h
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
90 --- a/src/nvc_info.c
91 +++ b/src/nvc_info.c
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)
94 return (-1);
95 ldcache_init(&ld, err, path);
96 - if (ldcache_open(&ld) < 0)
97 - return (-1);
99 info->nlibs = size;
100 info->libs = array_new(err, size);
101 if (info->libs == NULL)
102 goto fail;
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)
106 goto fail;
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)
111 goto fail;
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)
115 goto fail;
116 rv = 0;
118 fail:
119 - if (ldcache_close(&ld) < 0)
120 - return (-1);
121 return (rv);
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)
130 return (-1);
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.