From 2d1f838d20337fdbc792f612ea76691575f84004 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ingo=20Kl=C3=B6cker?= Date: Tue, 15 Nov 2022 16:39:11 +0100 Subject: [PATCH 1/5] Avoid $ORIGIN/.:$ORIGIN as result of calculateRelativeRPath --- src/core/appdir.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/core/appdir.cpp b/src/core/appdir.cpp index d6b510d1..5600e3fb 100644 --- a/src/core/appdir.cpp +++ b/src/core/appdir.cpp @@ -387,8 +387,12 @@ namespace linuxdeploy { static std::string calculateRelativeRPath(const fs::path& originDir, const fs::path& dependencyLibrariesDir) { auto relPath = fs::relative(fs::absolute(dependencyLibrariesDir), fs::absolute(originDir)); - std::string rpath = "$ORIGIN/" + relPath.string() + ":$ORIGIN"; - return rpath; + if (relPath.empty() || relPath == ".") { + return "$ORIGIN"; + } else { + auto rpath = "$ORIGIN/" + relPath.string() + ":$ORIGIN"; + return rpath; + } } bool deployLibrary(const fs::path& path, bool forceDeploy = false, bool deployDependencies = true, const fs::path& destination = fs::path()) { From 5aad589b4d0d4d76e2a67c355339fa2dd29f8fa1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ingo=20Kl=C3=B6cker?= Date: Tue, 15 Nov 2022 16:40:42 +0100 Subject: [PATCH 2/5] Allow callers to disable appending of :$ORIGIN to relative rpath --- src/core/appdir.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/appdir.cpp b/src/core/appdir.cpp index 5600e3fb..a59296ac 100644 --- a/src/core/appdir.cpp +++ b/src/core/appdir.cpp @@ -385,13 +385,13 @@ namespace linuxdeploy { return stripPath; } - static std::string calculateRelativeRPath(const fs::path& originDir, const fs::path& dependencyLibrariesDir) { + static std::string calculateRelativeRPath(const fs::path& originDir, const fs::path& dependencyLibrariesDir, bool appendOrigin = true) { auto relPath = fs::relative(fs::absolute(dependencyLibrariesDir), fs::absolute(originDir)); if (relPath.empty() || relPath == ".") { return "$ORIGIN"; } else { - auto rpath = "$ORIGIN/" + relPath.string() + ":$ORIGIN"; - return rpath; + auto rpath = "$ORIGIN/" + relPath.string(); + return appendOrigin ? rpath + ":$ORIGIN" : rpath; } } From 790a3c20df224dfd0491894c4486331da98349f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ingo=20Kl=C3=B6cker?= Date: Tue, 15 Nov 2022 16:43:58 +0100 Subject: [PATCH 3/5] Add the correct rpath for libraries in subfolders of usr/lib The rpath of libraries in subfolders of usr/lib should be $ORIGIN/ instead of just $ORIGIN, e.g. for usr/lib/sasl2/libscram.so.3.0.0 it should be $ORIGIN/.. --- src/core/appdir.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/core/appdir.cpp b/src/core/appdir.cpp index a59296ac..68248467 100644 --- a/src/core/appdir.cpp +++ b/src/core/appdir.cpp @@ -852,13 +852,20 @@ namespace linuxdeploy { if (!d->deployElfDependencies(sharedLibrary)) return false; - const auto rpath = elf_file::ElfFile(sharedLibrary).getRPath(); - auto rpathList = util::split(rpath, ':'); - if (std::find(rpathList.begin(), rpathList.end(), "$ORIGIN") == rpathList.end()) { - rpathList.push_back("$ORIGIN"); + // add correct rpath + const auto rpathDestination = path() / "usr" / PrivateData::getLibraryDirName(sharedLibrary); + ldLog() << LD_DEBUG << "rpath destination:" << rpathDestination << std::endl; + + const auto rpath = PrivateData::calculateRelativeRPath(sharedLibrary.parent_path(), rpathDestination, false); + ldLog() << LD_DEBUG << "Calculated rpath:" << rpath << std::endl; + + const auto rpaths = elf_file::ElfFile(sharedLibrary).getRPath(); + auto rpathList = util::split(rpaths, ':'); + if (std::find(rpathList.begin(), rpathList.end(), rpath) == rpathList.end()) { + rpathList.push_back(rpath); d->setElfRPathOperations[sharedLibrary] = util::join(rpathList, ":"); } else { - d->setElfRPathOperations[sharedLibrary] = rpath; + d->setElfRPathOperations[sharedLibrary] = rpaths; } } From 68c3744fc73eda1018ef2dda503f790c7fe7b8d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ingo=20Kl=C3=B6cker?= Date: Tue, 15 Nov 2022 16:45:32 +0100 Subject: [PATCH 4/5] Add support for executables in usr/lib/libexec --- src/core/appdir.cpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/core/appdir.cpp b/src/core/appdir.cpp index 68248467..a04757da 100644 --- a/src/core/appdir.cpp +++ b/src/core/appdir.cpp @@ -807,13 +807,30 @@ namespace linuxdeploy { executables.push_back(file); } + for (const auto& file : listFilesInDirectory(path() / "usr/lib/libexec", true)) { + // make sure it's an ELF file + try { + elf_file::ElfFile elfFile(file); + } catch (const elf_file::ElfFileParseError&) { + // FIXME: remove this workaround once the MIME check below works as intended + continue; + } + + executables.push_back(file); + } + return executables; } std::vector AppDir::listSharedLibraries() const { + const auto libexecPath = (path() / "usr/lib/libexec/").string(); std::vector sharedLibraries; for (const auto& file : listFilesInDirectory(path() / "usr" / "lib", true)) { + // skip executables in libexec + if (util::stringStartsWith(file.string(), libexecPath)) + continue; + // exclude debug symbols if (d->isInDebugSymbolsLocation(file)) continue; @@ -840,7 +857,12 @@ namespace linuxdeploy { if (!d->deployElfDependencies(executable)) return false; - std::string rpath = "$ORIGIN/../" + PrivateData::getLibraryDirName(executable); + // set rpath correctly + const auto rpathDestination = path() / "usr" / PrivateData::getLibraryDirName(executable); + ldLog() << LD_DEBUG << "rpath destination:" << rpathDestination << std::endl; + + const auto rpath = PrivateData::calculateRelativeRPath(executable.parent_path(), rpathDestination, false); + ldLog() << LD_DEBUG << "Calculated rpath:" << rpath << std::endl; d->setElfRPathOperations[executable] = rpath; } From fd95d72fe89216301ed44664f593a363a2935fe7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ingo=20Kl=C3=B6cker?= Date: Tue, 15 Nov 2022 16:47:43 +0100 Subject: [PATCH 5/5] Add missing includes gcc 12 requires explicitly including when using std::array. --- src/plugin/plugin_process_handler.cpp | 1 + src/subprocess/subprocess.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/src/plugin/plugin_process_handler.cpp b/src/plugin/plugin_process_handler.cpp index 07c41aae..6a4694eb 100644 --- a/src/plugin/plugin_process_handler.cpp +++ b/src/plugin/plugin_process_handler.cpp @@ -3,6 +3,7 @@ #include #include #include +#include // local headers #include diff --git a/src/subprocess/subprocess.cpp b/src/subprocess/subprocess.cpp index 92e0d803..e90b0f97 100644 --- a/src/subprocess/subprocess.cpp +++ b/src/subprocess/subprocess.cpp @@ -6,6 +6,7 @@ #include #include #include +#include // local headers #include "linuxdeploy/subprocess/subprocess.h"