From fce30b8d45b5e6eceba3cc6f6edf7d64613cc903 Mon Sep 17 00:00:00 2001 From: Simon McVittie <smcv@collabora.com> Date: Wed, 21 Apr 2021 18:17:57 +0100 Subject: [PATCH] pv-runtime: Avoid opening libraries to determine their SONAME This is surprisingly expensive to do, particularly with a cold cache. If we can avoid this, then deleting unwanted libraries from the mutable copy of the runtime becomes a lot faster. With the disk cache cleared and running on slow hardware, this cuts down deletion of the unwanted libraries from 2-4 seconds to basically instantaneous. Signed-off-by: Simon McVittie <smcv@collabora.com> --- pressure-vessel/runtime.c | 48 --------------------------------------- 1 file changed, 48 deletions(-) diff --git a/pressure-vessel/runtime.c b/pressure-vessel/runtime.c index b8f1d8653..7ea3aa168 100644 --- a/pressure-vessel/runtime.c +++ b/pressure-vessel/runtime.c @@ -39,7 +39,6 @@ #include "bwrap.h" #include "bwrap-lock.h" -#include "elf-utils.h" #include "enumtypes.h" #include "exports.h" #include "flatpak-run-private.h" @@ -2837,11 +2836,7 @@ pv_runtime_remove_overridden_libraries (PvRuntime *self, while (TRUE) { - g_autoptr(Elf) elf = NULL; - g_autoptr(GError) local_error = NULL; - glnx_autofd int libfd = -1; g_autofree gchar *path = NULL; - g_autofree gchar *soname = NULL; g_autofree gchar *target = NULL; const char *target_base; @@ -3018,49 +3013,6 @@ pv_runtime_remove_overridden_libraries (PvRuntime *self, continue; } } - - libfd = _srt_resolve_in_sysroot (self->mutable_sysroot_fd, path, - SRT_RESOLVE_FLAGS_READABLE, NULL, - &local_error); - - if (libfd < 0) - { - g_warning ("Unable to open %s/%s for reading: %s", - self->mutable_sysroot, path, local_error->message); - g_clear_error (&local_error); - continue; - } - - elf = pv_elf_open_fd (libfd, &local_error); - - if (elf != NULL) - soname = pv_elf_get_soname (elf, &local_error); - - if (soname == NULL) - { - g_warning ("Unable to get SONAME of %s/%s: %s", - self->mutable_sysroot, path, local_error->message); - g_clear_error (&local_error); - continue; - } - - /* If we found a library with SONAME libfoo.so.1 in the - * container, and libfoo.so.1 also exists among the overrides, - * delete it. */ - { - g_autofree gchar *soname_link = NULL; - - soname_link = g_build_filename (arch->libdir_in_current_namespace, - soname, NULL); - - if (g_file_test (soname_link, G_FILE_TEST_IS_SYMLINK)) - { - g_hash_table_replace (delete[i], - g_strdup (dent->d_name), - g_steal_pointer (&soname_link)); - continue; - } - } } /* Iterate over the directory again, to clean up dangling development -- GitLab