Skip to content
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

add --shrink-prefix used for build while package is not installed #101

Open
wants to merge 1 commit 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
3 changes: 3 additions & 0 deletions patchelf.1
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ For instance, if an executable references one library libfoo.so, has
an RPATH "/lib:/usr/lib:/foo/lib", and libfoo.so can only be found
in /foo/lib, then the new RPATH will be "/foo/lib".

.IP --shrink-prefix
Work with --shrink-rpath, used in stage of build before installed to real dest path.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't really make sense of this description...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for response

I use patchelf in a stage of rpmbuild, which install software files in a buildroot dir ( for example /home/rpmbuild/buildroot but which is not the root dir software actually run at ).
And in that case, patchelf would not find dynamic libs correctly.

.IP --shrink-prefix PREFIX
Work with --shrink-rpath, search all directory in RPATH with prefix $PREFIX, insteal search all directory IN RPATH

For instance as above, --shrink-prefix /root/build/, /root/build/lib:/root/build/usr/lib:/root/build/foo/lib would be searched


.IP --print-rpath
Prints the RPATH for an executable or library.

Expand Down
21 changes: 19 additions & 2 deletions src/patchelf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1092,7 +1092,13 @@ void ElfFile<ElfFileParamNames>::modifyRPath(RPathOp op, string newRPath)
needed library. */
if (op == rpShrink) {
static vector<bool> neededLibFound(neededLibs.size(), false);
string shrinkPath;

if (newRPath != "") {
shrinkPath = newRPath;
}
else
shrinkPath = "";
newRPath = "";

char * pos = rpath;
Expand All @@ -1117,7 +1123,12 @@ void ElfFile<ElfFileParamNames>::modifyRPath(RPathOp op, string newRPath)
bool libFound = false;
for (unsigned int j = 0; j < neededLibs.size(); ++j)
if (!neededLibFound[j]) {
string libName = dirName + "/" + neededLibs[j];
string libName;
if (shrinkPath != "") {
libName = shrinkPath + "/" + dirName + "/" + neededLibs[j];
}
else
libName = dirName + "/" + neededLibs[j];
struct stat st;
if (stat(libName.c_str(), &st) == 0) {
neededLibFound[j] = true;
Expand Down Expand Up @@ -1455,6 +1466,7 @@ static bool setSoname = false;
static string newSoname;
static string newInterpreter;
static bool shrinkRPath = false;
static string shrinkPrefix;
static bool removeRPath = false;
static bool setRPath = false;
static bool printRPath = false;
Expand Down Expand Up @@ -1486,7 +1498,7 @@ static void patchElf2(ElfFile & elfFile)
elfFile.modifyRPath(elfFile.rpPrint, "");

if (shrinkRPath)
elfFile.modifyRPath(elfFile.rpShrink, "");
elfFile.modifyRPath(elfFile.rpShrink, shrinkPrefix);
else if (removeRPath)
elfFile.modifyRPath(elfFile.rpRemove, "");
else if (setRPath)
Expand Down Expand Up @@ -1553,6 +1565,7 @@ void showHelp(const string & progName)
[--set-rpath RPATH]\n\
[--remove-rpath]\n\
[--shrink-rpath]\n\
[--shrink-prefix]\n\
[--print-rpath]\n\
[--force-rpath]\n\
[--add-needed LIBRARY]\n\
Expand Down Expand Up @@ -1604,6 +1617,10 @@ int main(int argc, char * * argv)
else if (arg == "--shrink-rpath") {
shrinkRPath = true;
}
else if (arg == "--shrink-prefix") {
if (++i == argc) error("missing argument");
shrinkPrefix = argv[i];
}
else if (arg == "--set-rpath") {
if (++i == argc) error("missing argument");
setRPath = true;
Expand Down