Lines Matching refs:shdr_info

406   struct shdr_info  in handle_elf()  struct
422 } *shdr_info = NULL; in handle_elf() local
582 if ((shnum + 2) * sizeof (struct shdr_info) > MAX_STACK_ALLOC) in handle_elf()
583 shdr_info = (struct shdr_info *) xcalloc (shnum + 2, in handle_elf()
584 sizeof (struct shdr_info)); in handle_elf()
587 shdr_info = (struct shdr_info *) alloca ((shnum + 2) in handle_elf()
588 * sizeof (struct shdr_info)); in handle_elf()
589 memset (shdr_info, '\0', (shnum + 2) * sizeof (struct shdr_info)); in handle_elf()
601 shdr_info[cnt].scn = scn; in handle_elf()
604 if (gelf_getshdr (scn, &shdr_info[cnt].shdr) == NULL) in handle_elf()
608 shdr_info[cnt].name = elf_strptr (elf, shstrndx, in handle_elf()
609 shdr_info[cnt].shdr.sh_name); in handle_elf()
610 if (shdr_info[cnt].name == NULL) in handle_elf()
618 shdr_info[cnt].idx = 1; in handle_elf()
621 shdr_info[cnt].old_sh_link = shdr_info[cnt].shdr.sh_link; in handle_elf()
622 if (shdr_info[cnt].old_sh_link >= shnum) in handle_elf()
629 || (shdr_info[cnt].shdr.sh_flags & SHF_ALLOC) == 0) in handle_elf()
630 shdr_info[cnt].shdr.sh_offset = 0; in handle_elf()
634 if (unlikely (shdr_info[cnt].shdr.sh_type == SHT_SYMTAB_SHNDX)) in handle_elf()
636 elf_assert (shdr_info[shdr_info[cnt].shdr.sh_link].symtab_idx == 0); in handle_elf()
637 shdr_info[shdr_info[cnt].shdr.sh_link].symtab_idx = cnt; in handle_elf()
639 else if (unlikely (shdr_info[cnt].shdr.sh_type == SHT_GROUP)) in handle_elf()
643 shdr_info[cnt].data = elf_getdata (shdr_info[cnt].scn, NULL); in handle_elf()
644 if (shdr_info[cnt].data == NULL) in handle_elf()
648 Elf32_Word *grpref = (Elf32_Word *) shdr_info[cnt].data->d_buf; in handle_elf()
651 inner < shdr_info[cnt].data->d_size / sizeof (Elf32_Word); in handle_elf()
655 shdr_info[grpref[inner]].group_idx = cnt; in handle_elf()
663 shdr_info[cnt].idx = 0; in handle_elf()
665 shdr_info[cnt].group_cnt = inner - 1; in handle_elf()
667 else if (unlikely (shdr_info[cnt].shdr.sh_type == SHT_GNU_versym)) in handle_elf()
669 elf_assert (shdr_info[shdr_info[cnt].shdr.sh_link].version_idx == 0); in handle_elf()
670 shdr_info[shdr_info[cnt].shdr.sh_link].version_idx = cnt; in handle_elf()
675 if ((shdr_info[cnt].shdr.sh_flags & SHF_GROUP) != 0) in handle_elf()
677 elf_assert (shdr_info[cnt].group_idx != 0); in handle_elf()
679 if (shdr_info[shdr_info[cnt].group_idx].idx == 0) in handle_elf()
682 shdr_info[cnt].group_idx = 0; in handle_elf()
683 shdr_info[cnt].shdr.sh_flags &= ~SHF_GROUP; in handle_elf()
703 if (remove_shdrs ? !(shdr_info[cnt].shdr.sh_flags & SHF_ALLOC) in handle_elf()
704 : ebl_section_strip_p (ebl, ehdr, &shdr_info[cnt].shdr, in handle_elf()
705 shdr_info[cnt].name, remove_comment, in handle_elf()
709 shdr_info[cnt].idx = 0; in handle_elf()
711 idx = shdr_info[cnt].group_idx; in handle_elf()
715 assert (shdr_info[idx].data != NULL); in handle_elf()
720 bool is_comdat = (((Elf32_Word *) shdr_info[idx].data->d_buf)[0] in handle_elf()
723 --shdr_info[idx].group_cnt; in handle_elf()
724 if ((!is_comdat && shdr_info[idx].group_cnt == 1) in handle_elf()
725 || (is_comdat && shdr_info[idx].group_cnt == 0)) in handle_elf()
727 shdr_info[idx].idx = 0; in handle_elf()
729 idx = shdr_info[idx].group_idx; in handle_elf()
737 shdr_info[0].idx = 2; in handle_elf()
749 if (shdr_info[cnt].idx == 0) in handle_elf()
753 if (shdr_info[cnt].shdr.sh_type == SHT_REL in handle_elf()
754 || shdr_info[cnt].shdr.sh_type == SHT_RELA) in handle_elf()
756 if (shdr_info[cnt].shdr.sh_info >= shnum) in handle_elf()
758 else if (shdr_info[shdr_info[cnt].shdr.sh_info].idx != 0) in handle_elf()
759 shdr_info[cnt].idx = 1; in handle_elf()
764 if (shdr_info[cnt].shdr.sh_type == SHT_GROUP) in handle_elf()
767 grpref = (Elf32_Word *) shdr_info[cnt].data->d_buf; in handle_elf()
769 in < shdr_info[cnt].data->d_size / sizeof (Elf32_Word); in handle_elf()
771 if (shdr_info[grpref[in]].idx != 0) in handle_elf()
773 shdr_info[cnt].idx = 1; in handle_elf()
779 if (shdr_info[cnt].idx == 1) in handle_elf()
785 && shdr_info[cnt].debug_data == NULL in handle_elf()
786 && (shdr_info[cnt].shdr.sh_type == SHT_DYNSYM in handle_elf()
787 || shdr_info[cnt].shdr.sh_type == SHT_SYMTAB)) in handle_elf()
790 if (shdr_info[cnt].data == NULL) in handle_elf()
792 shdr_info[cnt].data in handle_elf()
793 = elf_getdata (shdr_info[cnt].scn, NULL); in handle_elf()
794 if (shdr_info[cnt].data == NULL) in handle_elf()
797 Elf_Data *symdata = shdr_info[cnt].data; in handle_elf()
801 if (shdr_info[cnt].symtab_idx != 0 in handle_elf()
802 && shdr_info[shdr_info[cnt].symtab_idx].data == NULL) in handle_elf()
804 elf_assert (shdr_info[cnt].shdr.sh_type == SHT_SYMTAB); in handle_elf()
806 shdr_info[shdr_info[cnt].symtab_idx].data in handle_elf()
807 = elf_getdata (shdr_info[shdr_info[cnt].symtab_idx].scn, in handle_elf()
809 if (shdr_info[shdr_info[cnt].symtab_idx].data == NULL) in handle_elf()
813 = shdr_info[shdr_info[cnt].symtab_idx].data; in handle_elf()
821 inner < shdr_info[cnt].data->d_size / elsize; in handle_elf()
847 if (shdr_info[scnidx].idx == 0) in handle_elf()
851 shdr_info[cnt].debug_data = symdata; in handle_elf()
870 if (shdr_info[shdr_info[cnt].shdr.sh_link].idx == 0) in handle_elf()
872 shdr_info[shdr_info[cnt].shdr.sh_link].idx = 1; in handle_elf()
873 changes |= shdr_info[cnt].shdr.sh_link < cnt; in handle_elf()
877 if (SH_INFO_LINK_P (&shdr_info[cnt].shdr)) in handle_elf()
879 if (shdr_info[cnt].shdr.sh_info >= shnum) in handle_elf()
881 else if ( shdr_info[shdr_info[cnt].shdr.sh_info].idx == 0) in handle_elf()
883 shdr_info[shdr_info[cnt].shdr.sh_info].idx = 1; in handle_elf()
884 changes |= shdr_info[cnt].shdr.sh_info < cnt; in handle_elf()
889 shdr_info[cnt].idx = 2; in handle_elf()
893 && (shdr_info[cnt].idx == 0 || shdr_info[cnt].debug_data != NULL)) in handle_elf()
905 if (i != 0 && shdr_info[i].idx != 0 in handle_elf()
906 && shdr_info[i].debug_data == NULL) in handle_elf()
908 if (shdr_info[i].data == NULL) in handle_elf()
909 shdr_info[i].data = elf_getdata (shdr_info[i].scn, NULL); in handle_elf()
910 if (shdr_info[i].data == NULL) in handle_elf()
913 shdr_info[i].debug_data = shdr_info[i].data; in handle_elf()
918 check_preserved (shdr_info[cnt].shdr.sh_link); in handle_elf()
919 if (SH_INFO_LINK_P (&shdr_info[cnt].shdr)) in handle_elf()
920 check_preserved (shdr_info[cnt].shdr.sh_info); in handle_elf()
938 bool discard_section = (shdr_info[cnt].idx > 0 in handle_elf()
939 && shdr_info[cnt].debug_data == NULL in handle_elf()
940 && shdr_info[cnt].shdr.sh_type != SHT_NOTE in handle_elf()
941 && shdr_info[cnt].shdr.sh_type != SHT_GROUP in handle_elf()
945 GElf_Shdr debugshdr = shdr_info[cnt].shdr; in handle_elf()
954 if (shdr_info[cnt].data == NULL) in handle_elf()
956 shdr_info[cnt].data = elf_getdata (shdr_info[cnt].scn, NULL); in handle_elf()
957 if (shdr_info[cnt].data == NULL) in handle_elf()
968 *debugdata = *shdr_info[cnt].data; in handle_elf()
971 else if (shdr_info[cnt].debug_data != NULL in handle_elf()
972 || shdr_info[cnt].shdr.sh_type == SHT_GROUP) in handle_elf()
975 shdr_info[cnt].debug_data = debugdata; in handle_elf()
1006 shdr_info[shstrndx].idx = 0; in handle_elf()
1015 shdr_info[0].idx = 0; in handle_elf()
1017 if (shdr_info[cnt].idx > 0) in handle_elf()
1019 shdr_info[cnt].idx = idx++; in handle_elf()
1022 shdr_info[cnt].newscn = elf_newscn (newelf); in handle_elf()
1023 if (shdr_info[cnt].newscn == NULL) in handle_elf()
1027 elf_assert (elf_ndxscn (shdr_info[cnt].newscn) == shdr_info[cnt].idx); in handle_elf()
1030 shdr_info[cnt].se = ebl_strtabadd (shst, shdr_info[cnt].name, 0); in handle_elf()
1042 shdr_info[cnt].se = ebl_strtabadd (shst, ".gnu_debuglink", 15); in handle_elf()
1043 shdr_info[cnt].idx = idx++; in handle_elf()
1046 shdr_info[cnt].shdr.sh_type = SHT_PROGBITS; in handle_elf()
1047 shdr_info[cnt].shdr.sh_flags = 0; in handle_elf()
1048 shdr_info[cnt].shdr.sh_addr = 0; in handle_elf()
1049 shdr_info[cnt].shdr.sh_link = SHN_UNDEF; in handle_elf()
1050 shdr_info[cnt].shdr.sh_info = SHN_UNDEF; in handle_elf()
1051 shdr_info[cnt].shdr.sh_entsize = 0; in handle_elf()
1052 shdr_info[cnt].shdr.sh_addralign = 4; in handle_elf()
1056 shdr_info[cnt].shdr.sh_offset = 0; in handle_elf()
1059 shdr_info[cnt].newscn = elf_newscn (newelf); in handle_elf()
1060 if (shdr_info[cnt].newscn == NULL) in handle_elf()
1064 elf_assert (elf_ndxscn (shdr_info[cnt].newscn) == shdr_info[cnt].idx); in handle_elf()
1066 shdr_info[cnt].data = elf_newdata (shdr_info[cnt].newscn); in handle_elf()
1067 if (shdr_info[cnt].data == NULL) in handle_elf()
1076 shdr_info[cnt].data->d_align = 4; in handle_elf()
1077 shdr_info[cnt].shdr.sh_size = shdr_info[cnt].data->d_size in handle_elf()
1079 debuglink_buf = xcalloc (1, shdr_info[cnt].data->d_size); in handle_elf()
1080 shdr_info[cnt].data->d_buf = debuglink_buf; in handle_elf()
1082 strcpy (shdr_info[cnt].data->d_buf, debug_basename); in handle_elf()
1086 debuglink_crc_data = *shdr_info[cnt].data; in handle_elf()
1099 shdr_info[cnt].se = ebl_strtabadd (shst, ".shstrtab", 10); in handle_elf()
1100 shdr_info[cnt].idx = idx; in handle_elf()
1103 shdr_info[cnt].shdr.sh_type = SHT_STRTAB; in handle_elf()
1104 shdr_info[cnt].shdr.sh_flags = 0; in handle_elf()
1105 shdr_info[cnt].shdr.sh_addr = 0; in handle_elf()
1106 shdr_info[cnt].shdr.sh_link = SHN_UNDEF; in handle_elf()
1107 shdr_info[cnt].shdr.sh_info = SHN_UNDEF; in handle_elf()
1108 shdr_info[cnt].shdr.sh_entsize = 0; in handle_elf()
1112 shdr_info[cnt].shdr.sh_offset = 0; in handle_elf()
1113 shdr_info[cnt].shdr.sh_addralign = 1; in handle_elf()
1116 shdr_info[cnt].newscn = elf_newscn (newelf); in handle_elf()
1117 if (shdr_info[cnt].newscn == NULL) in handle_elf()
1121 elf_assert (elf_ndxscn (shdr_info[cnt].newscn) == idx); in handle_elf()
1125 shstrtab_data = elf_newdata (shdr_info[cnt].newscn); in handle_elf()
1133 shdr_info[cnt].shdr.sh_size = shstrtab_data->d_size; in handle_elf()
1138 if (shdr_info[cnt].idx > 0) in handle_elf()
1142 scn = elf_getscn (newelf, shdr_info[cnt].idx); in handle_elf()
1146 shdr_info[cnt].shdr.sh_name = ebl_strtaboffset (shdr_info[cnt].se); in handle_elf()
1150 if (shdr_info[cnt].shdr.sh_link != 0) in handle_elf()
1151 shdr_info[cnt].shdr.sh_link = in handle_elf()
1152 shdr_info[shdr_info[cnt].shdr.sh_link].idx; in handle_elf()
1154 if (shdr_info[cnt].shdr.sh_type == SHT_GROUP) in handle_elf()
1156 assert (shdr_info[cnt].data != NULL); in handle_elf()
1158 Elf32_Word *grpref = (Elf32_Word *) shdr_info[cnt].data->d_buf; in handle_elf()
1160 inner < shdr_info[cnt].data->d_size / sizeof (Elf32_Word); in handle_elf()
1162 grpref[inner] = shdr_info[grpref[inner]].idx; in handle_elf()
1166 if (SH_INFO_LINK_P (&shdr_info[cnt].shdr)) in handle_elf()
1167 shdr_info[cnt].shdr.sh_info = in handle_elf()
1168 shdr_info[shdr_info[cnt].shdr.sh_info].idx; in handle_elf()
1174 if (shdr_info[cnt].data == NULL) in handle_elf()
1176 shdr_info[cnt].data = elf_getdata (shdr_info[cnt].scn, NULL); in handle_elf()
1177 if (shdr_info[cnt].data == NULL) in handle_elf()
1187 *newdata = *shdr_info[cnt].data; in handle_elf()
1190 shdr_info[cnt].shdr.sh_size = shdr_info[cnt].data->d_size; in handle_elf()
1194 if (shdr_info[cnt].shdr.sh_type == SHT_DYNSYM in handle_elf()
1195 || shdr_info[cnt].shdr.sh_type == SHT_SYMTAB) in handle_elf()
1203 if (shdr_info[cnt].symtab_idx != 0) in handle_elf()
1205 assert (shdr_info[cnt].shdr.sh_type == SHT_SYMTAB_SHNDX); in handle_elf()
1208 shndxdata = elf_getdata (shdr_info[shdr_info[cnt].symtab_idx].scn, in handle_elf()
1212 >= shdr_info[cnt].data->d_size / elsize); in handle_elf()
1215 if (shdr_info[cnt].version_idx != 0) in handle_elf()
1217 elf_assert (shdr_info[cnt].shdr.sh_type == SHT_DYNSYM); in handle_elf()
1221 versiondata = elf_getdata (shdr_info[shdr_info[cnt].version_idx].scn, in handle_elf()
1225 >= shdr_info[cnt].data->d_size / elsize); in handle_elf()
1228 shdr_info[cnt].newsymidx in handle_elf()
1229 = (Elf32_Word *) xcalloc (shdr_info[cnt].data->d_size in handle_elf()
1236 inner < shdr_info[cnt].data->d_size / elsize; in handle_elf()
1242 GElf_Sym *sym = gelf_getsymshndx (shdr_info[cnt].data, in handle_elf()
1255 && gelf_update_symshndx (shdr_info[cnt].data, in handle_elf()
1261 shdr_info[cnt].newsymidx[inner] = destidx++; in handle_elf()
1267 shdr_info[cnt].shdr.sh_info = destidx - 1; in handle_elf()
1276 sec = shdr_info[sym->st_shndx].idx; in handle_elf()
1281 sec = shdr_info[xshndx].idx; in handle_elf()
1305 gelf_update_symshndx (shdr_info[cnt].data, in handle_elf()
1311 shdr_info[cnt].newsymidx[inner] = destidx++; in handle_elf()
1317 shdr_info[cnt].shdr.sh_info = destidx - 1; in handle_elf()
1321 || shdr_info[cnt].debug_data == NULL) in handle_elf()
1328 || ((shdr_info[sidx].shdr.sh_type in handle_elf()
1330 && (shdr_info[sidx].shdr.sh_info in handle_elf()
1338 shdr_info[cnt].shdr.sh_size = newdata->d_size in handle_elf()
1345 free (shdr_info[cnt].newsymidx); in handle_elf()
1346 shdr_info[cnt].newsymidx = NULL; in handle_elf()
1352 if (shdr_info[cnt].shdr.sh_offset == 0) in handle_elf()
1353 shdr_info[cnt].shdr.sh_offset in handle_elf()
1354 = ((lastoffset + shdr_info[cnt].shdr.sh_addralign - 1) in handle_elf()
1355 & ~((GElf_Off) (shdr_info[cnt].shdr.sh_addralign - 1))); in handle_elf()
1358 if (unlikely (gelf_update_shdr (scn, &shdr_info[cnt].shdr) == 0)) in handle_elf()
1363 GElf_Off filesz = (shdr_info[cnt].shdr.sh_type != SHT_NOBITS in handle_elf()
1364 ? shdr_info[cnt].shdr.sh_size : 0); in handle_elf()
1365 if (lastoffset < shdr_info[cnt].shdr.sh_offset + filesz) in handle_elf()
1366 lastoffset = shdr_info[cnt].shdr.sh_offset + filesz; in handle_elf()
1392 if (shdr_info[cnt].idx == 0 && debug_fname == NULL) in handle_elf()
1398 const Elf32_Word symtabidx = shdr_info[cnt].old_sh_link; in handle_elf()
1399 const Elf32_Word *const newsymidx = shdr_info[symtabidx].newsymidx; in handle_elf()
1400 switch (shdr_info[cnt].shdr.sh_type) in handle_elf()
1405 if (shdr_info[symtabidx].newsymidx == NULL) in handle_elf()
1411 return (shdr_info[cnt].idx == 0 in handle_elf()
1412 && shdr_info[symtabidx].debug_data != NULL); in handle_elf()
1420 Elf_Data *d = elf_getdata (shdr_info[cnt].idx == 0 in handle_elf()
1423 shdr_info[cnt].idx), in handle_elf()
1426 size_t nrels = (shdr_info[cnt].shdr.sh_size in handle_elf()
1427 / shdr_info[cnt].shdr.sh_entsize); in handle_elf()
1429 if (shdr_info[cnt].shdr.sh_type == SHT_REL) in handle_elf()
1473 assert (shdr_info[cnt].idx > 0); in handle_elf()
1476 scn = elf_getscn (newelf, shdr_info[cnt].idx); in handle_elf()
1480 shdr_info[symtabidx].idx), in handle_elf()
1488 if (shdr_info[cnt].shdr.sh_entsize == sizeof (Elf32_Word)) in handle_elf()
1493 size_t strshndx = shdr_info[symtabidx].old_sh_link; in handle_elf()
1514 for (size_t inner = shdr_info[symtabidx].shdr.sh_info; in handle_elf()
1542 elf_assert (shdr_info[cnt].shdr.sh_entsize in handle_elf()
1547 size_t strshndx = shdr_info[symtabidx].old_sh_link; in handle_elf()
1568 for (size_t inner = shdr_info[symtabidx].shdr.sh_info; in handle_elf()
1600 assert (shdr_info[cnt].idx > 0); in handle_elf()
1603 scn = elf_getscn (newelf, shdr_info[cnt].idx); in handle_elf()
1606 symd = elf_getdata (elf_getscn (newelf, shdr_info[symtabidx].idx), in handle_elf()
1642 scn = elf_getscn (newelf, shdr_info[cnt].idx); in handle_elf()
1702 symdata = (shdr_info[symt].debug_data in handle_elf()
1703 ?: shdr_info[symt].data); in handle_elf()
1704 xndxdata = (shdr_info[shdr_info[symt].symtab_idx].debug_data in handle_elf()
1705 ?: shdr_info[shdr_info[symt].symtab_idx].data); in handle_elf()
1734 if (ebl_debugscn_p (ebl, shdr_info[sec].name)) in handle_elf()
1938 newehdr->e_shoff = ((shdr_info[shdridx].shdr.sh_offset in handle_elf()
1939 + shdr_info[shdridx].shdr.sh_size + offsize - 1) in handle_elf()
1949 shdr_info[0].scn = elf_getscn (elf, 0); in handle_elf()
1951 if (gelf_getshdr (shdr_info[0].scn, &shdr_info[0].shdr) == NULL) in handle_elf()
1954 shdr_info[0].shdr.sh_link = idx; in handle_elf()
1955 (void) gelf_update_shdr (shdr_info[0].scn, &shdr_info[0].shdr); in handle_elf()
2007 || ftruncate64 (fd, shdr_info[shdridx].shdr.sh_offset) < 0) in handle_elf()
2027 || ftruncate64 (fd, shdr_info[shdridx].shdr.sh_offset) < 0) in handle_elf()
2037 if (shdr_info != NULL) in handle_elf()
2044 free (shdr_info[cnt].newsymidx); in handle_elf()
2045 if (shdr_info[cnt].debug_data != NULL) in handle_elf()
2046 free (shdr_info[cnt].debug_data->d_buf); in handle_elf()
2053 if ((shnum + 2) * sizeof (struct shdr_info) > MAX_STACK_ALLOC) in handle_elf()
2054 free (shdr_info); in handle_elf()