mirror of
https://github.com/tianocore/edk2
synced 2026-08-27 00:23:19 -04:00
BaseTools/GenFds: Allow PE32 section keywords in any order
Replace sequential if-statements for Align, Xip, and RELOCS_STRIPPED/RELOCS_RETAINED parsing in _GetEfiSection() with a while-loop that accepts these keywords in any permutation. Previously, specifying Xip before Align in a [Rule] PE32 section caused a Python stack trace. Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
This commit is contained in:
parent
80bf0137c1
commit
d6eb4c4965
1 changed files with 26 additions and 25 deletions
|
|
@ -3893,33 +3893,34 @@ class FdfParser:
|
|||
raise Warning.Expected("Build number", self.FileName, self.CurrentLineNumber)
|
||||
EfiSectionObj.BuildNum = self._Token
|
||||
|
||||
if self._GetAlignment():
|
||||
if self._Token not in ALIGNMENTS:
|
||||
raise Warning("Incorrect alignment '%s'" % self._Token, self.FileName, self.CurrentLineNumber)
|
||||
if self._Token == 'Auto' and (not SectionName == BINARY_FILE_TYPE_PE32) and (not SectionName == BINARY_FILE_TYPE_TE):
|
||||
raise Warning("Auto alignment can only be used in PE32 or TE section ", self.FileName, self.CurrentLineNumber)
|
||||
EfiSectionObj.Alignment = self._Token
|
||||
|
||||
if self._IsKeyword("Xip"):
|
||||
if not self._IsToken(TAB_EQUAL_SPLIT):
|
||||
raise Warning.ExpectedEquals(self.FileName, self.CurrentLineNumber)
|
||||
if not self._GetNextWord():
|
||||
raise Warning.Expected("Xip value (TRUE/FALSE)", self.FileName, self.CurrentLineNumber)
|
||||
XipValue = self._Token.strip().upper()
|
||||
if XipValue not in {"TRUE", "FALSE"}:
|
||||
raise Warning("Invalid Xip value '%s'" % XipValue, self.FileName, self.CurrentLineNumber)
|
||||
EfiSectionObj.Xip = XipValue
|
||||
|
||||
if self._IsKeyword('RELOCS_STRIPPED') or self._IsKeyword('RELOCS_RETAINED'):
|
||||
if self._SectionCouldHaveRelocFlag(EfiSectionObj.SectionType):
|
||||
if self._Token == 'RELOCS_STRIPPED':
|
||||
EfiSectionObj.KeepReloc = False
|
||||
while True:
|
||||
if self._GetAlignment():
|
||||
if self._Token not in ALIGNMENTS:
|
||||
raise Warning("Incorrect alignment '%s'" % self._Token, self.FileName, self.CurrentLineNumber)
|
||||
if self._Token == 'Auto' and (not SectionName == BINARY_FILE_TYPE_PE32) and (not SectionName == BINARY_FILE_TYPE_TE):
|
||||
raise Warning("Auto alignment can only be used in PE32 or TE section ", self.FileName, self.CurrentLineNumber)
|
||||
EfiSectionObj.Alignment = self._Token
|
||||
elif self._IsKeyword("Xip"):
|
||||
if not self._IsToken(TAB_EQUAL_SPLIT):
|
||||
raise Warning.ExpectedEquals(self.FileName, self.CurrentLineNumber)
|
||||
if not self._GetNextWord():
|
||||
raise Warning.Expected("Xip value (TRUE/FALSE)", self.FileName, self.CurrentLineNumber)
|
||||
XipValue = self._Token.strip().upper()
|
||||
if XipValue not in {"TRUE", "FALSE"}:
|
||||
raise Warning("Invalid Xip value '%s'" % XipValue, self.FileName, self.CurrentLineNumber)
|
||||
EfiSectionObj.Xip = XipValue
|
||||
elif self._IsKeyword('RELOCS_STRIPPED') or self._IsKeyword('RELOCS_RETAINED'):
|
||||
if self._SectionCouldHaveRelocFlag(EfiSectionObj.SectionType):
|
||||
if self._Token == 'RELOCS_STRIPPED':
|
||||
EfiSectionObj.KeepReloc = False
|
||||
else:
|
||||
EfiSectionObj.KeepReloc = True
|
||||
if Obj.KeepReloc is not None and Obj.KeepReloc != EfiSectionObj.KeepReloc:
|
||||
raise Warning("Section type %s has reloc strip flag conflict with Rule" % EfiSectionObj.SectionType, self.FileName, self.CurrentLineNumber)
|
||||
else:
|
||||
EfiSectionObj.KeepReloc = True
|
||||
if Obj.KeepReloc is not None and Obj.KeepReloc != EfiSectionObj.KeepReloc:
|
||||
raise Warning("Section type %s has reloc strip flag conflict with Rule" % EfiSectionObj.SectionType, self.FileName, self.CurrentLineNumber)
|
||||
raise Warning("Section type %s could not have reloc strip flag" % EfiSectionObj.SectionType, self.FileName, self.CurrentLineNumber)
|
||||
else:
|
||||
raise Warning("Section type %s could not have reloc strip flag" % EfiSectionObj.SectionType, self.FileName, self.CurrentLineNumber)
|
||||
break
|
||||
|
||||
|
||||
if self._IsToken(TAB_VALUE_SPLIT):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue