82 set_synthesized(
true);
84 set_purpose(SP_HEADER);
102 ROSE_ASSERT(fhdr!=NULL);
105 size_t ent_size, struct_size, opt_size, nentries;
106 calculate_sizes(&ent_size, &struct_size, &opt_size, &nentries);
112 if (get_size()<=1 && get_size()<nentries*ent_size)
113 extend(nentries*ent_size - get_size());
116 std::vector<SgAsmElfSectionTableEntry*> entries;
118 for (
size_t i=0; i<nentries; i++, offset+=ent_size) {
122 read_content_local(offset, &disk, struct_size);
126 read_content_local(offset, &disk, struct_size);
130 shdr->
get_extra() = read_content_local_ucl(offset+struct_size, opt_size);
131 entries.push_back(shdr);
137 std::vector<SgAsmElfSection*> is_parsed;
138 is_parsed.resize(entries.size(), NULL);
146 section_name_strings->
parse();
153 bool try_again=
false;
154 for (
size_t i=0; i<entries.size(); i++) {
160 ROSE_ASSERT(!need_linked || entry->
get_sh_link()<entries.size());
167 ROSE_ASSERT(!need_info_linked || entry->
get_sh_info()<entries.size());
172 }
else if ((need_linked && !linked) || (need_info_linked && !info_linked)) {
196 is_parsed[i] = symsec;
204 is_parsed[i] = symsec;
214 is_parsed[i] = relocsec;
221 is_parsed[i] = relocsec;
225 if (!section_name_strings) {
226 fprintf(stderr,
"SgAsmElfSectionTable::parse(): no string table for section table\n");
230 if (section_name ==
".eh_frame") {
258 is_parsed[i]->init_from_section_table(entry, section_name_strings, i);
259 is_parsed[i]->parse();
267 for (
size_t i = 0; i < entries.size(); i++) {
278 for (
size_t i=0; i<is_parsed.size(); i++)
279 is_parsed[i]->finish_parsing();
295 ROSE_ASSERT(section!=NULL);
296 ROSE_ASSERT(section->
get_file()==get_file());
297 ROSE_ASSERT(section->
get_header()==get_header());
301 ROSE_ASSERT(fhdr!=NULL);
304 if (section->
get_id()<0) {
305 int id = fhdr->get_e_shnum();
306 fhdr->set_e_shnum(
id+1);
314 if (fhdr->get_e_shstrndx()==0) {
317 fhdr->set_e_shstrndx(section->
get_id());
328 ROSE_ASSERT(strsec!=NULL);
365 ROSE_ASSERT(fhdr!=NULL);
367 size_t struct_size = 0;
369 size_t entry_size = 0;
382 entry_size = struct_size;
387 for (
size_t i=0; i<sections.size(); i++) {
390 ROSE_ASSERT(elfsec->
get_id()>=0);
404 *entsize = entry_size;
406 *required = struct_size;
408 *optional = extra_size;
410 *entcount = nentries;
411 return entry_size * nentries;
425 if (get_sh_type()==SHT_NOBITS && section->
is_mapped()) {
435 p_sh_flags |= SHF_WRITE;
437 p_sh_flags &= ~SHF_WRITE;
440 p_sh_flags |= SHF_EXECINSTR;
442 p_sh_flags &= ~SHF_EXECINSTR;
446 p_sh_flags &= ~(SHF_WRITE | SHF_EXECINSTR);
451 ROSE_ASSERT(linked_to->
get_id()>0);
452 set_sh_link(linked_to->
get_id());
466 std::string retval =
"";
472 if(t>=SHT_LOOS && t <= SHT_HIOS) {
473 snprintf(buf,
sizeof(buf),
"os-specific (%zu)",
size_t(t)) ;
476 if (t>=SHT_LOPROC && t<=SHT_HIPROC) {
477 snprintf(buf,
sizeof(buf),
"processor-specific (%zu)",
size_t(t)) ;
480 if (t>=SHT_LOUSER && t<=SHT_HIUSER) {
481 snprintf(buf,
sizeof(buf),
"application-specific (%zu)",
size_t(t)) ;
484 snprintf(buf,
sizeof(buf),
"unknown section type (%zu)",
size_t(t)) ;
492 static const uint32_t kBaseMask=0x3ff;
493 for(
size_t i=0; (1u <<i) <= SHF_TLS; ++i){
498 case SHF_NULL: str +=
"NULL";
break;
499 case SHF_WRITE: str +=
"WRITE";
break;
500 case SHF_ALLOC: str +=
"ALLOC";
break;
501 case SHF_EXECINSTR: str +=
"CODE";
break;
502 case SHF_MERGE: str +=
"MERGE";
break;
503 case SHF_STRINGS: str +=
"STRINGS";
break;
504 case SHF_INFO_LINK: str +=
"INFO_LINK";
break;
505 case SHF_LINK_ORDER:str +=
"LINK_ORDER";
break;
506 case SHF_OS_NONCONFORMING:str +=
"OS SPECIAL";
break;
507 case SHF_GROUP: str +=
"GROUP";
break;
508 case SHF_TLS: str +=
"TLS";
break;
512 uint32_t os = (val & ~(uint32_t)(SHF_MASKOS));
513 uint32_t proc = (val & ~(uint32_t)(SHF_MASKPROC));
514 uint32_t rest = (val & ~(uint32_t)(kBaseMask | SHF_MASKOS | SHF_MASKPROC));
518 snprintf(buf,
sizeof(buf),
"os flags(%2x)", os >> 20);
524 snprintf(buf,
sizeof(buf),
"proc flags(%1x)", proc >> 28);
530 snprintf(buf,
sizeof(buf),
"unknown(%x)", rest);
543 sprintf(p,
"%sElfSectionTableEntry[%zd].", prefix, idx);
545 sprintf(p,
"%sElfSectionTableEntry.", prefix);
549 fprintf(f,
"%s%-*s = %u bytes into strtab\n", p, w,
"sh_name", p_sh_name);
550 fprintf(f,
"%s%-*s = 0x%x (%d) %s\n", p, w,
"sh_type",
551 p_sh_type, p_sh_type, to_string(p_sh_type).c_str());
552 fprintf(f,
"%s%-*s = %lu\n", p, w,
"sh_link", p_sh_link);
553 fprintf(f,
"%s%-*s = %lu\n", p, w,
"sh_info", p_sh_info);
554 fprintf(f,
"%s%-*s = 0x%08"PRIx64
"\n", p, w,
"sh_flags", p_sh_flags);
555 fprintf(f,
"%s%-*s = 0x%08"PRIx64
" (%"PRIu64
")\n", p, w,
"sh_addr", p_sh_addr, p_sh_addr);
556 fprintf(f,
"%s%-*s = 0x%08"PRIx64
" (%"PRIu64
") bytes into file\n", p, w,
"sh_offset", p_sh_offset, p_sh_offset);
557 fprintf(f,
"%s%-*s = 0x%08"PRIx64
" (%"PRIu64
") bytes\n", p, w,
"sh_size", p_sh_size, p_sh_size);
558 fprintf(f,
"%s%-*s = 0x%08"PRIx64
" (%"PRIu64
") bytes\n", p, w,
"sh_addralign", p_sh_addralign, p_sh_addralign);
559 fprintf(f,
"%s%-*s = 0x%08"PRIx64
" (%"PRIu64
") bytes\n", p, w,
"sh_entsize", p_sh_entsize, p_sh_entsize);
560 if (p_extra.size()>0) {
561 fprintf(f,
"%s%-*s = %zu bytes\n", p, w,
"extra", p_extra.size());
562 hexdump(f, 0, std::string(p)+
"extra at ", p_extra);
571 bool reallocated =
false;
574 size_t opt_size, nentries;
575 rose_addr_t need = calculate_sizes(NULL, NULL, &opt_size, &nentries);
576 if (need < get_size()) {
578 ROSE_ASSERT(get_mapped_size()==get_size());
579 set_mapped_size(need);
584 }
else if (need > get_size()) {
602 ROSE_ASSERT(fhdr!=NULL);
607 for (
size_t i=0; i<sections.size(); i++)
608 sections[i]->unparse(f);
612 size_t ent_size, struct_size, opt_size, nentries;
613 calculate_sizes(&ent_size, &struct_size, &opt_size, &nentries);
618 for (
size_t i=0; i<sections.size(); ++i) {
620 ROSE_ASSERT(section!=NULL);
622 ROSE_ASSERT(shdr!=NULL);
625 int id = section->
get_id();
626 ROSE_ASSERT(
id>=0 && (
size_t)
id<nentries);
633 disk = shdr->
encode(sex, &disk32);
635 disk = shdr->
encode(sex, &disk64);
637 ROSE_ASSERT(!
"invalid word size");
641 rose_addr_t spos = write(f,
id*ent_size, struct_size, disk);
643 ROSE_ASSERT(shdr->
get_extra().size()<=opt_size);
655 sprintf(p,
"%sSectionTable[%zd].", prefix, idx);
657 sprintf(p,
"%sSectionTable.", prefix);
663 hexdump(f, 0, std::string(p)+
"data at ", p_data);