From 1bfcf64f39ce33fd6529c91fad6e9fe50f1698b1 Mon Sep 17 00:00:00 2001 From: Yonghong Zhu Date: Tue, 13 Mar 2018 22:44:01 +0800 Subject: BaseTools: Fix a bug for VOID* type Fixatbuild Pcd in Library The case is a FixedAtBuild VOID* PCD is used from a lib, but is set to a different sized value in a module INF scope section. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Yonghong Zhu Reviewed-by: Liming Gao --- BaseTools/Source/Python/AutoGen/GenC.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/BaseTools/Source/Python/AutoGen/GenC.py b/BaseTools/Source/Python/AutoGen/GenC.py index 36dc0ff..8c10e30 100644 --- a/BaseTools/Source/Python/AutoGen/GenC.py +++ b/BaseTools/Source/Python/AutoGen/GenC.py @@ -917,6 +917,7 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd): PatchPcdSizeTokenName = '_PCD_PATCHABLE_' + TokenCName +'_SIZE' PatchPcdSizeVariableName = '_gPcd_BinaryPatch_Size_' + TokenCName FixPcdSizeTokenName = '_PCD_SIZE_' + TokenCName + FixedPcdSizeVariableName = '_gPcd_FixedAtBuild_Size_' + TokenCName if Pcd.PcdValueFromComm: Pcd.DefaultValue = Pcd.PcdValueFromComm @@ -1151,7 +1152,7 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd): if Pcd.Type == TAB_PCDS_FIXED_AT_BUILD: AutoGenH.Append('#define %s %s\n' % (FixPcdSizeTokenName, PcdDataSize)) AutoGenH.Append('#define %s %s \n' % (GetModeSizeName,FixPcdSizeTokenName)) - + AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED const UINTN %s = %s;\n' % (FixedPcdSizeVariableName,PcdDataSize)) if Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE: AutoGenH.Append('#define %s %s\n' % (PatchPcdSizeTokenName, Pcd.MaxDatumSize)) AutoGenH.Append('#define %s %s \n' % (GetModeSizeName,PatchPcdSizeVariableName)) @@ -1208,6 +1209,7 @@ def CreateLibraryPcdCode(Info, AutoGenC, AutoGenH, Pcd): FixPcdSizeTokenName = '_PCD_SIZE_' + TokenCName PatchPcdSizeTokenName = '_PCD_PATCHABLE_' + TokenCName +'_SIZE' PatchPcdSizeVariableName = '_gPcd_BinaryPatch_Size_' + TokenCName + FixedPcdSizeVariableName = '_gPcd_FixedAtBuild_Size_' + TokenCName if Pcd.PcdValueFromComm: Pcd.DefaultValue = Pcd.PcdValueFromComm @@ -1348,16 +1350,26 @@ def CreateLibraryPcdCode(Info, AutoGenC, AutoGenH, Pcd): AutoGenH.Append('#define %s %s_gPcd_FixedAtBuild_%s\n' %(GetModeName, Type, TokenCName)) AutoGenH.Append('//#define %s ASSERT(FALSE) // It is not allowed to set value for a FIXED_AT_BUILD PCD\n' % SetModeName) + ConstFixedPcd = False if PcdItemType == TAB_PCDS_FIXED_AT_BUILD and (key in Info.ConstPcd or (Info.IsLibrary and not Info._ReferenceModules)): + ConstFixedPcd = True if Pcd.DatumType not in _NumericDataTypesList: AutoGenH.Append('#define _PCD_VALUE_%s %s%s\n' %(TokenCName, Type, PcdVariableName)) else: AutoGenH.Append('#define _PCD_VALUE_%s %s\n' %(TokenCName, Pcd.DefaultValue)) - + PcdDataSize = GetPcdSize(Pcd) if PcdItemType == TAB_PCDS_FIXED_AT_BUILD: - PcdDataSize = GetPcdSize(Pcd) - AutoGenH.Append('#define %s %s\n' % (FixPcdSizeTokenName, PcdDataSize)) - AutoGenH.Append('#define %s %s\n' % (GetModeSizeName,FixPcdSizeTokenName)) + if Pcd.DatumType not in _NumericDataTypesList: + if ConstFixedPcd: + AutoGenH.Append('#define %s %s\n' % (FixPcdSizeTokenName, PcdDataSize)) + AutoGenH.Append('#define %s %s\n' % (GetModeSizeName,FixPcdSizeTokenName)) + else: + AutoGenH.Append('#define %s %s\n' % (GetModeSizeName,FixedPcdSizeVariableName)) + AutoGenH.Append('#define %s %s\n' % (FixPcdSizeTokenName,FixedPcdSizeVariableName)) + AutoGenH.Append('extern const UINTN %s; \n' % FixedPcdSizeVariableName) + else: + AutoGenH.Append('#define %s %s\n' % (FixPcdSizeTokenName, PcdDataSize)) + AutoGenH.Append('#define %s %s\n' % (GetModeSizeName,FixPcdSizeTokenName)) ## Create code for library constructor # -- cgit v1.1