| 403 | |
| 404 | template <class Types> |
| 405 | cmELFInternalImpl<Types>::cmELFInternalImpl(cmELF* external, |
| 406 | std::unique_ptr<std::istream> fin, |
| 407 | ByteOrderType order) |
| 408 | : cmELFInternal(external, std::move(fin), order) |
| 409 | { |
| 410 | // Read the main header. |
| 411 | if (!this->Read(this->ELFHeader)) { |
| 412 | this->SetErrorMessage("Failed to read main ELF header."); |
| 413 | return; |
| 414 | } |
| 415 | |
| 416 | // Determine the ELF file type. |
| 417 | switch (this->ELFHeader.e_type) { |
| 418 | case ET_NONE: |
| 419 | this->SetErrorMessage("ELF file type is NONE."); |
| 420 | return; |
| 421 | case ET_REL: |
| 422 | this->ELFType = cmELF::FileTypeRelocatableObject; |
| 423 | break; |
| 424 | case ET_EXEC: |
| 425 | this->ELFType = cmELF::FileTypeExecutable; |
| 426 | break; |
| 427 | case ET_DYN: |
| 428 | this->ELFType = cmELF::FileTypeSharedLibrary; |
| 429 | break; |
| 430 | case ET_CORE: |
| 431 | this->ELFType = cmELF::FileTypeCore; |
| 432 | break; |
| 433 | default: { |
| 434 | unsigned int eti = static_cast<unsigned int>(this->ELFHeader.e_type); |
| 435 | if (eti >= ET_LOOS && eti <= ET_HIOS) { |
| 436 | this->ELFType = cmELF::FileTypeSpecificOS; |
| 437 | break; |
| 438 | } |
| 439 | if (eti >= ET_LOPROC && eti <= ET_HIPROC) { |
| 440 | this->ELFType = cmELF::FileTypeSpecificProc; |
| 441 | break; |
| 442 | } |
| 443 | std::ostringstream e; |
| 444 | e << "Unknown ELF file type " << eti; |
| 445 | this->SetErrorMessage(e.str().c_str()); |
| 446 | return; |
| 447 | } |
| 448 | } |
| 449 | |
| 450 | this->Machine = this->ELFHeader.e_machine; |
| 451 | |
| 452 | // Load the section headers. |
| 453 | std::size_t const minSections = 1; |
| 454 | std::size_t numSections = this->ELFHeader.e_shnum; |
| 455 | this->SectionHeaders.resize(std::max(numSections, minSections)); |
| 456 | if (!this->LoadSectionHeader(0)) { |
| 457 | return; |
| 458 | } |
| 459 | numSections = this->GetNumberOfSections(); |
| 460 | this->SectionHeaders.resize(std::max(numSections, minSections)); |
| 461 | for (std::size_t i = 1; i < numSections; ++i) { |
| 462 | if (!this->LoadSectionHeader(i)) { |
nothing calls this directly
no test coverage detected