@@ -673,15 +673,15 @@ void ElfFile<ElfFileParamNames>::writeReplacedSections(Elf_Off & curOff,
673673 *before* writing the new section contents (below) to prevent
674674 clobbering previously written new section contents. */
675675 for (auto & i : replacedSections) {
676- std::string sectionName = i.first ;
676+ const std::string & sectionName = i.first ;
677677 Elf_Shdr & shdr = findSection (sectionName);
678678 if (rdi (shdr.sh_type ) != SHT_NOBITS)
679679 memset (contents + rdi (shdr.sh_offset ), ' X' , rdi (shdr.sh_size ));
680680 }
681681
682682 std::set<unsigned int > noted_phdrs = {};
683683 for (auto & i : replacedSections) {
684- std::string sectionName = i.first ;
684+ const std::string & sectionName = i.first ;
685685 auto & shdr = findSection (sectionName);
686686 Elf_Shdr orig_shdr = shdr;
687687 debug (" rewriting section '%s' from offset 0x%x (size %d) to offset 0x%x (size %d)\n " ,
@@ -1143,7 +1143,7 @@ void ElfFile<ElfFileParamNames>::rewriteHeaders(Elf_Addr phdrAddress)
11431143 fprintf (stderr, " warning: entry %d in symbol table refers to a non-existent section, skipping\n " , shndx);
11441144 continue ;
11451145 }
1146- std::string section = sectionsByOldIndex.at (shndx);
1146+ const std::string & section = sectionsByOldIndex.at (shndx);
11471147 assert (!section.empty ());
11481148 auto newIndex = findSection3 (section); // inefficient
11491149 // debug("rewriting symbol %d: index = %d (%s) -> %d\n", entry, shndx, section.c_str(), newIndex);
@@ -1198,7 +1198,7 @@ void ElfFile<ElfFileParamNames>::modifySoname(sonameMode op, const std::string &
11981198
11991199 if (op == printSoname) {
12001200 if (soname) {
1201- if (std::string (soname ? soname : " " ). empty () )
1201+ if (strlen (soname) == 0 )
12021202 debug (" DT_SONAME is empty\n " );
12031203 else
12041204 printf (" %s\n " , soname);
@@ -1208,7 +1208,7 @@ void ElfFile<ElfFileParamNames>::modifySoname(sonameMode op, const std::string &
12081208 return ;
12091209 }
12101210
1211- if (std::string ( soname ? soname : " " ) == newSoname) {
1211+ if (soname && soname == newSoname) {
12121212 debug (" current and proposed new SONAMEs are equal keeping DT_SONAME entry\n " );
12131213 return ;
12141214 }
@@ -1399,7 +1399,7 @@ void ElfFile<ElfFileParamNames>::modifyRPath(RPathOp op,
13991399 changed = true ;
14001400 }
14011401
1402- if (std::string ( rpath ? rpath : " " ) == newRPath) {
1402+ if (rpath && rpath == newRPath) {
14031403 return ;
14041404 }
14051405
@@ -1732,7 +1732,7 @@ static bool printNeeded = false;
17321732static bool noDefaultLib = false ;
17331733
17341734template <class ElfFile >
1735- static void patchElf2 (ElfFile && elfFile, const FileContents & fileContents, std::string fileName)
1735+ static void patchElf2 (ElfFile && elfFile, const FileContents & fileContents, const std::string & fileName)
17361736{
17371737 if (printInterpreter)
17381738 printf (" %s\n " , elfFile.getInterpreter ().c_str ());
@@ -1783,7 +1783,7 @@ static void patchElf()
17831783 debug (" patching ELF file '%s'\n " , fileName.c_str ());
17841784
17851785 auto fileContents = readFile (fileName);
1786- std::string outputFileName2 = outputFileName.empty () ? fileName : outputFileName;
1786+ const std::string & outputFileName2 = outputFileName.empty () ? fileName : outputFileName;
17871787
17881788 if (getElfType (fileContents).is32Bit )
17891789 patchElf2 (ElfFile<Elf32_Ehdr, Elf32_Phdr, Elf32_Shdr, Elf32_Addr, Elf32_Off, Elf32_Dyn, Elf32_Sym, Elf32_Verneed, Elf32_Versym>(fileContents), fileContents, outputFileName2);
0 commit comments