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

Function ScanSections32

BaseTools/Source/C/GenFw/Elf32Convert.c:331–632  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

329//
330
331STATIC
332VOID
333ScanSections32 (
334 VOID
335 )
336{
337 UINT32 i;
338 EFI_IMAGE_DOS_HEADER *DosHdr;
339 EFI_IMAGE_OPTIONAL_HEADER_UNION *NtHdr;
340 UINT32 CoffEntry;
341 UINT32 SectionCount;
342 BOOLEAN FoundSection;
343
344 CoffEntry = 0;
345 mCoffOffset = 0;
346
347 //
348 // Coff file start with a DOS header.
349 //
350 mCoffOffset = sizeof(EFI_IMAGE_DOS_HEADER) + 0x40;
351 mNtHdrOffset = mCoffOffset;
352 switch (mEhdr->e_machine) {
353 case EM_386:
354 case EM_ARM:
355 mCoffOffset += sizeof (EFI_IMAGE_NT_HEADERS32);
356 break;
357 default:
358 VerboseMsg ("%s unknown e_machine type. Assume IA-32", (UINTN)mEhdr->e_machine);
359 mCoffOffset += sizeof (EFI_IMAGE_NT_HEADERS32);
360 break;
361 }
362
363 mTableOffset = mCoffOffset;
364 mCoffOffset += mCoffNbrSections * sizeof(EFI_IMAGE_SECTION_HEADER);
365
366 //
367 // Set mCoffAlignment to the maximum alignment of the input sections
368 // we care about
369 //
370 for (i = 0; i < mEhdr->e_shnum; i++) {
371 Elf_Shdr *shdr = GetShdrByIndex(i);
372 if (shdr->sh_addralign <= mCoffAlignment) {
373 continue;
374 }
375 if (IsTextShdr(shdr) || IsDataShdr(shdr) || IsHiiRsrcShdr(shdr)) {
376 mCoffAlignment = (UINT32)shdr->sh_addralign;
377 }
378 }
379
380 //
381 // Check if mCoffAlignment is larger than MAX_COFF_ALIGNMENT
382 //
383 if (mCoffAlignment > MAX_COFF_ALIGNMENT) {
384 Error (NULL, 0, 3000, "Invalid", "Section alignment is larger than MAX_COFF_ALIGNMENT.");
385 assert (FALSE);
386 }
387
388 //

Callers

nothing calls this directly

Calls 14

VerboseMsgFunction · 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
strlenFunction · 0.50

Tested by

no test coverage detected