Skip to content

Commit 6d4c1d9

Browse files
committed
Attempt to obey pre-existing RPATHs, #52
1 parent 646201d commit 6d4c1d9

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

shared/shared.cpp

+19-4
Original file line numberDiff line numberDiff line change
@@ -670,26 +670,28 @@ QString copyDylib(const LibraryInfo &library, const QString path)
670670
return dylibDestinationBinaryPath;
671671
}
672672

673-
void runPatchelf(QStringList options)
673+
QString runPatchelf(QStringList options)
674674
{
675675
QProcess patchelftool;
676+
LogDebug() << "options:" << options;
676677
patchelftool.start("patchelf", options);
677678
if (!patchelftool.waitForStarted()) {
678-
if(patchelftool.errorString().contains("execvp: No such file or directory")){
679+
if(patchelftool.errorString().contains("No such file or directory")){
679680
LogError() << "Could not start patchelf.";
680681
LogError() << "Make sure it is installed on your $PATH, e.g., in /usr/local/bin.";
681682
LogError() << "You can get it from https://nixos.org/patchelf.html.";
682683
} else {
683-
LogError() << "Could not start patchelftool. Process error is" << patchelftool.errorString();
684+
LogError() << "Could not start patchelf tool. Process error is" << patchelftool.errorString();
684685
}
685686
exit(1);
686687
}
687688
patchelftool.waitForFinished();
688689
if (patchelftool.exitCode() != 0) {
689690
LogError() << "runPatchelf:" << patchelftool.readAllStandardError();
690-
LogError() << "runPatchelf:" << patchelftool.readAllStandardOutput();
691+
// LogError() << "runPatchelf:" << patchelftool.readAllStandardOutput();
691692
// exit(1); // Do not exit because this could be a script that patchelf can't work on
692693
}
694+
return(patchelftool.readAllStandardOutput().trimmed());
693695
}
694696

695697
bool patchQtCore(const QString &path, const QString &variable, const QString &value)
@@ -742,6 +744,19 @@ bool patchQtCore(const QString &path, const QString &variable, const QString &va
742744

743745
void changeIdentification(const QString &id, const QString &binaryPath)
744746
{
747+
LogNormal() << "Checking rpath in" << binaryPath;
748+
QString oldRpath = runPatchelf(QStringList() << "--print-rpath" << binaryPath);
749+
LogDebug() << "oldRpath:" << oldRpath;
750+
if (oldRpath.startsWith("/")){
751+
LogDebug() << "Old rpath in" << binaryPath << "starts with /, hence adding it to LD_LIBRARY_PATH";
752+
// FIXME: Split along ":" characters, check each one, only append to LD_LIBRARY_PATH if not already there
753+
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
754+
QString oldPath = env.value("LD_LIBRARY_PATH");
755+
QString newPath = oldRpath + ":" + oldPath; // FIXME: If we use a ldd replacement, we still need to observe this path
756+
// FIXME: Directory layout might be different for system Qt; cannot assume lib/ to always be inside the Qt directory
757+
LogDebug() << "Added to LD_LIBRARY_PATH:" << newPath;
758+
setenv("LD_LIBRARY_PATH",newPath.toUtf8().constData(),1);
759+
}
745760
LogNormal() << "Changing rpath in" << binaryPath << "to" << id;
746761
runPatchelf(QStringList() << "--set-rpath" << id << binaryPath);
747762

0 commit comments

Comments
 (0)