Lines Matching refs:shdr_info
388 struct shdr_info
404 } *shdr_info = NULL;
551 if ((shnum + 2) * sizeof (struct shdr_info) > MAX_STACK_ALLOC)
552 shdr_info = (struct shdr_info *) xcalloc (shnum + 2,
553 sizeof (struct shdr_info));
556 shdr_info = (struct shdr_info *) alloca ((shnum + 2)
557 * sizeof (struct shdr_info));
558 memset (shdr_info, '\0', (shnum + 2) * sizeof (struct shdr_info));
570 shdr_info[cnt].scn = scn;
573 shdr_info[cnt].shdr) == NULL)
577 shdr_info[cnt].name = elf_strptr (elf, shstrndx,
578 shdr_info[cnt].shdr.sh_name);
579 if (shdr_info[cnt].name == NULL)
586 shdr_info[cnt].idx = 1;
589 shdr_info[cnt].old_sh_link = shdr_info[cnt].shdr.sh_link;
595 || (shdr_info[cnt].shdr.sh_flags & SHF_ALLOC) == 0)
596 shdr_info[cnt].shdr.sh_offset = 0;
600 if (unlikely (shdr_info[cnt].shdr.sh_type == SHT_SYMTAB_SHNDX))
602 assert (shdr_info[shdr_info[cnt].shdr.sh_link].symtab_idx == 0);
603 shdr_info[shdr_info[cnt].shdr.sh_link].symtab_idx = cnt;
605 else if (unlikely (shdr_info[cnt].shdr.sh_type == SHT_GROUP))
609 shdr_info[cnt].data = elf_getdata (shdr_info[cnt].scn, NULL);
610 if (shdr_info[cnt].data == NULL)
614 Elf32_Word *grpref = (Elf32_Word *) shdr_info[cnt].data->d_buf;
617 inner < shdr_info[cnt].data->d_size / sizeof (Elf32_Word);
619 shdr_info[grpref[inner]].group_idx = cnt;
624 shdr_info[cnt].idx = 0;
626 shdr_info[cnt].group_cnt = inner - 1;
628 else if (unlikely (shdr_info[cnt].shdr.sh_type == SHT_GNU_versym))
630 assert (shdr_info[shdr_info[cnt].shdr.sh_link].version_idx == 0);
631 shdr_info[shdr_info[cnt].shdr.sh_link].version_idx = cnt;
636 if ((shdr_info[cnt].shdr.sh_flags & SHF_GROUP) != 0)
638 assert (shdr_info[cnt].group_idx != 0);
640 if (shdr_info[shdr_info[cnt].group_idx].idx == 0)
643 shdr_info[cnt].group_idx = 0;
644 shdr_info[cnt].shdr.sh_flags &= ~SHF_GROUP;
664 if (ebl_section_strip_p (ebl, ehdr, &shdr_info[cnt].shdr,
665 shdr_info[cnt].name, remove_comment,
669 shdr_info[cnt].idx = 0;
671 idx = shdr_info[cnt].group_idx;
675 assert (shdr_info[idx].data != NULL);
680 bool is_comdat = (((Elf32_Word *) shdr_info[idx].data->d_buf)[0]
683 --shdr_info[idx].group_cnt;
684 if ((!is_comdat && shdr_info[idx].group_cnt == 1)
685 || (is_comdat && shdr_info[idx].group_cnt == 0))
687 shdr_info[idx].idx = 0;
689 idx = shdr_info[idx].group_idx;
697 shdr_info[0].idx = 2;
709 if (shdr_info[cnt].idx == 0)
713 if ((shdr_info[cnt].shdr.sh_type == SHT_REL
714 || shdr_info[cnt].shdr.sh_type == SHT_RELA)
715 && shdr_info[shdr_info[cnt].shdr.sh_info].idx != 0)
716 shdr_info[cnt].idx = 1;
719 if (shdr_info[cnt].idx == 1)
725 && shdr_info[cnt].debug_data == NULL
726 && (shdr_info[cnt].shdr.sh_type == SHT_DYNSYM
727 || shdr_info[cnt].shdr.sh_type == SHT_SYMTAB))
730 if (shdr_info[cnt].data == NULL)
732 shdr_info[cnt].data
733 = elf_getdata (shdr_info[cnt].scn, NULL);
734 if (shdr_info[cnt].data == NULL)
737 Elf_Data *symdata = shdr_info[cnt].data;
741 if (shdr_info[cnt].symtab_idx != 0
742 && shdr_info[shdr_info[cnt].symtab_idx].data == NULL)
744 assert (shdr_info[cnt].shdr.sh_type == SHT_SYMTAB);
746 shdr_info[shdr_info[cnt].symtab_idx].data
747 = elf_getdata (shdr_info[shdr_info[cnt].symtab_idx].scn,
749 if (shdr_info[shdr_info[cnt].symtab_idx].data == NULL)
753 = shdr_info[shdr_info[cnt].symtab_idx].data;
761 inner < shdr_info[cnt].data->d_size / elsize;
784 if (shdr_info[scnidx].idx == 0)
788 shdr_info[cnt].debug_data = symdata;
807 if (shdr_info[shdr_info[cnt].shdr.sh_link].idx == 0)
809 shdr_info[shdr_info[cnt].shdr.sh_link].idx = 1;
810 changes |= shdr_info[cnt].shdr.sh_link < cnt;
814 if (SH_INFO_LINK_P (&shdr_info[cnt].shdr)
815 && shdr_info[shdr_info[cnt].shdr.sh_info].idx == 0)
817 shdr_info[shdr_info[cnt].shdr.sh_info].idx = 1;
818 changes |= shdr_info[cnt].shdr.sh_info < cnt;
822 shdr_info[cnt].idx = 2;
826 && (shdr_info[cnt].idx == 0 || shdr_info[cnt].debug_data != NULL))
838 if (i != 0 && shdr_info[i].idx != 0)
840 if (shdr_info[i].data == NULL)
841 shdr_info[i].data = elf_getdata (shdr_info[i].scn, NULL);
842 if (shdr_info[i].data == NULL)
845 shdr_info[i].debug_data = shdr_info[i].data;
850 check_preserved (shdr_info[cnt].shdr.sh_link);
851 if (SH_INFO_LINK_P (&shdr_info[cnt].shdr))
852 check_preserved (shdr_info[cnt].shdr.sh_info);
870 bool discard_section = (shdr_info[cnt].idx > 0
871 && shdr_info[cnt].debug_data == NULL
872 && shdr_info[cnt].shdr.sh_type != SHT_NOTE
876 GElf_Shdr debugshdr = shdr_info[cnt].shdr;
885 if (shdr_info[cnt].data == NULL)
887 shdr_info[cnt].data = elf_getdata (shdr_info[cnt].scn, NULL);
888 if (shdr_info[cnt].data == NULL)
899 *debugdata = *shdr_info[cnt].data;
902 else if (shdr_info[cnt].debug_data != NULL)
905 shdr_info[cnt].debug_data = debugdata;
936 shdr_info[shstrndx].idx = 0;
945 shdr_info[0].idx = 0;
947 if (shdr_info[cnt].idx > 0)
949 shdr_info[cnt].idx = idx++;
952 shdr_info[cnt].newscn = elf_newscn (newelf);
953 if (shdr_info[cnt].newscn == NULL)
957 assert (elf_ndxscn (shdr_info[cnt].newscn) == shdr_info[cnt].idx);
960 shdr_info[cnt].se = ebl_strtabadd (shst, shdr_info[cnt].name, 0);
972 shdr_info[cnt].se = ebl_strtabadd (shst, ".gnu_debuglink", 15);
973 shdr_info[cnt].idx = idx++;
976 shdr_info[cnt].shdr.sh_type = SHT_PROGBITS;
977 shdr_info[cnt].shdr.sh_flags = 0;
978 shdr_info[cnt].shdr.sh_addr = 0;
979 shdr_info[cnt].shdr.sh_link = SHN_UNDEF;
980 shdr_info[cnt].shdr.sh_info = SHN_UNDEF;
981 shdr_info[cnt].shdr.sh_entsize = 0;
982 shdr_info[cnt].shdr.sh_addralign = 4;
986 shdr_info[cnt].shdr.sh_offset = 0;
989 shdr_info[cnt].newscn = elf_newscn (newelf);
990 if (shdr_info[cnt].newscn == NULL)
994 assert (elf_ndxscn (shdr_info[cnt].newscn) == shdr_info[cnt].idx);
996 shdr_info[cnt].data = elf_newdata (shdr_info[cnt].newscn);
997 if (shdr_info[cnt].data == NULL)
1006 shdr_info[cnt].data->d_align = 4;
1007 shdr_info[cnt].shdr.sh_size = shdr_info[cnt].data->d_size
1009 shdr_info[cnt].data->d_buf = xcalloc (1, shdr_info[cnt].data->d_size);
1011 strcpy (shdr_info[cnt].data->d_buf, debug_basename);
1015 debuglink_crc_data = *shdr_info[cnt].data;
1024 /* Index of the section header table in the shdr_info array. */
1028 shdr_info[cnt].se = ebl_strtabadd (shst, ".shstrtab", 10);
1029 shdr_info[cnt].idx = idx;
1032 shdr_info[cnt].shdr.sh_type = SHT_STRTAB;
1033 shdr_info[cnt].shdr.sh_flags = 0;
1034 shdr_info[cnt].shdr.sh_addr = 0;
1035 shdr_info[cnt].shdr.sh_link = SHN_UNDEF;
1036 shdr_info[cnt].shdr.sh_info = SHN_UNDEF;
1037 shdr_info[cnt].shdr.sh_entsize = 0;
1041 shdr_info[cnt].shdr.sh_offset = 0;
1042 shdr_info[cnt].shdr.sh_addralign = 1;
1045 shdr_info[cnt].newscn = elf_newscn (newelf);
1046 if (shdr_info[cnt].newscn == NULL)
1050 assert (elf_ndxscn (shdr_info[cnt].newscn) == idx);
1054 shstrtab_data = elf_newdata (shdr_info[cnt].newscn);
1062 shdr_info[cnt].shdr.sh_size = shstrtab_data->d_size;
1067 if (shdr_info[cnt].idx > 0)
1071 scn = elf_getscn (newelf, shdr_info[cnt].idx);
1075 shdr_info[cnt].shdr.sh_name = ebl_strtaboffset (shdr_info[cnt].se);
1079 if (shdr_info[cnt].shdr.sh_link != 0)
1080 shdr_info[cnt].shdr.sh_link =
1081 shdr_info[shdr_info[cnt].shdr.sh_link].idx;
1083 if (shdr_info[cnt].shdr.sh_type == SHT_GROUP)
1085 assert (shdr_info[cnt].data != NULL);
1087 Elf32_Word *grpref = (Elf32_Word *) shdr_info[cnt].data->d_buf;
1089 inner < shdr_info[cnt].data->d_size / sizeof (Elf32_Word);
1091 grpref[inner] = shdr_info[grpref[inner]].idx;
1095 if (SH_INFO_LINK_P (&shdr_info[cnt].shdr))
1096 shdr_info[cnt].shdr.sh_info =
1097 shdr_info[shdr_info[cnt].shdr.sh_info].idx;
1103 if (shdr_info[cnt].data == NULL)
1105 shdr_info[cnt].data = elf_getdata (shdr_info[cnt].scn, NULL);
1106 if (shdr_info[cnt].data == NULL)
1116 *newdata = *shdr_info[cnt].data;
1119 shdr_info[cnt].shdr.sh_size = shdr_info[cnt].data->d_size;
1123 if (shdr_info[cnt].shdr.sh_type == SHT_DYNSYM
1124 || shdr_info[cnt].shdr.sh_type == SHT_SYMTAB)
1132 if (shdr_info[cnt].symtab_idx != 0)
1134 assert (shdr_info[cnt].shdr.sh_type == SHT_SYMTAB_SHNDX);
1137 shndxdata = elf_getdata (shdr_info[shdr_info[cnt].symtab_idx].scn,
1141 >= shdr_info[cnt].data->d_size / elsize);
1144 if (shdr_info[cnt].version_idx != 0)
1146 assert (shdr_info[cnt].shdr.sh_type == SHT_DYNSYM);
1150 versiondata = elf_getdata (shdr_info[shdr_info[cnt].version_idx].scn,
1154 >= shdr_info[cnt].data->d_size / elsize);
1157 shdr_info[cnt].newsymidx
1158 = (Elf32_Word *) xcalloc (shdr_info[cnt].data->d_size
1165 inner < shdr_info[cnt].data->d_size / elsize;
1171 GElf_Sym *sym = gelf_getsymshndx (shdr_info[cnt].data,
1184 && gelf_update_symshndx (shdr_info[cnt].data,
1190 shdr_info[cnt].newsymidx[inner] = destidx++;
1196 shdr_info[cnt].shdr.sh_info = destidx - 1;
1205 sec = shdr_info[sym->st_shndx].idx;
1210 sec = shdr_info[xshndx].idx;
1234 gelf_update_symshndx (shdr_info[cnt].data,
1240 shdr_info[cnt].newsymidx[inner] = destidx++;
1246 shdr_info[cnt].shdr.sh_info = destidx - 1;
1250 || shdr_info[cnt].debug_data == NULL)
1259 shdr_info[cnt].shdr.sh_size = newdata->d_size
1266 free (shdr_info[cnt].newsymidx);
1267 shdr_info[cnt].newsymidx = NULL;
1273 if (shdr_info[cnt].shdr.sh_offset == 0)
1274 shdr_info[cnt].shdr.sh_offset
1275 = ((lastoffset + shdr_info[cnt].shdr.sh_addralign - 1)
1276 & ~((GElf_Off) (shdr_info[cnt].shdr.sh_addralign - 1)));
1279 if (unlikely (gelf_update_shdr (scn, &shdr_info[cnt].shdr) == 0))
1284 GElf_Off filesz = (shdr_info[cnt].shdr.sh_type != SHT_NOBITS
1285 ? shdr_info[cnt].shdr.sh_size : 0);
1286 if (lastoffset < shdr_info[cnt].shdr.sh_offset + filesz)
1287 lastoffset = shdr_info[cnt].shdr.sh_offset + filesz;
1313 if (shdr_info[cnt].idx == 0 && debug_fname == NULL)
1319 const Elf32_Word symtabidx = shdr_info[cnt].old_sh_link;
1320 const Elf32_Word *const newsymidx = shdr_info[symtabidx].newsymidx;
1321 switch (shdr_info[cnt].shdr.sh_type)
1326 if (shdr_info[symtabidx].newsymidx == NULL)
1332 return (shdr_info[cnt].idx == 0
1333 && shdr_info[symtabidx].debug_data != NULL);
1341 Elf_Data *d = elf_getdata (shdr_info[cnt].idx == 0
1344 shdr_info[cnt].idx),
1347 size_t nrels = (shdr_info[cnt].shdr.sh_size
1348 / shdr_info[cnt].shdr.sh_entsize);
1350 if (shdr_info[cnt].shdr.sh_type == SHT_REL)
1394 assert (shdr_info[cnt].idx > 0);
1397 scn = elf_getscn (newelf, shdr_info[cnt].idx);
1401 shdr_info[symtabidx].idx),
1409 if (shdr_info[cnt].shdr.sh_entsize == sizeof (Elf32_Word))
1414 size_t strshndx = shdr_info[symtabidx].old_sh_link;
1435 for (size_t inner = shdr_info[symtabidx].shdr.sh_info;
1463 assert (shdr_info[cnt].shdr.sh_entsize
1468 size_t strshndx = shdr_info[symtabidx].old_sh_link;
1489 for (size_t inner = shdr_info[symtabidx].shdr.sh_info;
1521 assert (shdr_info[cnt].idx > 0);
1524 scn = elf_getscn (newelf, shdr_info[cnt].idx);
1527 symd = elf_getdata (elf_getscn (newelf, shdr_info[symtabidx].idx),
1563 scn = elf_getscn (newelf, shdr_info[cnt].idx);
1642 newehdr->e_shoff = ((shdr_info[shdridx].shdr.sh_offset
1643 + shdr_info[shdridx].shdr.sh_size + offsize - 1)
1653 shdr_info[0].scn = elf_getscn (elf, 0);
1655 if (gelf_getshdr (shdr_info[0].scn, &shdr_info[0].shdr) == NULL)
1658 shdr_info[0].shdr.sh_link = idx;
1659 (void) gelf_update_shdr (shdr_info[0].scn, &shdr_info[0].shdr);
1694 if (shdr_info != NULL)
1701 free (shdr_info[cnt].newsymidx);
1702 if (shdr_info[cnt].debug_data != NULL)
1703 free (shdr_info[cnt].debug_data->d_buf);
1707 if ((shnum + 2) * sizeof (struct shdr_info) > MAX_STACK_ALLOC)
1708 free (shdr_info);