diff --git a/BaseTools/Source/C/GenFw/Elf64Convert.c b/BaseTools/Source/C/GenFw/Elf64Convert.c index 25879d9bf..288069e84 100755 --- a/BaseTools/Source/C/GenFw/Elf64Convert.c +++ b/BaseTools/Source/C/GenFw/Elf64Convert.c @@ -540,6 +540,7 @@ ScanSections64 ( // First text sections. // mCoffOffset = CoffAlign(mCoffOffset); + mCoffOffsetMax = MAX(mCoffOffsetMax, mCoffOffset); mTextOffset = mCoffOffset; FoundSection = FALSE; SectionCount = 0; @@ -554,7 +555,7 @@ ScanSections64 ( // 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)); 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)\n", i, sectName, mCoffOffset, mCoffOffset, mCoffOffsetNew, mCoffOffsetNew, mCoffOffsetNew-mCoffOffset, mCoffOffsetNew-mCoffOffset); +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); mCoffOffset=mCoffOffsetNew; } else { Error (NULL, 0, 3000, "Invalid", "Section address not aligned to its own alignment."); @@ -577,6 +578,7 @@ mCoffOffset=mCoffOffsetNew; mCoffSectionsOffset[i] = mCoffOffset; mCoffOffset += (UINT32) shdr->sh_size; + mCoffOffsetMax = MAX(mCoffOffsetMax, mCoffOffset); SectionCount ++; } } @@ -610,7 +612,7 @@ mCoffOffset=mCoffOffsetNew; // 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)); 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)\n", i, sectName, mCoffOffset, mCoffOffset, mCoffOffsetNew, mCoffOffsetNew, mCoffOffsetNew-mCoffOffset, mCoffOffsetNew-mCoffOffset); + 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); mCoffOffset=mCoffOffsetNew; } else { Error (NULL, 0, 3000, "Invalid", "Section address not aligned to its own alignment."); @@ -626,6 +628,7 @@ mCoffOffset=mCoffOffsetNew; } mCoffSectionsOffset[i] = mCoffOffset; mCoffOffset += (UINT32) shdr->sh_size; + mCoffOffsetMax = MAX(mCoffOffsetMax, mCoffOffset); SectionCount ++; } } @@ -673,6 +676,7 @@ mCoffOffset=mCoffOffsetNew; mCoffSectionsOffset[i] = mCoffOffset; mCoffOffset += (UINT32) shdr->sh_size; mCoffOffset = CoffAlign(mCoffOffset); + mCoffOffsetMax = MAX(mCoffOffsetMax, mCoffOffset); SetHiiResourceHeader ((UINT8*) mEhdr + shdr->sh_offset, mHiiRsrcOffset); } break; @@ -685,7 +689,7 @@ mCoffOffset=mCoffOffsetNew; // Allocate base Coff file. Will be expanded later for relocations. // NormalMsg("Allocate %d bytes for mCoffFile", mCoffOffset); - mCoffFile = (UINT8 *)malloc(mCoffOffset); + mCoffFile = (UINT8 *)malloc(mCoffOffsetMax); if (mCoffFile == NULL) { Error (NULL, 0, 4001, "Resource", "memory cannot be allocated!"); } diff --git a/BaseTools/Source/C/GenFw/ElfConvert.c b/BaseTools/Source/C/GenFw/ElfConvert.c index bd216f2be..0ffa9b168 100755 --- a/BaseTools/Source/C/GenFw/ElfConvert.c +++ b/BaseTools/Source/C/GenFw/ElfConvert.c @@ -45,6 +45,7 @@ UINT16 *mCoffEntryRel; // Current offset in coff file. // UINT32 mCoffOffset; +UINT32 mCoffOffsetMax; // // Offset in Coff file of headers and sections. diff --git a/BaseTools/Source/C/GenFw/ElfConvert.h b/BaseTools/Source/C/GenFw/ElfConvert.h index 801e8de4a..791adb1a8 100755 --- a/BaseTools/Source/C/GenFw/ElfConvert.h +++ b/BaseTools/Source/C/GenFw/ElfConvert.h @@ -18,6 +18,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent // Externally defined variables // extern UINT32 mCoffOffset; +extern UINT32 mCoffOffsetMax; extern CHAR8 *mInImageName; extern UINT32 mImageTimeStamp; extern UINT8 *mCoffFile; diff --git a/BaseTools/Source/C/GenFw/GenFw.xcodeproj/xcshareddata/xcschemes/GenFw.xcscheme b/BaseTools/Source/C/GenFw/GenFw.xcodeproj/xcshareddata/xcschemes/GenFw.xcscheme index 8dc01ffe6..559dc9626 100644 --- a/BaseTools/Source/C/GenFw/GenFw.xcodeproj/xcshareddata/xcschemes/GenFw.xcscheme +++ b/BaseTools/Source/C/GenFw/GenFw.xcodeproj/xcshareddata/xcschemes/GenFw.xcscheme @@ -36,7 +36,7 @@ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" launchStyle = "0" useCustomWorkingDirectory = "YES" - customWorkingDirectory = "/JiefLand/5.Devel/Clover/Clover-projects/Clover--CloverHackyColor--master.2/Build/Clover/RELEASE_GCC53/X64/rEFIt_UEFI/refit/DEBUG" + customWorkingDirectory = "/JiefLand/5.Devel/Clover/Clover-projects/Clover--CloverHackyColor--master.2/RELEASE_GCC53" ignoresPersistentStateOnLaunch = "NO" debugDocumentVersioning = "YES" debugServiceExtension = "internal"