Lines Matching refs:cnt

432   size_t cnt;
532 for (cnt = 0; cnt < ehdr->e_phnum; ++cnt)
535 GElf_Phdr *phdr = gelf_getphdr (elf, cnt, &phdr_mem);
537 || unlikely (gelf_update_phdr (newelf, cnt, phdr) == 0))
556 for (cnt = 0; cnt < ehdr->e_phnum; ++cnt)
559 GElf_Phdr *phdr = gelf_getphdr (elf, cnt, &phdr_mem);
561 || unlikely (gelf_update_phdr (debugelf, cnt, phdr) == 0))
591 cnt = 1;
596 assert (elf_ndxscn (scn) == cnt);
598 shdr_info[cnt].scn = scn;
601 if (gelf_getshdr (scn, &shdr_info[cnt].shdr) == NULL)
605 shdr_info[cnt].name = elf_strptr (elf, shstrndx,
606 shdr_info[cnt].shdr.sh_name);
607 if (shdr_info[cnt].name == NULL)
614 shdr_info[cnt].idx = 1;
617 shdr_info[cnt].old_sh_link = shdr_info[cnt].shdr.sh_link;
623 || (shdr_info[cnt].shdr.sh_flags & SHF_ALLOC) == 0)
624 shdr_info[cnt].shdr.sh_offset = 0;
628 if (unlikely (shdr_info[cnt].shdr.sh_type == SHT_SYMTAB_SHNDX))
630 assert (shdr_info[shdr_info[cnt].shdr.sh_link].symtab_idx == 0);
631 shdr_info[shdr_info[cnt].shdr.sh_link].symtab_idx = cnt;
633 else if (unlikely (shdr_info[cnt].shdr.sh_type == SHT_GROUP))
637 shdr_info[cnt].data = elf_getdata (shdr_info[cnt].scn, NULL);
638 if (shdr_info[cnt].data == NULL)
642 Elf32_Word *grpref = (Elf32_Word *) shdr_info[cnt].data->d_buf;
645 inner < shdr_info[cnt].data->d_size / sizeof (Elf32_Word);
647 shdr_info[grpref[inner]].group_idx = cnt;
652 shdr_info[cnt].idx = 0;
654 shdr_info[cnt].group_cnt = inner - 1;
656 else if (unlikely (shdr_info[cnt].shdr.sh_type == SHT_GNU_versym))
658 assert (shdr_info[shdr_info[cnt].shdr.sh_link].version_idx == 0);
659 shdr_info[shdr_info[cnt].shdr.sh_link].version_idx = cnt;
664 if ((shdr_info[cnt].shdr.sh_flags & SHF_GROUP) != 0)
666 assert (shdr_info[cnt].group_idx != 0);
668 if (shdr_info[shdr_info[cnt].group_idx].idx == 0)
671 shdr_info[cnt].group_idx = 0;
672 shdr_info[cnt].shdr.sh_flags &= ~SHF_GROUP;
677 ++cnt;
690 for (cnt = 1; cnt < shnum; ++cnt)
692 if (remove_shdrs ? !(shdr_info[cnt].shdr.sh_flags & SHF_ALLOC)
693 : ebl_section_strip_p (ebl, ehdr, &shdr_info[cnt].shdr,
694 shdr_info[cnt].name, remove_comment,
698 shdr_info[cnt].idx = 0;
700 idx = shdr_info[cnt].group_idx;
736 for (cnt = 1; cnt < shnum; ++cnt)
738 if (shdr_info[cnt].idx == 0)
742 if ((shdr_info[cnt].shdr.sh_type == SHT_REL
743 || shdr_info[cnt].shdr.sh_type == SHT_RELA)
744 && shdr_info[shdr_info[cnt].shdr.sh_info].idx != 0)
745 shdr_info[cnt].idx = 1;
749 if (shdr_info[cnt].shdr.sh_type == SHT_GROUP)
752 grpref = (Elf32_Word *) shdr_info[cnt].data->d_buf;
754 in < shdr_info[cnt].data->d_size / sizeof (Elf32_Word);
758 shdr_info[cnt].idx = 1;
764 if (shdr_info[cnt].idx == 1)
770 && shdr_info[cnt].debug_data == NULL
771 && (shdr_info[cnt].shdr.sh_type == SHT_DYNSYM
772 || shdr_info[cnt].shdr.sh_type == SHT_SYMTAB))
775 if (shdr_info[cnt].data == NULL)
777 shdr_info[cnt].data
778 = elf_getdata (shdr_info[cnt].scn, NULL);
779 if (shdr_info[cnt].data == NULL)
782 Elf_Data *symdata = shdr_info[cnt].data;
786 if (shdr_info[cnt].symtab_idx != 0
787 && shdr_info[shdr_info[cnt].symtab_idx].data == NULL)
789 assert (shdr_info[cnt].shdr.sh_type == SHT_SYMTAB);
791 shdr_info[shdr_info[cnt].symtab_idx].data
792 = elf_getdata (shdr_info[shdr_info[cnt].symtab_idx].scn,
794 if (shdr_info[shdr_info[cnt].symtab_idx].data == NULL)
798 = shdr_info[shdr_info[cnt].symtab_idx].data;
806 inner < shdr_info[cnt].data->d_size / elsize;
833 shdr_info[cnt].debug_data = symdata;
852 if (shdr_info[shdr_info[cnt].shdr.sh_link].idx == 0)
854 shdr_info[shdr_info[cnt].shdr.sh_link].idx = 1;
855 changes |= shdr_info[cnt].shdr.sh_link < cnt;
859 if (SH_INFO_LINK_P (&shdr_info[cnt].shdr)
860 && shdr_info[shdr_info[cnt].shdr.sh_info].idx == 0)
862 shdr_info[shdr_info[cnt].shdr.sh_info].idx = 1;
863 changes |= shdr_info[cnt].shdr.sh_info < cnt;
867 shdr_info[cnt].idx = 2;
871 && (shdr_info[cnt].idx == 0 || shdr_info[cnt].debug_data != NULL))
892 changes |= i < cnt;
896 check_preserved (shdr_info[cnt].shdr.sh_link);
897 if (SH_INFO_LINK_P (&shdr_info[cnt].shdr))
898 check_preserved (shdr_info[cnt].shdr.sh_info);
908 for (cnt = 1; cnt < shnum; ++cnt)
916 bool discard_section = (shdr_info[cnt].idx > 0
917 && shdr_info[cnt].debug_data == NULL
918 && shdr_info[cnt].shdr.sh_type != SHT_NOTE
919 && shdr_info[cnt].shdr.sh_type != SHT_GROUP
920 && cnt != ehdr->e_shstrndx);
923 GElf_Shdr debugshdr = shdr_info[cnt].shdr;
932 if (shdr_info[cnt].data == NULL)
934 shdr_info[cnt].data = elf_getdata (shdr_info[cnt].scn, NULL);
935 if (shdr_info[cnt].data == NULL)
946 *debugdata = *shdr_info[cnt].data;
949 else if (shdr_info[cnt].debug_data != NULL
950 || shdr_info[cnt].shdr.sh_type == SHT_GROUP)
953 shdr_info[cnt].debug_data = debugdata;
994 for (cnt = idx = 1; cnt < shnum; ++cnt)
995 if (shdr_info[cnt].idx > 0)
997 shdr_info[cnt].idx = idx++;
1000 shdr_info[cnt].newscn = elf_newscn (newelf);
1001 if (shdr_info[cnt].newscn == NULL)
1005 assert (elf_ndxscn (shdr_info[cnt].newscn) == shdr_info[cnt].idx);
1008 shdr_info[cnt].se = ebl_strtabadd (shst, shdr_info[cnt].name, 0);
1012 if (cnt == idx)
1020 shdr_info[cnt].se = ebl_strtabadd (shst, ".gnu_debuglink", 15);
1021 shdr_info[cnt].idx = idx++;
1024 shdr_info[cnt].shdr.sh_type = SHT_PROGBITS;
1025 shdr_info[cnt].shdr.sh_flags = 0;
1026 shdr_info[cnt].shdr.sh_addr = 0;
1027 shdr_info[cnt].shdr.sh_link = SHN_UNDEF;
1028 shdr_info[cnt].shdr.sh_info = SHN_UNDEF;
1029 shdr_info[cnt].shdr.sh_entsize = 0;
1030 shdr_info[cnt].shdr.sh_addralign = 4;
1034 shdr_info[cnt].shdr.sh_offset = 0;
1037 shdr_info[cnt].newscn = elf_newscn (newelf);
1038 if (shdr_info[cnt].newscn == NULL)
1042 assert (elf_ndxscn (shdr_info[cnt].newscn) == shdr_info[cnt].idx);
1044 shdr_info[cnt].data = elf_newdata (shdr_info[cnt].newscn);
1045 if (shdr_info[cnt].data == NULL)
1054 shdr_info[cnt].data->d_align = 4;
1055 shdr_info[cnt].shdr.sh_size = shdr_info[cnt].data->d_size
1057 shdr_info[cnt].data->d_buf = xcalloc (1, shdr_info[cnt].data->d_size);
1059 strcpy (shdr_info[cnt].data->d_buf, debug_basename);
1063 debuglink_crc_data = *shdr_info[cnt].data;
1069 ++cnt;
1073 shdridx = cnt;
1076 shdr_info[cnt].se = ebl_strtabadd (shst, ".shstrtab", 10);
1077 shdr_info[cnt].idx = idx;
1080 shdr_info[cnt].shdr.sh_type = SHT_STRTAB;
1081 shdr_info[cnt].shdr.sh_flags = 0;
1082 shdr_info[cnt].shdr.sh_addr = 0;
1083 shdr_info[cnt].shdr.sh_link = SHN_UNDEF;
1084 shdr_info[cnt].shdr.sh_info = SHN_UNDEF;
1085 shdr_info[cnt].shdr.sh_entsize = 0;
1089 shdr_info[cnt].shdr.sh_offset = 0;
1090 shdr_info[cnt].shdr.sh_addralign = 1;
1093 shdr_info[cnt].newscn = elf_newscn (newelf);
1094 if (shdr_info[cnt].newscn == NULL)
1098 assert (elf_ndxscn (shdr_info[cnt].newscn) == idx);
1102 shstrtab_data = elf_newdata (shdr_info[cnt].newscn);
1110 shdr_info[cnt].shdr.sh_size = shstrtab_data->d_size;
1114 for (cnt = 1; cnt <= shdridx; ++cnt)
1115 if (shdr_info[cnt].idx > 0)
1119 scn = elf_getscn (newelf, shdr_info[cnt].idx);
1123 shdr_info[cnt].shdr.sh_name = ebl_strtaboffset (shdr_info[cnt].se);
1127 if (shdr_info[cnt].shdr.sh_link != 0)
1128 shdr_info[cnt].shdr.sh_link =
1129 shdr_info[shdr_info[cnt].shdr.sh_link].idx;
1131 if (shdr_info[cnt].shdr.sh_type == SHT_GROUP)
1133 assert (shdr_info[cnt].data != NULL);
1135 Elf32_Word *grpref = (Elf32_Word *) shdr_info[cnt].data->d_buf;
1137 inner < shdr_info[cnt].data->d_size / sizeof (Elf32_Word);
1143 if (SH_INFO_LINK_P (&shdr_info[cnt].shdr))
1144 shdr_info[cnt].shdr.sh_info =
1145 shdr_info[shdr_info[cnt].shdr.sh_info].idx;
1149 if (cnt < shnum)
1151 if (shdr_info[cnt].data == NULL)
1153 shdr_info[cnt].data = elf_getdata (shdr_info[cnt].scn, NULL);
1154 if (shdr_info[cnt].data == NULL)
1164 *newdata = *shdr_info[cnt].data;
1167 shdr_info[cnt].shdr.sh_size = shdr_info[cnt].data->d_size;
1171 if (shdr_info[cnt].shdr.sh_type == SHT_DYNSYM
1172 || shdr_info[cnt].shdr.sh_type == SHT_SYMTAB)
1180 if (shdr_info[cnt].symtab_idx != 0)
1182 assert (shdr_info[cnt].shdr.sh_type == SHT_SYMTAB_SHNDX);
1185 shndxdata = elf_getdata (shdr_info[shdr_info[cnt].symtab_idx].scn,
1189 >= shdr_info[cnt].data->d_size / elsize);
1192 if (shdr_info[cnt].version_idx != 0)
1194 assert (shdr_info[cnt].shdr.sh_type == SHT_DYNSYM);
1198 versiondata = elf_getdata (shdr_info[shdr_info[cnt].version_idx].scn,
1202 >= shdr_info[cnt].data->d_size / elsize);
1205 shdr_info[cnt].newsymidx
1206 = (Elf32_Word *) xcalloc (shdr_info[cnt].data->d_size
1213 inner < shdr_info[cnt].data->d_size / elsize;
1219 GElf_Sym *sym = gelf_getsymshndx (shdr_info[cnt].data,
1232 && gelf_update_symshndx (shdr_info[cnt].data,
1238 shdr_info[cnt].newsymidx[inner] = destidx++;
1244 shdr_info[cnt].shdr.sh_info = destidx - 1;
1282 gelf_update_symshndx (shdr_info[cnt].data,
1288 shdr_info[cnt].newsymidx[inner] = destidx++;
1294 shdr_info[cnt].shdr.sh_info = destidx - 1;
1298 || shdr_info[cnt].debug_data == NULL)
1313 shdr_info[cnt].shdr.sh_size = newdata->d_size
1320 free (shdr_info[cnt].newsymidx);
1321 shdr_info[cnt].newsymidx = NULL;
1327 if (shdr_info[cnt].shdr.sh_offset == 0)
1328 shdr_info[cnt].shdr.sh_offset
1329 = ((lastoffset + shdr_info[cnt].shdr.sh_addralign - 1)
1330 & ~((GElf_Off) (shdr_info[cnt].shdr.sh_addralign - 1)));
1333 if (unlikely (gelf_update_shdr (scn, &shdr_info[cnt].shdr) == 0))
1338 GElf_Off filesz = (shdr_info[cnt].shdr.sh_type != SHT_NOBITS
1339 ? shdr_info[cnt].shdr.sh_size : 0);
1340 if (lastoffset < shdr_info[cnt].shdr.sh_offset + filesz)
1341 lastoffset = shdr_info[cnt].shdr.sh_offset + filesz;
1347 for (cnt = 1; cnt <= shdridx; ++cnt)
1362 cnt), NULL);
1367 if (shdr_info[cnt].idx == 0 && debug_fname == NULL)
1373 const Elf32_Word symtabidx = shdr_info[cnt].old_sh_link;
1375 switch (shdr_info[cnt].shdr.sh_type)
1386 return (shdr_info[cnt].idx == 0
1395 Elf_Data *d = elf_getdata (shdr_info[cnt].idx == 0
1396 ? elf_getscn (debugelf, cnt)
1398 shdr_info[cnt].idx),
1401 size_t nrels = (shdr_info[cnt].shdr.sh_size
1402 / shdr_info[cnt].shdr.sh_entsize);
1404 if (shdr_info[cnt].shdr.sh_type == SHT_REL)
1448 assert (shdr_info[cnt].idx > 0);
1451 scn = elf_getscn (newelf, shdr_info[cnt].idx);
1463 if (shdr_info[cnt].shdr.sh_entsize == sizeof (Elf32_Word))
1517 assert (shdr_info[cnt].shdr.sh_entsize
1575 assert (shdr_info[cnt].idx > 0);
1578 scn = elf_getscn (newelf, shdr_info[cnt].idx);
1617 scn = elf_getscn (newelf, shdr_info[cnt].idx);
1635 cnt = 0;
1638 cnt++;
2017 for (cnt = 1; cnt <= shdridx; ++cnt)
2019 free (shdr_info[cnt].newsymidx);
2020 if (shdr_info[cnt].debug_data != NULL)
2021 free (shdr_info[cnt].debug_data->d_buf);