diff options
author | Changli Gao <xiaosuo@gmail.com> | 2014-10-22 17:41:47 (GMT) |
---|---|---|
committer | Changli Gao <xiaosuo@gmail.com> | 2014-10-22 17:41:47 (GMT) |
commit | c09a356552c87daf27e97f054b9ef293afa8647a (patch) | |
tree | fecf5164f09c8ab09b7206d4a329625524961d63 /src/patchelf.cc | |
parent | 03fc9079b722da4b75b86878d139b225162e3335 (diff) | |
download | patchelf-c09a356552c87daf27e97f054b9ef293afa8647a.zip patchelf-c09a356552c87daf27e97f054b9ef293afa8647a.tar.gz patchelf-c09a356552c87daf27e97f054b9ef293afa8647a.tar.bz2 |
Add option --no-default-lib
Marks the object that the search for dependencies of this object will ignore any
default library search paths.
Diffstat (limited to 'src/patchelf.cc')
-rw-r--r-- | src/patchelf.cc | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/patchelf.cc b/src/patchelf.cc index 731b9ad..eca80a6 100644 --- a/src/patchelf.cc +++ b/src/patchelf.cc @@ -170,6 +170,8 @@ public: void replaceNeeded(map<string, string>& libs); + void noDefaultLib(); + private: /* Convert an integer in big or little endian representation (as @@ -1289,6 +1291,46 @@ void ElfFile<ElfFileParamNames>::addNeeded(set<string> libs) } +template<ElfFileParams> +void ElfFile<ElfFileParamNames>::noDefaultLib() +{ + Elf_Shdr & shdrDynamic = findSection(".dynamic"); + + Elf_Dyn * dyn = (Elf_Dyn *) (contents + rdi(shdrDynamic.sh_offset)); + Elf_Dyn * dynFlags1 = 0; + for ( ; rdi(dyn->d_tag) != DT_NULL; dyn++) { + if (rdi(dyn->d_tag) == DT_FLAGS_1) { + dynFlags1 = dyn; + break; + } + } + if (dynFlags1) { + if (dynFlags1->d_un.d_val & DF_1_NODEFLIB) + return; + dynFlags1->d_un.d_val |= DF_1_NODEFLIB; + } else { + string & newDynamic = replaceSection(".dynamic", + rdi(shdrDynamic.sh_size) + sizeof(Elf_Dyn)); + + unsigned int idx = 0; + for ( ; rdi(((Elf_Dyn *) newDynamic.c_str())[idx].d_tag) != DT_NULL; idx++) ; + debug("DT_NULL index is %d\n", idx); + + /* Shift all entries down by one. */ + setSubstr(newDynamic, sizeof(Elf_Dyn), + string(newDynamic, 0, sizeof(Elf_Dyn) * (idx + 1))); + + /* Add the DT_FLAGS_1 entry at the top. */ + Elf_Dyn newDyn; + wri(newDyn.d_tag, DT_FLAGS_1); + newDyn.d_un.d_val = DF_1_NODEFLIB; + setSubstr(newDynamic, 0, string((char *) &newDyn, sizeof(Elf_Dyn))); + } + + changed = true; +} + + static bool printInterpreter = false; static bool printSoname = false; static bool setSoname = false; @@ -1302,6 +1344,7 @@ static string newRPath; static set<string> neededLibsToRemove; static map<string, string> neededLibsToReplace; static set<string> neededLibsToAdd; +static bool noDefaultLib = false; template<class ElfFile> static void patchElf2(ElfFile & elfFile, mode_t fileMode) @@ -1332,6 +1375,9 @@ static void patchElf2(ElfFile & elfFile, mode_t fileMode) elfFile.replaceNeeded(neededLibsToReplace); elfFile.addNeeded(neededLibsToAdd); + if (noDefaultLib) + elfFile.noDefaultLib(); + if (elfFile.isChanged()){ elfFile.rewriteSections(); writeFile(fileName, fileMode); @@ -1387,6 +1433,7 @@ void showHelp(const string & progName) [--add-needed LIBRARY]\n\ [--remove-needed LIBRARY]\n\ [--replace-needed LIBRARY NEW_LIBRARY]\n\ + [--no-default-lib]\n\ [--debug]\n\ [--version]\n\ FILENAME\n", progName.c_str()); @@ -1461,6 +1508,9 @@ int main(int argc, char * * argv) else if (arg == "--debug") { debugMode = true; } + else if (arg == "--no-default-lib") { + noDefaultLib = true; + } else if (arg == "--help" || arg == "-h" ) { showHelp(argv[0]); return 0; |