| 458 | // |
| 459 | |
| 460 | STATIC |
| 461 | VOID |
| 462 | ScanSections64 ( |
| 463 | VOID |
| 464 | ) |
| 465 | { |
| 466 | UINT32 i; |
| 467 | EFI_IMAGE_DOS_HEADER *DosHdr; |
| 468 | EFI_IMAGE_OPTIONAL_HEADER_UNION *NtHdr; |
| 469 | UINT32 CoffEntry; |
| 470 | UINT32 SectionCount; |
| 471 | BOOLEAN FoundSection; |
| 472 | |
| 473 | CoffEntry = 0; |
| 474 | mCoffOffset = 0; |
| 475 | |
| 476 | // |
| 477 | // Coff file start with a DOS header. |
| 478 | // |
| 479 | mCoffOffset = sizeof(EFI_IMAGE_DOS_HEADER) + 0x40; |
| 480 | mNtHdrOffset = mCoffOffset; |
| 481 | switch (mEhdr->e_machine) { |
| 482 | case EM_X86_64: |
| 483 | case EM_AARCH64: |
| 484 | mCoffOffset += sizeof (EFI_IMAGE_NT_HEADERS64); |
| 485 | break; |
| 486 | default: |
| 487 | VerboseMsg ("%s unknown e_machine type %hu. Assume X64", mInImageName, mEhdr->e_machine); |
| 488 | mCoffOffset += sizeof (EFI_IMAGE_NT_HEADERS64); |
| 489 | break; |
| 490 | } |
| 491 | |
| 492 | mTableOffset = mCoffOffset; |
| 493 | mCoffOffset += mCoffNbrSections * sizeof(EFI_IMAGE_SECTION_HEADER); |
| 494 | |
| 495 | // |
| 496 | // Set mCoffAlignment to the maximum alignment of the input sections |
| 497 | // we care about |
| 498 | // |
| 499 | for (i = 0; i < mEhdr->e_shnum; i++) { |
| 500 | Elf_Shdr *shdr = GetShdrByIndex(i); |
| 501 | if (shdr->sh_addralign <= mCoffAlignment) { |
| 502 | continue; |
| 503 | } |
| 504 | if (IsTextShdr(shdr) || IsDataShdr(shdr) || IsHiiRsrcShdr(shdr)) { |
| 505 | mCoffAlignment = (UINT32)shdr->sh_addralign; |
| 506 | } |
| 507 | } |
| 508 | |
| 509 | // |
| 510 | // Check if mCoffAlignment is larger than MAX_COFF_ALIGNMENT |
| 511 | // |
| 512 | if (mCoffAlignment > MAX_COFF_ALIGNMENT) { |
| 513 | Error (NULL, 0, 3000, "Invalid", "Section alignment is larger than MAX_COFF_ALIGNMENT."); |
| 514 | assert (FALSE); |
| 515 | } |
| 516 | |
| 517 |
nothing calls this directly
no test coverage detected