public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [Patch] BaseTools: Fix a bug for VOID* type Fixatbuild Pcd in Library
@ 2018-03-23  5:57 Yonghong Zhu
  2018-04-09  5:43 ` Gao, Liming
  0 siblings, 1 reply; 2+ messages in thread
From: Yonghong Zhu @ 2018-03-23  5:57 UTC (permalink / raw)
  To: edk2-devel

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 <PcdsFixedAtBuild> section.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Yonghong Zhu <yonghong.zhu@intel.com>
---
 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 481c4dd..fbf892f 100644
--- a/BaseTools/Source/Python/AutoGen/GenC.py
+++ b/BaseTools/Source/Python/AutoGen/GenC.py
@@ -913,10 +913,11 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):
             break
     PcdTokenName = '_PCD_TOKEN_' + TokenCName
     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
     
     if Pcd.Type in gDynamicExPcd:
@@ -1152,11 +1153,11 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):
                 
             PcdDataSize = GetPcdSize(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))
                 AutoGenH.Append('extern UINTN %s; \n' % PatchPcdSizeVariableName)
                 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED UINTN %s = %s;\n' % (PatchPcdSizeVariableName,PcdDataSize))
@@ -1209,10 +1210,11 @@ def CreateLibraryPcdCode(Info, AutoGenC, AutoGenH, Pcd):
             break
     PcdTokenName = '_PCD_TOKEN_' + TokenCName
     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
     #
     # Write PCDs
@@ -1349,20 +1351,30 @@ def CreateLibraryPcdCode(Info, AutoGenC, AutoGenH, Pcd):
             DatumType = 'UINT8'
         AutoGenH.Append('extern const %s _gPcd_FixedAtBuild_%s%s;\n' %(DatumType, TokenCName, Array))
         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 ['UINT8', 'UINT16', 'UINT32', 'UINT64', 'BOOLEAN']:
                 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 ['UINT8', 'UINT16', 'UINT32', 'UINT64', 'BOOLEAN']:
+                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
 #
 #   @param      Info        The ModuleAutoGen object
 #   @param      AutoGenC    The TemplateString object for C code
-- 
2.6.1.windows.1



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [Patch] BaseTools: Fix a bug for VOID* type Fixatbuild Pcd in Library
  2018-03-23  5:57 [Patch] BaseTools: Fix a bug for VOID* type Fixatbuild Pcd in Library Yonghong Zhu
@ 2018-04-09  5:43 ` Gao, Liming
  0 siblings, 0 replies; 2+ messages in thread
From: Gao, Liming @ 2018-04-09  5:43 UTC (permalink / raw)
  To: Zhu, Yonghong, edk2-devel@lists.01.org

Reviewed-by: Liming Gao <liming.gao@intel.com>

>-----Original Message-----
>From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of
>Yonghong Zhu
>Sent: Friday, March 23, 2018 1:57 PM
>To: edk2-devel@lists.01.org
>Subject: [edk2] [Patch] 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 <PcdsFixedAtBuild> section.
>
>Contributed-under: TianoCore Contribution Agreement 1.1
>Signed-off-by: Yonghong Zhu <yonghong.zhu@intel.com>
>---
> 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 481c4dd..fbf892f 100644
>--- a/BaseTools/Source/Python/AutoGen/GenC.py
>+++ b/BaseTools/Source/Python/AutoGen/GenC.py
>@@ -913,10 +913,11 @@ def CreateModulePcdCode(Info, AutoGenC,
>AutoGenH, Pcd):
>             break
>     PcdTokenName = '_PCD_TOKEN_' + TokenCName
>     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
>
>     if Pcd.Type in gDynamicExPcd:
>@@ -1152,11 +1153,11 @@ def CreateModulePcdCode(Info, AutoGenC,
>AutoGenH, Pcd):
>
>             PcdDataSize = GetPcdSize(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))
>                 AutoGenH.Append('extern UINTN %s; \n' %
>PatchPcdSizeVariableName)
>                 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED UINTN %s
>= %s;\n' % (PatchPcdSizeVariableName,PcdDataSize))
>@@ -1209,10 +1210,11 @@ def CreateLibraryPcdCode(Info, AutoGenC,
>AutoGenH, Pcd):
>             break
>     PcdTokenName = '_PCD_TOKEN_' + TokenCName
>     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
>     #
>     # Write PCDs
>@@ -1349,20 +1351,30 @@ def CreateLibraryPcdCode(Info, AutoGenC,
>AutoGenH, Pcd):
>             DatumType = 'UINT8'
>         AutoGenH.Append('extern const %s
>_gPcd_FixedAtBuild_%s%s;\n' %(DatumType, TokenCName, Array))
>
>AutoGenH.Append('#define %s  %s_gPcd_FixedAtBuild_%s\n' %(GetModeN
>ame, 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 ['UINT8', 'UINT16', 'UINT32', 'UINT64',
>'BOOLEAN']:
>                 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 ['UINT8', 'UINT16', 'UINT32', 'UINT64',
>'BOOLEAN']:
>+                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
> #
> #   @param      Info        The ModuleAutoGen object
> #   @param      AutoGenC    The TemplateString object for C code
>--
>2.6.1.windows.1
>
>_______________________________________________
>edk2-devel mailing list
>edk2-devel@lists.01.org
>https://lists.01.org/mailman/listinfo/edk2-devel


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-04-09  5:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-03-23  5:57 [Patch] BaseTools: Fix a bug for VOID* type Fixatbuild Pcd in Library Yonghong Zhu
2018-04-09  5:43 ` Gao, Liming

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox