@@ -699,23 +699,25 @@ void ElfFile<ElfFileParamNames>::writeReplacedSections(Elf_Off & curOff,
699699 /* If this is the .interp section, then the PT_INTERP segment
700700 must be sync'ed with it. */
701701 if (sectionName == " .interp" ) {
702- for (unsigned int j = 0 ; j < phdrs. size (); ++j)
703- if (rdi (phdrs[j] .p_type ) == PT_INTERP) {
704- phdrs[j] .p_offset = shdr.sh_offset ;
705- phdrs[j] .p_vaddr = phdrs[j] .p_paddr = shdr.sh_addr ;
706- phdrs[j] .p_filesz = phdrs[j] .p_memsz = shdr.sh_size ;
702+ for (auto & phdr : phdrs) {
703+ if (rdi (phdr .p_type ) == PT_INTERP) {
704+ phdr .p_offset = shdr.sh_offset ;
705+ phdr .p_vaddr = phdr .p_paddr = shdr.sh_addr ;
706+ phdr .p_filesz = phdr .p_memsz = shdr.sh_size ;
707707 }
708+ }
708709 }
709710
710711 /* If this is the .dynamic section, then the PT_DYNAMIC segment
711712 must be sync'ed with it. */
712713 if (sectionName == " .dynamic" ) {
713- for (unsigned int j = 0 ; j < phdrs. size (); ++j)
714- if (rdi (phdrs[j] .p_type ) == PT_DYNAMIC) {
715- phdrs[j] .p_offset = shdr.sh_offset ;
716- phdrs[j] .p_vaddr = phdrs[j] .p_paddr = shdr.sh_addr ;
717- phdrs[j] .p_filesz = phdrs[j] .p_memsz = shdr.sh_size ;
714+ for (auto & phdr : phdrs) {
715+ if (rdi (phdr .p_type ) == PT_DYNAMIC) {
716+ phdr .p_offset = shdr.sh_offset ;
717+ phdr .p_vaddr = phdr .p_paddr = shdr.sh_addr ;
718+ phdr .p_filesz = phdr .p_memsz = shdr.sh_size ;
718719 }
720+ }
719721 }
720722
721723 /* If this is a note section, there might be a PT_NOTE segment that
@@ -770,8 +772,8 @@ void ElfFile<ElfFileParamNames>::rewriteSectionsLibrary()
770772 PT_LOAD segment located directly after the last virtual address
771773 page of other segments. */
772774 Elf_Addr startPage = 0 ;
773- for (unsigned int i = 0 ; i < phdrs. size (); ++i ) {
774- Elf_Addr thisPage = roundUp (rdi (phdrs[i] .p_vaddr ) + rdi (phdrs[i] .p_memsz ), getPageSize ());
775+ for (auto & phdr : phdrs) {
776+ Elf_Addr thisPage = roundUp (rdi (phdr .p_vaddr ) + rdi (phdr .p_memsz ), getPageSize ());
775777 if (thisPage > startPage) startPage = thisPage;
776778 }
777779
@@ -984,9 +986,7 @@ void ElfFile<ElfFileParamNames>::normalizeNoteSegments()
984986 bool replaced_note = std::any_of (replacedSections.begin (), replacedSections.end (), [this ](std::pair<const std::string, std::string> & i) { return rdi (findSection (i.first ).sh_type ) == SHT_NOTE; });
985987 if (!replaced_note) return ;
986988
987- size_t orig_count = phdrs.size ();
988- for (size_t i = 0 ; i < orig_count; ++i) {
989- auto & phdr = phdrs[i];
989+ for (auto & phdr : phdrs) {
990990 if (rdi (phdr.p_type ) != PT_NOTE) continue ;
991991
992992 size_t start_off = rdi (phdr.p_offset );
@@ -1056,11 +1056,11 @@ void ElfFile<ElfFileParamNames>::rewriteHeaders(Elf_Addr phdrAddress)
10561056
10571057 /* If there is a segment for the program header table, update it.
10581058 (According to the ELF spec, there can only be one.) */
1059- for (unsigned int i = 0 ; i < phdrs. size (); ++i ) {
1060- if (rdi (phdrs[i] .p_type ) == PT_PHDR) {
1061- phdrs[i] .p_offset = hdr->e_phoff ;
1062- wri (phdrs[i] .p_vaddr , wri (phdrs[i] .p_paddr , phdrAddress));
1063- wri (phdrs[i] .p_filesz , wri (phdrs[i] .p_memsz , phdrs.size () * sizeof (Elf_Phdr)));
1059+ for (auto phdr : phdrs) {
1060+ if (rdi (phdr .p_type ) == PT_PHDR) {
1061+ phdr .p_offset = hdr->e_phoff ;
1062+ wri (phdr .p_vaddr , wri (phdr .p_paddr , phdrAddress));
1063+ wri (phdr .p_filesz , wri (phdr .p_memsz , phdrs.size () * sizeof (Elf_Phdr)));
10641064 break ;
10651065 }
10661066 }
0 commit comments