MCPcopy Create free account
hub / github.com/CloverHackyColor/CloverBootloader / ScanSections64

Function ScanSections64

BaseTools/Source/C/GenFw/Elf64Convert.c:460–770  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

458//
459
460STATIC
461VOID
462ScanSections64 (
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

Callers

nothing calls this directly

Calls 15

VerboseMsgFunction · 0.85
printfFunction · 0.85
timeFunction · 0.85
CreateSectionHeaderFunction · 0.85
GetShdrByIndexFunction · 0.70
IsTextShdrFunction · 0.70
IsDataShdrFunction · 0.70
IsHiiRsrcShdrFunction · 0.70
CoffAlignFunction · 0.70
DebugRvaAlignFunction · 0.70
ErrorFunction · 0.50
WarningFunction · 0.50

Tested by

no test coverage detected