| 428 | } |
| 429 | |
| 430 | CElfSection* |
| 431 | CElf::AddSection( |
| 432 | const string& name, |
| 433 | Elf64_Word type, |
| 434 | Elf64_Xword flags, |
| 435 | Elf64_Word info, |
| 436 | Elf64_Xword addrAlign, |
| 437 | Elf64_Xword entrySize) |
| 438 | { |
| 439 | assert(m_Initialized); |
| 440 | |
| 441 | // These need to be created with CElfStringTable & CElfSymbolTable. |
| 442 | // Also, we are only prepared to deal with one SYMTAB per object. |
| 443 | // And DYNSYM is unimplemented. |
| 444 | // If this code ever gets used to create objects from scratch, |
| 445 | // I'll need to adjust this part to mirror the code in CElf::Read(). |
| 446 | if (type == SHT_DYNSYM || |
| 447 | type == SHT_SYMTAB || |
| 448 | type == SHT_STRTAB) |
| 449 | { |
| 450 | return NULL; |
| 451 | } |
| 452 | |
| 453 | if (UnsupportedSectionType(type)) |
| 454 | { |
| 455 | return NULL; |
| 456 | } |
| 457 | |
| 458 | CElfSection* section = new CElfSection(); |
| 459 | |
| 460 | section->SetName(name); |
| 461 | section->SetData("", 0); |
| 462 | section->m_Header.sh_type = type; |
| 463 | section->m_Header.sh_flags = flags; |
| 464 | // Does this function need an addr argument? |
| 465 | section->m_Header.sh_addr = 0; |
| 466 | // sh_offset is meaningless here. We'll recompute before writing. |
| 467 | // sh_size will be determined from m_Data.size(). |
| 468 | // sh_link gets determined from m_Link. |
| 469 | // sh_info might get determined from m_Info (if non-null). |
| 470 | // Otherwise it's the data here. |
| 471 | section->m_Header.sh_info = info; |
| 472 | section->m_Header.sh_addralign = addrAlign; |
| 473 | section->m_Header.sh_entsize = entrySize; |
| 474 | m_Sections.push_back(section); |
| 475 | |
| 476 | return section; |
| 477 | } |
| 478 | |
| 479 | bool |
| 480 | CElf::RemoveSection( |