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:
Michael D Kinney 2026-05-19 12:51:42 -07:00 committed by mergify[bot]
parent 80bf0137c1
commit d6eb4c4965

View file

@ -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):