diff options
author | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2016-01-08 13:48:15 (GMT) |
---|---|---|
committer | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2016-01-08 13:48:15 (GMT) |
commit | 1d0ab307db61c64ab50e9fb582ab236d2b09f221 (patch) | |
tree | 48c8d7dcb8cef416cdc0962e5317f6678cf27cf8 | |
parent | f5ffb8de8e9376614af42833d2277a383d2f628e (diff) | |
parent | 34e50f2e1d3d3a123260056d71aa3af1cfc663e7 (diff) | |
download | patchelf-1d0ab307db61c64ab50e9fb582ab236d2b09f221.zip patchelf-1d0ab307db61c64ab50e9fb582ab236d2b09f221.tar.gz patchelf-1d0ab307db61c64ab50e9fb582ab236d2b09f221.tar.bz2 |
Merge branch 'print-needed' of https://github.com/darealshinji/patchelf
-rw-r--r-- | src/patchelf.cc | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/src/patchelf.cc b/src/patchelf.cc index 37ea09d..4d299e9 100644 --- a/src/patchelf.cc +++ b/src/patchelf.cc @@ -164,6 +164,8 @@ public: void replaceNeeded(map<string, string>& libs); + void printNeededLibs(); + void noDefaultLib(); private: @@ -1320,6 +1322,23 @@ void ElfFile<ElfFileParamNames>::addNeeded(set<string> libs) changed = true; } +template<ElfFileParams> +void ElfFile<ElfFileParamNames>::printNeededLibs() +{ + Elf_Shdr & shdrDynamic = findSection(".dynamic"); + Elf_Shdr & shdrDynStr = findSection(".dynstr"); + char *strTab = (char *)contents + rdi(shdrDynStr.sh_offset); + + Elf_Dyn *dyn = (Elf_Dyn *) (contents + rdi(shdrDynamic.sh_offset)); + + for (; rdi(dyn->d_tag) != DT_NULL; dyn++) { + if (rdi(dyn->d_tag) == DT_NEEDED) { + char *name = strTab + rdi(dyn->d_un.d_val); + printf("%s\n", name); + } + } +} + template<ElfFileParams> void ElfFile<ElfFileParamNames>::noDefaultLib() @@ -1366,7 +1385,6 @@ static bool printSoname = false; static bool setSoname = false; static string newSoname; static string newInterpreter; - static bool shrinkRPath = false; static bool removeRPath = false; static bool setRPath = false; @@ -1375,6 +1393,7 @@ static string newRPath; static set<string> neededLibsToRemove; static map<string, string> neededLibsToReplace; static set<string> neededLibsToAdd; +static bool printNeeded = false; static bool noDefaultLib = false; template<class ElfFile> @@ -1404,6 +1423,8 @@ static void patchElf2(ElfFile & elfFile) else if (setRPath) elfFile.modifyRPath(elfFile.rpSet, newRPath); + if (printNeeded) elfFile.printNeededLibs(); + elfFile.removeNeeded(neededLibsToRemove); elfFile.replaceNeeded(neededLibsToReplace); elfFile.addNeeded(neededLibsToAdd); @@ -1420,7 +1441,7 @@ static void patchElf2(ElfFile & elfFile) static void patchElf() { - if (!printInterpreter && !printRPath && !printSoname) + if (!printInterpreter && !printRPath && !printSoname && !printNeeded) debug("patching ELF file `%s'\n", fileName.c_str()); debug("Kernel page size is %u bytes\n", getPageSize()); @@ -1467,6 +1488,7 @@ void showHelp(const string & progName) [--add-needed LIBRARY]\n\ [--remove-needed LIBRARY]\n\ [--replace-needed LIBRARY NEW_LIBRARY]\n\ + [--print-needed]\n\ [--no-default-lib]\n\ [--debug]\n\ [--version]\n\ @@ -1529,6 +1551,9 @@ int main(int argc, char * * argv) added. */ forceRPath = true; } + else if (arg == "--print-needed") { + printNeeded = true; + } else if (arg == "--add-needed") { if (++i == argc) error("missing argument"); neededLibsToAdd.insert(argv[i]); |