@@ -201,7 +201,7 @@ class ElfFile
201201
202202 void setInterpreter (const std::string & newInterpreter);
203203
204- typedef enum { rpPrint, rpShrink, rpSet, rpRemove } RPathOp;
204+ typedef enum { rpPrint, rpShrink, rpSet, rpAdd, rpRemove } RPathOp;
205205
206206 void modifyRPath (RPathOp op, const std::vector<std::string> & allowedRpathPrefixes, std::string newRPath);
207207
@@ -1396,6 +1396,10 @@ void ElfFile<ElfFileParamNames>::modifyRPath(RPathOp op,
13961396 return ;
13971397 }
13981398
1399+ if (op == rpAdd) {
1400+ newRPath = std::string (rpath ? rpath : " " ) + " :" + newRPath;
1401+ }
1402+
13991403 changed = true ;
14001404
14011405 /* Zero out the previous rpath to prevent retained dependencies in
@@ -1715,6 +1719,7 @@ static bool shrinkRPath = false;
17151719static std::vector<std::string> allowedRpathPrefixes;
17161720static bool removeRPath = false ;
17171721static bool setRPath = false ;
1722+ static bool addRPath = false ;
17181723static bool printRPath = false ;
17191724static std::string newRPath;
17201725static std::set<std::string> neededLibsToRemove;
@@ -1748,6 +1753,8 @@ static void patchElf2(ElfFile && elfFile, const FileContents & fileContents, std
17481753 elfFile.modifyRPath (elfFile.rpRemove , {}, " " );
17491754 else if (setRPath)
17501755 elfFile.modifyRPath (elfFile.rpSet , {}, newRPath);
1756+ else if (addRPath)
1757+ elfFile.modifyRPath (elfFile.rpAdd , {}, newRPath);
17511758
17521759 if (printNeeded) elfFile.printNeededLibs ();
17531760
@@ -1795,6 +1802,7 @@ void showHelp(const std::string & progName)
17951802 [--print-soname]\t\t Prints 'DT_SONAME' entry of .dynamic section. Raises an error if DT_SONAME doesn't exist\n \
17961803 [--set-soname SONAME]\t\t Sets 'DT_SONAME' entry to SONAME.\n \
17971804 [--set-rpath RPATH]\n \
1805+ [--add-rpath RPATH]\n \
17981806 [--remove-rpath]\n \
17991807 [--shrink-rpath]\n \
18001808 [--allowed-rpath-prefixes PREFIXES]\t\t With '--shrink-rpath', reject rpath entries not starting with the allowed prefix\n \
@@ -1860,6 +1868,11 @@ int mainWrapped(int argc, char * * argv)
18601868 setRPath = true ;
18611869 newRPath = argv[i];
18621870 }
1871+ else if (arg == " --add-rpath" ) {
1872+ if (++i == argc) error (" missing argument" );
1873+ addRPath = true ;
1874+ newRPath = argv[i];
1875+ }
18631876 else if (arg == " --print-rpath" ) {
18641877 printRPath = true ;
18651878 }
0 commit comments