Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix rpath for libraries in subfolders of usr/lib and for executables in usr/lib/libexec #233

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 42 additions & 9 deletions src/core/appdir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,10 +385,14 @@ 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));
std::string rpath = "$ORIGIN/" + relPath.string() + ":$ORIGIN";
return rpath;
if (relPath.empty() || relPath == ".") {
return "$ORIGIN";
} else {
auto rpath = "$ORIGIN/" + relPath.string();
return appendOrigin ? rpath + ":$ORIGIN" : rpath;
}
}

bool deployLibrary(const fs::path& path, bool forceDeploy = false, bool deployDependencies = true, const fs::path& destination = fs::path()) {
Expand Down Expand Up @@ -803,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<fs::path> AppDir::listSharedLibraries() const {
const auto libexecPath = (path() / "usr/lib/libexec/").string();
std::vector<fs::path> 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;
Expand All @@ -836,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;
}
Expand All @@ -848,13 +874,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;
}
}

Expand Down
1 change: 1 addition & 0 deletions src/plugin/plugin_process_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <thread>
#include <tuple>
#include <utility>
#include <array>

// local headers
#include <linuxdeploy/plugin/plugin_process_handler.h>
Expand Down
1 change: 1 addition & 0 deletions src/subprocess/subprocess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <utility>
#include <unistd.h>
#include <thread>
#include <array>

// local headers
#include "linuxdeploy/subprocess/subprocess.h"
Expand Down