mirror of
https://github.com/CloverHackyColor/CloverBootloader.git
synced 2025-01-23 21:11:32 +01:00
gcc12 fix.
This commit is contained in:
parent
68f80562e0
commit
cec450188d
@ -528,6 +528,7 @@ ScanSections64 (
|
|||||||
//
|
//
|
||||||
// List all sections.
|
// List all sections.
|
||||||
//
|
//
|
||||||
|
// printf("%d sections\n", mEhdr->e_shnum);
|
||||||
// for (i = 0; i < mEhdr->e_shnum; i++) {
|
// for (i = 0; i < mEhdr->e_shnum; i++) {
|
||||||
// Elf_Shdr *shdr = GetShdrByIndex(i);
|
// Elf_Shdr *shdr = GetShdrByIndex(i);
|
||||||
// Elf_Shdr *Namedr = GetShdrByIndex(mEhdr->e_shstrndx);
|
// Elf_Shdr *Namedr = GetShdrByIndex(mEhdr->e_shstrndx);
|
||||||
@ -555,7 +556,7 @@ ScanSections64 (
|
|||||||
// if the section address is aligned we must align PE/COFF
|
// if the section address is aligned we must align PE/COFF
|
||||||
UINT32 mCoffOffsetNew = (UINT32) ((shdr->sh_addr + shdr->sh_addralign - 1) & ~(shdr->sh_addralign - 1));
|
UINT32 mCoffOffsetNew = (UINT32) ((shdr->sh_addr + shdr->sh_addralign - 1) & ~(shdr->sh_addralign - 1));
|
||||||
// mCoffOffset = (UINT32) ((mCoffOffset + shdr->sh_addralign - 1) & ~(shdr->sh_addralign - 1));
|
// mCoffOffset = (UINT32) ((mCoffOffset + shdr->sh_addralign - 1) & ~(shdr->sh_addralign - 1));
|
||||||
//printf("Section %d %s mCoffOffset=%d(0x%x) mCoffOffsetNew=%d(0x%x) diff=%d(0x%x), size=%llu\n", i, sectName, mCoffOffset, mCoffOffset, mCoffOffsetNew, mCoffOffsetNew, mCoffOffsetNew-mCoffOffset, mCoffOffsetNew-mCoffOffset, shdr->sh_size);
|
//printf("Section %d %s mCoffOffset=%d(0x%x) mCoffOffsetNew=%d(0x%x) diff=%d(0x%x), size=%llx\n", i, sectName, mCoffOffset, mCoffOffset, mCoffOffsetNew, mCoffOffsetNew, mCoffOffsetNew-mCoffOffset, mCoffOffsetNew-mCoffOffset, shdr->sh_size);
|
||||||
mCoffOffset=mCoffOffsetNew;
|
mCoffOffset=mCoffOffsetNew;
|
||||||
} else {
|
} else {
|
||||||
Error (NULL, 0, 3000, "Invalid", "Section address not aligned to its own alignment.");
|
Error (NULL, 0, 3000, "Invalid", "Section address not aligned to its own alignment.");
|
||||||
@ -605,6 +606,7 @@ ScanSections64 (
|
|||||||
Elf_Shdr *shdr = GetShdrByIndex(i);
|
Elf_Shdr *shdr = GetShdrByIndex(i);
|
||||||
// /*debug*/Elf_Shdr *Namedr = GetShdrByIndex(mEhdr->e_shstrndx);
|
// /*debug*/Elf_Shdr *Namedr = GetShdrByIndex(mEhdr->e_shstrndx);
|
||||||
// /*debug*/CHAR8* sectName = ((CHAR8*)mEhdr) + Namedr->sh_offset + shdr->sh_name;
|
// /*debug*/CHAR8* sectName = ((CHAR8*)mEhdr) + Namedr->sh_offset + shdr->sh_name;
|
||||||
|
// /*debug*/printf("Section %d %s shdr->sh_flags=%llx IsTextShdr(shdr)=%d\n", i, sectName, shdr->sh_flags, IsDataShdr(shdr));
|
||||||
if (IsDataShdr(shdr)) {
|
if (IsDataShdr(shdr)) {
|
||||||
if ((shdr->sh_addralign != 0) && (shdr->sh_addralign != 1)) {
|
if ((shdr->sh_addralign != 0) && (shdr->sh_addralign != 1)) {
|
||||||
// the alignment field is valid
|
// the alignment field is valid
|
||||||
@ -612,7 +614,7 @@ ScanSections64 (
|
|||||||
// if the section address is aligned we must align PE/COFF
|
// if the section address is aligned we must align PE/COFF
|
||||||
UINT32 mCoffOffsetNew = (UINT32) ((shdr->sh_addr + shdr->sh_addralign - 1) & ~(shdr->sh_addralign - 1));
|
UINT32 mCoffOffsetNew = (UINT32) ((shdr->sh_addr + shdr->sh_addralign - 1) & ~(shdr->sh_addralign - 1));
|
||||||
// mCoffOffset = (UINT32) ((mCoffOffset + shdr->sh_addralign - 1) & ~(shdr->sh_addralign - 1));
|
// mCoffOffset = (UINT32) ((mCoffOffset + shdr->sh_addralign - 1) & ~(shdr->sh_addralign - 1));
|
||||||
//printf("Section %d %s mCoffOffset=%d(0x%x) mCoffOffsetNew=%d(0x%x) diff=%d(0x%x), size=%llu\n", i, sectName, mCoffOffset, mCoffOffset, mCoffOffsetNew, mCoffOffsetNew, mCoffOffsetNew-mCoffOffset, mCoffOffsetNew-mCoffOffset, shdr->sh_size);
|
//printf("Section %d %s mCoffOffset=%d(0x%x) mCoffOffsetNew=%d(0x%x) diff=%d(0x%x), size=%llx\n", i, sectName, mCoffOffset, mCoffOffset, mCoffOffsetNew, mCoffOffsetNew, mCoffOffsetNew-mCoffOffset, mCoffOffsetNew-mCoffOffset, shdr->sh_size);
|
||||||
mCoffOffset=mCoffOffsetNew;
|
mCoffOffset=mCoffOffsetNew;
|
||||||
} else {
|
} else {
|
||||||
Error (NULL, 0, 3000, "Invalid", "Section address not aligned to its own alignment.");
|
Error (NULL, 0, 3000, "Invalid", "Section address not aligned to its own alignment.");
|
||||||
@ -820,19 +822,37 @@ WriteSections64 (
|
|||||||
//
|
//
|
||||||
for (Idx = 0; Idx < mEhdr->e_shnum; Idx++) {
|
for (Idx = 0; Idx < mEhdr->e_shnum; Idx++) {
|
||||||
Elf_Shdr *Shdr = GetShdrByIndex(Idx);
|
Elf_Shdr *Shdr = GetShdrByIndex(Idx);
|
||||||
|
Elf_Shdr *Namedr = GetShdrByIndex(mEhdr->e_shstrndx);
|
||||||
|
CHAR8* sectName = ((CHAR8*)mEhdr) + Namedr->sh_offset + Shdr->sh_name;
|
||||||
|
//printf("filter %s =%d\n", sectName, (*Filter)(Shdr));
|
||||||
if ((*Filter)(Shdr)) {
|
if ((*Filter)(Shdr)) {
|
||||||
switch (Shdr->sh_type) {
|
switch (Shdr->sh_type) {
|
||||||
case SHT_PROGBITS:
|
case SHT_PROGBITS:
|
||||||
/* Copy. */
|
/* Copy. */
|
||||||
if (Shdr->sh_offset + Shdr->sh_size > mFileBufferSize) {
|
if (Shdr->sh_offset + Shdr->sh_size > mFileBufferSize) {
|
||||||
|
VerboseMsg("Section %s is too big\n", sectName);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
///*debug*/printf("copy %s in mCoffFile at %x-%llx from %llx-%llx, size %llx\n", sectName, mCoffSectionsOffset[Idx], mCoffSectionsOffset[Idx]+Shdr->sh_size, Shdr->sh_offset, Shdr->sh_offset+Shdr->sh_size, Shdr->sh_size);
|
||||||
|
memcpy(mCoffFile + mCoffSectionsOffset[Idx],
|
||||||
|
(UINT8*)mEhdr + Shdr->sh_offset,
|
||||||
|
(size_t) Shdr->sh_size);
|
||||||
|
break;
|
||||||
|
case SHT_INIT_ARRAY:
|
||||||
|
/* Copy. */
|
||||||
|
if (Shdr->sh_offset + Shdr->sh_size > mFileBufferSize) {
|
||||||
|
VerboseMsg("Section %s is too big\n", sectName);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
///*debug*/printf("copy %s in mCoffFile at %x-%llx from %llx-%llx, size %llx\n", sectName, mCoffSectionsOffset[Idx], mCoffSectionsOffset[Idx]+Shdr->sh_size, Shdr->sh_offset, Shdr->sh_offset+Shdr->sh_size, Shdr->sh_size);
|
||||||
memcpy(mCoffFile + mCoffSectionsOffset[Idx],
|
memcpy(mCoffFile + mCoffSectionsOffset[Idx],
|
||||||
(UINT8*)mEhdr + Shdr->sh_offset,
|
(UINT8*)mEhdr + Shdr->sh_offset,
|
||||||
(size_t) Shdr->sh_size);
|
(size_t) Shdr->sh_size);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
case SHT_NOBITS:
|
case SHT_NOBITS:
|
||||||
|
///*debug*/printf("Erase %s in mCoffFile at %x-%llx\n", sectName, mCoffSectionsOffset[Idx], mCoffSectionsOffset[Idx]+Shdr->sh_size);
|
||||||
memset(mCoffFile + mCoffSectionsOffset[Idx], 0, (size_t) Shdr->sh_size);
|
memset(mCoffFile + mCoffSectionsOffset[Idx], 0, (size_t) Shdr->sh_size);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -840,7 +860,7 @@ WriteSections64 (
|
|||||||
//
|
//
|
||||||
// Ignore for unknown section type.
|
// Ignore for unknown section type.
|
||||||
//
|
//
|
||||||
VerboseMsg ("%s unknown section type %x. We ignore this unknown section type.", mInImageName, (unsigned)Shdr->sh_type);
|
VerboseMsg ("%s unknown section '%s' type %x. We ignore this unknown section type.", mInImageName, sectName, (unsigned)Shdr->sh_type);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -920,14 +940,20 @@ WriteSections64 (
|
|||||||
if (SymName == NULL) {
|
if (SymName == NULL) {
|
||||||
SymName = (const UINT8 *)"<unknown>";
|
SymName = (const UINT8 *)"<unknown>";
|
||||||
}
|
}
|
||||||
/*
|
if ( strcmp((const char *)SymName, "__cxa_pure_virtual") == 0 ) {
|
||||||
|
static int already_printed_once = 0;
|
||||||
|
if ( !already_printed_once ) {
|
||||||
|
printf("FIXME reminder : __cxa_pure_virtual is undefined -> ignored. This is happening since gcc 12.1 for unknown reasons.\n");
|
||||||
|
already_printed_once = 1;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
Error (NULL, 0, 3000, "Invalid",
|
Error (NULL, 0, 3000, "Invalid",
|
||||||
"%s: Bad definition for symbol '%s'@%#llx or unsupported symbol type. "
|
"%s: Bad definition for symbol '%s'@%#llx or unsupported symbol type. "
|
||||||
"For example, absolute and undefined symbols are not supported.",
|
"For example, absolute and undefined symbols are not supported.",
|
||||||
mInImageName, SymName, Sym->st_value);
|
mInImageName, SymName, Sym->st_value);
|
||||||
|
|
||||||
exit(EXIT_FAILURE); */
|
exit(EXIT_FAILURE);
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
SymShdr = GetShdrByIndex(Sym->st_shndx);
|
SymShdr = GetShdrByIndex(Sym->st_shndx);
|
||||||
|
|
||||||
|
@ -19,7 +19,12 @@ extern "C" {
|
|||||||
#include <Platform.h> // Only use angled for Platform, else, xcode project won't compile
|
#include <Platform.h> // Only use angled for Platform, else, xcode project won't compile
|
||||||
#include <Protocol/LoadedImage.h>
|
#include <Protocol/LoadedImage.h>
|
||||||
|
|
||||||
|
//#define DUMP_EFI_FROM_MEMORY
|
||||||
|
|
||||||
|
#ifdef DUMP_EFI_FROM_MEMORY
|
||||||
|
#include "../../libeg/libeg.h"
|
||||||
|
#include "../../Settings/Self.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef void (ctor)(void);
|
typedef void (ctor)(void);
|
||||||
typedef ctor* ctor_ptr;
|
typedef ctor* ctor_ptr;
|
||||||
@ -84,7 +89,23 @@ ctor_ptr* pend = (ctor_ptr*)&__end_of_section_ctors;
|
|||||||
void construct_globals_objects(EFI_HANDLE ImageHandle)
|
void construct_globals_objects(EFI_HANDLE ImageHandle)
|
||||||
{
|
{
|
||||||
(void)ImageHandle;
|
(void)ImageHandle;
|
||||||
DBG("CTORS %llX(%lld) size %ld\n", (UINTN)p, (UINTN)p, pend-p );
|
|
||||||
|
#ifdef DUMP_EFI_FROM_MEMORY
|
||||||
|
EFI_LOADED_IMAGE* LoadedImage;
|
||||||
|
EFI_STATUS Status = gBS->HandleProtocol(gImageHandle, &gEfiLoadedImageProtocolGuid, (void **) &LoadedImage);
|
||||||
|
if ( EFI_ERROR(Status) ) {
|
||||||
|
panic("construct_globals_objects: Cannot get LoadedImage protocol");
|
||||||
|
}
|
||||||
|
|
||||||
|
Self self;
|
||||||
|
self.initialize(ImageHandle);
|
||||||
|
// for (size_t i=0 ; i<2467264 ; i +=16) DBG("%08llx %08llx %08llx %08llx %08llx %08llx %08llx %08llx %08llx %08llx %08llx %08llx %08llx %08llx %08llx %08llx\n", (UINTN)p[i], (UINTN)p[i+1], (UINTN)p[i+2], (UINTN)p[i+3], (UINTN)p[i+4], (UINTN)p[i+5], (UINTN)p[i+6], (UINTN)p[i+7], (UINTN)p[i+8], (UINTN)p[i+9], (UINTN)p[i+10], (UINTN)p[i+11], (UINTN)p[i+12], (UINTN)p[i+13], (UINTN)p[i+14], (UINTN)p[i+15]);
|
||||||
|
// unsigned char* cp = (unsigned char*)p;
|
||||||
|
// for (size_t i=0 ; i<2467264 ; i +=16) DBG("%c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c\n",cp[0]>=32 ? cp[i+0] : '.',cp[i+1]>=32 ? cp[i+1] : '.',cp[i+2]>=32 ? cp[i+2] : '.',cp[i+3]>=32 ? cp[i+3] : '.',cp[i+4]>=32 ? cp[i+4] : '.',cp[i+5]>=32 ? cp[i+5] : '.',cp[i+6]>=32 ? cp[i+6] : '.',cp[i+7]>=32 ? cp[i+7] : '.',cp[i+8]>=32 ? cp[i+8] : '.',cp[i+9]>=32 ? cp[i+9] : '.',cp[i+10]>=32 ? cp[i+10] : '.',cp[i+11]>=32 ? cp[i+11] : '.',cp[i+12]>=32 ? cp[i+12] : '.',cp[i+13]>=32 ? cp[i+13] : '.',cp[i+14]>=32 ? cp[i+14] : '.',cp[i+15]>=32 ? cp[i+15] : '.');
|
||||||
|
// egSaveFile(&self.getCloverDir(), L"dump.bin", LoadedImage->ImageBase, 3000000);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
DBG("CTORS %llX(%lld), offset from file beginning %llX(%lld) size %ld\n", (UINTN)p, (UINTN)p, (UINTN)p - (UINTN)LoadedImage->ImageBase, (UINTN)p - (UINTN)LoadedImage->ImageBase, pend-p );
|
||||||
while ( p < pend ) {
|
while ( p < pend ) {
|
||||||
DBG("CTOR %llX(%lld)\n", (UINTN)p[0], (UINTN)p[0]);
|
DBG("CTOR %llX(%lld)\n", (UINTN)p[0], (UINTN)p[0]);
|
||||||
(*p)();
|
(*p)();
|
||||||
|
Loading…
Reference in New Issue
Block a user