@@ -197,7 +197,7 @@ class ElfFile
197197
198198 void setInterpreter (const std::string & newInterpreter);
199199
200- typedef enum { rpPrint, rpShrink, rpSet, rpRemove } RPathOp;
200+ typedef enum { rpPrint, rpShrink, rpSet, rpAdd, rpRemove } RPathOp;
201201
202202 void modifyRPath (RPathOp op, const std::vector<std::string> & allowedRpathPrefixes, std::string newRPath);
203203
@@ -1408,6 +1408,10 @@ void ElfFile<ElfFileParamNames>::modifyRPath(RPathOp op,
14081408 return ;
14091409 }
14101410
1411+ if (op == rpAdd) {
1412+ newRPath = std::string (rpath ? rpath : " " ) + " :" + newRPath;
1413+ }
1414+
14111415 changed = true ;
14121416
14131417 /* Zero out the previous rpath to prevent retained dependencies in
@@ -1730,6 +1734,7 @@ static bool shrinkRPath = false;
17301734static std::vector<std::string> allowedRpathPrefixes;
17311735static bool removeRPath = false ;
17321736static bool setRPath = false ;
1737+ static bool addRPath = false ;
17331738static bool printRPath = false ;
17341739static std::string newRPath;
17351740static std::set<std::string> neededLibsToRemove;
@@ -1763,6 +1768,8 @@ static void patchElf2(ElfFile && elfFile, const FileContents & fileContents, con
17631768 elfFile.modifyRPath (elfFile.rpRemove , {}, " " );
17641769 else if (setRPath)
17651770 elfFile.modifyRPath (elfFile.rpSet , {}, newRPath);
1771+ else if (addRPath)
1772+ elfFile.modifyRPath (elfFile.rpAdd , {}, newRPath);
17661773
17671774 if (printNeeded) elfFile.printNeededLibs ();
17681775
@@ -1810,6 +1817,7 @@ void showHelp(const std::string & progName)
18101817 [--print-soname]\t\t Prints 'DT_SONAME' entry of .dynamic section. Raises an error if DT_SONAME doesn't exist\n \
18111818 [--set-soname SONAME]\t\t Sets 'DT_SONAME' entry to SONAME.\n \
18121819 [--set-rpath RPATH]\n \
1820+ [--add-rpath RPATH]\n \
18131821 [--remove-rpath]\n \
18141822 [--shrink-rpath]\n \
18151823 [--allowed-rpath-prefixes PREFIXES]\t\t With '--shrink-rpath', reject rpath entries not starting with the allowed prefix\n \
@@ -1876,6 +1884,11 @@ int mainWrapped(int argc, char * * argv)
18761884 setRPath = true ;
18771885 newRPath = argv[i];
18781886 }
1887+ else if (arg == " --add-rpath" ) {
1888+ if (++i == argc) error (" missing argument" );
1889+ addRPath = true ;
1890+ newRPath = argv[i];
1891+ }
18791892 else if (arg == " --print-rpath" ) {
18801893 printRPath = true ;
18811894 }
@@ -1942,6 +1955,9 @@ int mainWrapped(int argc, char * * argv)
19421955 if (!outputFileName.empty () && fileNames.size () != 1 )
19431956 error (" --output option only allowed with single input file" );
19441957
1958+ if (setRPath && addRPath)
1959+ error (" --set-rpath option not allowed with --add-rpath" );
1960+
19451961 patchElf ();
19461962
19471963 return 0 ;
0 commit comments