public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH v2] BaseTools: Correct initialization data size check for array PCDs
@ 2022-08-30 10:20 Konstantin Aladyshev
  2022-09-27  2:17 ` 回复: " gaoliming
  2022-10-01 14:43 ` Bob Feng
  0 siblings, 2 replies; 3+ messages in thread
From: Konstantin Aladyshev @ 2022-08-30 10:20 UTC (permalink / raw)
  To: devel; +Cc: bob.c.feng, gaoliming, yuwei.chen, Konstantin Aladyshev

Currently it is not possible to initialize all elements in the
array PCD.

For example, this PCD would result to a build failure:
gTokenSpaceGuid.PcdArray|{0x11, 0x22}|UINT8[2]|0x4C4CB9A3

Correct logical operator in the initialization data size checks to
fix the issue.

Signed-off-by: Konstantin Aladyshev <aladyshev22@gmail.com>
---
 .../Source/Python/Workspace/DscBuildData.py      | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py b/BaseTools/Source/Python/Workspace/DscBuildData.py
index e9f68384b4..73c6ee4006 100644
--- a/BaseTools/Source/Python/Workspace/DscBuildData.py
+++ b/BaseTools/Source/Python/Workspace/DscBuildData.py
@@ -2089,12 +2089,12 @@ class DscBuildData(PlatformBuildClassObject):
                 pcdarraysize = Pcd.PcdArraySize()
                 if "{CODE(" in Pcd.DefaultValueFromDec:
                     if Pcd.Capacity[-1] != "-1":
-                        CApp = CApp + '__STATIC_ASSERT(sizeof(%s_%s_INIT_Value) < %d * sizeof(%s), "Pcd %s.%s Value in Dec exceed the array capability %s"); // From  %s Line %s \n ' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCName, Pcd.TokenCName,Pcd.DatumType,Pcd.DefaultValueFromDecInfo[0],Pcd.DefaultValueFromDecInfo[1])
+                        CApp = CApp + '__STATIC_ASSERT(sizeof(%s_%s_INIT_Value) <= %d * sizeof(%s), "Pcd %s.%s Value in Dec exceed the array capability %s"); // From  %s Line %s \n ' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCName, Pcd.TokenCName,Pcd.DatumType,Pcd.DefaultValueFromDecInfo[0],Pcd.DefaultValueFromDecInfo[1])
                     CApp = CApp + ' PcdArraySize = sizeof(%s_%s_INIT_Value);\n ' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName)
                     CApp = CApp + '  memcpy (Pcd, %s_%s_INIT_Value,PcdArraySize);\n ' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName)
                 else:
                     if Pcd.Capacity[-1] != "-1":
-                        CApp = CApp + '__STATIC_ASSERT(%d < %d * sizeof(%s), "Pcd %s.%s Value in Dec exceed the array capability %s"); // From %s Line %s \n' % (ValueSize,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCName, Pcd.TokenCName,Pcd.DatumType,Pcd.DefaultValueFromDecInfo[0],Pcd.DefaultValueFromDecInfo[1])
+                        CApp = CApp + '__STATIC_ASSERT(%d <= %d * sizeof(%s), "Pcd %s.%s Value in Dec exceed the array capability %s"); // From %s Line %s \n' % (ValueSize,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCName, Pcd.TokenCName,Pcd.DatumType,Pcd.DefaultValueFromDecInfo[0],Pcd.DefaultValueFromDecInfo[1])
                     CApp = CApp + ' PcdArraySize = %d;\n' % ValueSize
                     CApp = CApp + '  Value     = %s; // From DEC Default Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize), Pcd.DefaultValueFromDec)
                     CApp = CApp + '  memcpy (Pcd, Value, PcdArraySize);\n'
@@ -2204,7 +2204,7 @@ class DscBuildData(PlatformBuildClassObject):
                     if "{CODE(" in Value:
                         if Pcd.IsArray() and Pcd.Capacity[-1] != "-1":
                             pcdarraysize = Pcd.PcdArraySize()
-                            CApp = CApp + '__STATIC_ASSERT(sizeof(%s_%s_%s_%s_Value) < %d * sizeof(%s), "Pcd %s.%s Value in Dsc exceed the array capability %s"); // From %s \n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultStoreName,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCName, Pcd.TokenCName,Pcd.DatumType, valuefrom)
+                            CApp = CApp + '__STATIC_ASSERT(sizeof(%s_%s_%s_%s_Value) <= %d * sizeof(%s), "Pcd %s.%s Value in Dsc exceed the array capability %s"); // From %s \n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultStoreName,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCName, Pcd.TokenCName,Pcd.DatumType, valuefrom)
                         CApp = CApp+ ' PcdArraySize = sizeof(%s_%s_%s_%s_Value);\n ' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultStoreName)
                         CApp = CApp + '  memcpy (Pcd, &%s_%s_%s_%s_Value,PcdArraySize);\n ' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultStoreName)
                     else:
@@ -2217,12 +2217,12 @@ class DscBuildData(PlatformBuildClassObject):
                         pcdarraysize = Pcd.PcdArraySize()
                         if "{CODE(" in pcddefaultvalue:
                             if Pcd.Capacity[-1] != "-1":
-                                CApp = CApp + '__STATIC_ASSERT(sizeof(%s_%s_%s_%s_Value) < %d * sizeof(%s), "Pcd %s.%s Value in Dsc exceed the array capability %s"); // From  %s \n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultStoreName,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCName, Pcd.TokenCName,Pcd.DatumType,valuefrom)
+                                CApp = CApp + '__STATIC_ASSERT(sizeof(%s_%s_%s_%s_Value) <= %d * sizeof(%s), "Pcd %s.%s Value in Dsc exceed the array capability %s"); // From  %s \n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultStoreName,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCName, Pcd.TokenCName,Pcd.DatumType,valuefrom)
                             CApp = CApp + ' PcdArraySize = sizeof(%s_%s_%s_%s_Value);\n ' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultStoreName)
                             CApp = CApp + '  memcpy (Pcd, %s_%s_%s_%s_Value, PcdArraySize);\n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultStoreName)
                         else:
                             if Pcd.Capacity[-1] != "-1":
-                                CApp = CApp + '__STATIC_ASSERT(%d < %d * sizeof(%s), "Pcd %s.%s Value in Dsc exceed the array capability %s"); // From  %s \n' % (ValueSize,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCName, Pcd.TokenCName,Pcd.DatumType,valuefrom)
+                                CApp = CApp + '__STATIC_ASSERT(%d <= %d * sizeof(%s), "Pcd %s.%s Value in Dsc exceed the array capability %s"); // From  %s \n' % (ValueSize,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCName, Pcd.TokenCName,Pcd.DatumType,valuefrom)
                             CApp = CApp + ' PcdArraySize = %d;\n' % ValueSize
                             CApp = CApp + '  Value     = %s; // From DSC Default Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize), Pcd.DefaultFromDSC.get(TAB_DEFAULT, {}).get(TAB_DEFAULT_STORES_DEFAULT, Pcd.DefaultValue) if Pcd.DefaultFromDSC else Pcd.DefaultValue)
                             CApp = CApp + '  memcpy (Pcd, Value, PcdArraySize);\n'
@@ -2238,7 +2238,7 @@ class DscBuildData(PlatformBuildClassObject):
                     if "{CODE(" in Value:
                         if Pcd.IsArray() and Pcd.Capacity[-1] != "-1":
                             pcdarraysize = Pcd.PcdArraySize()
-                            CApp = CApp + '__STATIC_ASSERT(sizeof(%s_%s_%s_%s_Value) < %d * sizeof(%s), "Pcd %s.%s Value in Dsc exceed the array capability %s"); // From %s \n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultStoreName,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCName, Pcd.TokenCName,Pcd.DatumType,valuefrom)
+                            CApp = CApp + '__STATIC_ASSERT(sizeof(%s_%s_%s_%s_Value) <= %d * sizeof(%s), "Pcd %s.%s Value in Dsc exceed the array capability %s"); // From %s \n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultStoreName,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCName, Pcd.TokenCName,Pcd.DatumType,valuefrom)
                         CApp = CApp + ' PcdArraySize = sizeof(%s_%s_%s_%s_Value);\n '% (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultStoreName)
                         CApp = CApp + '  memcpy (Pcd, &%s_%s_%s_%s_Value, PcdArraySize);\n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultStoreName)
                     else:
@@ -2251,12 +2251,12 @@ class DscBuildData(PlatformBuildClassObject):
                         pcdarraysize = Pcd.PcdArraySize()
                         if "{CODE(" in pcddefaultvalue:
                             if Pcd.Capacity[-1] != "-1":
-                                CApp = CApp + '__STATIC_ASSERT(sizeof(%s_%s_%s_%s_Value) < %d * sizeof(%s), "Pcd %s.%s Value in Dsc exceed the array capability %s"); // From  %s \n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultStoreName,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCName, Pcd.TokenCName,Pcd.DatumType,valuefrom)
+                                CApp = CApp + '__STATIC_ASSERT(sizeof(%s_%s_%s_%s_Value) <= %d * sizeof(%s), "Pcd %s.%s Value in Dsc exceed the array capability %s"); // From  %s \n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultStoreName,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCName, Pcd.TokenCName,Pcd.DatumType,valuefrom)
                             CApp + ' PcdArraySize = sizeof(%s_%s_%s_%s_Value);\n ' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultStoreName)
                             CApp = CApp + '  memcpy (Pcd, %s_%s_%s_%s_Value, PcdArraySize);\n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultStoreName)
                         else:
                             if Pcd.Capacity[-1] != "-1":
-                                CApp = CApp + '__STATIC_ASSERT(%d < %d * sizeof(%s), "Pcd %s.%s Value in Dsc exceed the array capability %s"); // From  %s \n' % (ValueSize,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCName, Pcd.TokenCName,Pcd.DatumType,valuefrom)
+                                CApp = CApp + '__STATIC_ASSERT(%d <= %d * sizeof(%s), "Pcd %s.%s Value in Dsc exceed the array capability %s"); // From  %s \n' % (ValueSize,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCName, Pcd.TokenCName,Pcd.DatumType,valuefrom)
                             CApp = CApp + ' PcdArraySize = %d;\n' % ValueSize
                             CApp = CApp + '  Value     = %s; // From DSC Default Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize), Pcd.DscRawValue.get(TAB_DEFAULT, {}).get(TAB_DEFAULT_STORES_DEFAULT, Pcd.DefaultValue) if Pcd.DefaultFromDSC else Pcd.DefaultValue)
                             CApp = CApp + '  memcpy (Pcd, Value, PcdArraySize);\n'
-- 
2.25.1


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

* 回复: [PATCH v2] BaseTools: Correct initialization data size check for array PCDs
  2022-08-30 10:20 [PATCH v2] BaseTools: Correct initialization data size check for array PCDs Konstantin Aladyshev
@ 2022-09-27  2:17 ` gaoliming
  2022-10-01 14:43 ` Bob Feng
  1 sibling, 0 replies; 3+ messages in thread
From: gaoliming @ 2022-09-27  2:17 UTC (permalink / raw)
  To: 'Konstantin Aladyshev', devel; +Cc: bob.c.feng, yuwei.chen

Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>

> -----邮件原件-----
> 发件人: Konstantin Aladyshev <aladyshev22@gmail.com>
> 发送时间: 2022年8月30日 18:21
> 收件人: devel@edk2.groups.io
> 抄送: bob.c.feng@intel.com; gaoliming@byosoft.com.cn;
> yuwei.chen@intel.com; Konstantin Aladyshev <aladyshev22@gmail.com>
> 主题: [PATCH v2] BaseTools: Correct initialization data size check for
array
> PCDs
> 
> Currently it is not possible to initialize all elements in the
> array PCD.
> 
> For example, this PCD would result to a build failure:
> gTokenSpaceGuid.PcdArray|{0x11, 0x22}|UINT8[2]|0x4C4CB9A3
> 
> Correct logical operator in the initialization data size checks to
> fix the issue.
> 
> Signed-off-by: Konstantin Aladyshev <aladyshev22@gmail.com>
> ---
>  .../Source/Python/Workspace/DscBuildData.py      | 16 ++++++++--------
>  1 file changed, 8 insertions(+), 8 deletions(-)
> 
> diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py
> b/BaseTools/Source/Python/Workspace/DscBuildData.py
> index e9f68384b4..73c6ee4006 100644
> --- a/BaseTools/Source/Python/Workspace/DscBuildData.py
> +++ b/BaseTools/Source/Python/Workspace/DscBuildData.py
> @@ -2089,12 +2089,12 @@ class DscBuildData(PlatformBuildClassObject):
>                  pcdarraysize = Pcd.PcdArraySize()
> 
>                  if "{CODE(" in Pcd.DefaultValueFromDec:
> 
>                      if Pcd.Capacity[-1] != "-1":
> 
> -                        CApp = CApp +
> '__STATIC_ASSERT(sizeof(%s_%s_INIT_Value) < %d * sizeof(%s), "Pcd %s.%s
> Value in Dec exceed the array capability %s"); // From  %s Line %s \n ' %
> (Pcd.TokenSpaceGuidCName,
> Pcd.TokenCName,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCNa
> me,
> Pcd.TokenCName,Pcd.DatumType,Pcd.DefaultValueFromDecInfo[0],Pcd.Defa
> ultValueFromDecInfo[1])
> 
> +                        CApp = CApp +
> '__STATIC_ASSERT(sizeof(%s_%s_INIT_Value) <= %d * sizeof(%s), "Pcd %s.%s
> Value in Dec exceed the array capability %s"); // From  %s Line %s \n ' %
> (Pcd.TokenSpaceGuidCName,
> Pcd.TokenCName,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCNa
> me,
> Pcd.TokenCName,Pcd.DatumType,Pcd.DefaultValueFromDecInfo[0],Pcd.Defa
> ultValueFromDecInfo[1])
> 
>                      CApp = CApp + ' PcdArraySize =
> sizeof(%s_%s_INIT_Value);\n ' % (Pcd.TokenSpaceGuidCName,
> Pcd.TokenCName)
> 
>                      CApp = CApp + '  memcpy
> (Pcd, %s_%s_INIT_Value,PcdArraySize);\n ' % (Pcd.TokenSpaceGuidCName,
> Pcd.TokenCName)
> 
>                  else:
> 
>                      if Pcd.Capacity[-1] != "-1":
> 
> -                        CApp = CApp + '__STATIC_ASSERT(%d < %d *
> sizeof(%s), "Pcd %s.%s Value in Dec exceed the array capability %s"); //
> From %s Line %s \n' %
> (ValueSize,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCName,
> Pcd.TokenCName,Pcd.DatumType,Pcd.DefaultValueFromDecInfo[0],Pcd.Defa
> ultValueFromDecInfo[1])
> 
> +                        CApp = CApp + '__STATIC_ASSERT(%d <= %d *
> sizeof(%s), "Pcd %s.%s Value in Dec exceed the array capability %s"); //
> From %s Line %s \n' %
> (ValueSize,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCName,
> Pcd.TokenCName,Pcd.DatumType,Pcd.DefaultValueFromDecInfo[0],Pcd.Defa
> ultValueFromDecInfo[1])
> 
>                      CApp = CApp + ' PcdArraySize = %d;\n' % ValueSize
> 
>                      CApp = CApp + '  Value     = %s; // From DEC
> Default Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize),
> Pcd.DefaultValueFromDec)
> 
>                      CApp = CApp + '  memcpy (Pcd, Value,
> PcdArraySize);\n'
> 
> @@ -2204,7 +2204,7 @@ class DscBuildData(PlatformBuildClassObject):
>                      if "{CODE(" in Value:
> 
>                          if Pcd.IsArray() and Pcd.Capacity[-1] != "-1":
> 
>                              pcdarraysize = Pcd.PcdArraySize()
> 
> -                            CApp = CApp +
> '__STATIC_ASSERT(sizeof(%s_%s_%s_%s_Value) < %d * sizeof(%s),
> "Pcd %s.%s Value in Dsc exceed the array capability %s"); // From %s \n' %
> (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName,
> DefaultStoreName,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCN
> ame, Pcd.TokenCName,Pcd.DatumType, valuefrom)
> 
> +                            CApp = CApp +
> '__STATIC_ASSERT(sizeof(%s_%s_%s_%s_Value) <= %d * sizeof(%s),
> "Pcd %s.%s Value in Dsc exceed the array capability %s"); // From %s \n' %
> (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName,
> DefaultStoreName,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCN
> ame, Pcd.TokenCName,Pcd.DatumType, valuefrom)
> 
>                          CApp = CApp+ ' PcdArraySize =
> sizeof(%s_%s_%s_%s_Value);\n ' % (Pcd.TokenSpaceGuidCName,
> Pcd.TokenCName,SkuName, DefaultStoreName)
> 
>                          CApp = CApp + '  memcpy (Pcd,
> &%s_%s_%s_%s_Value,PcdArraySize);\n ' % (Pcd.TokenSpaceGuidCName,
> Pcd.TokenCName,SkuName, DefaultStoreName)
> 
>                      else:
> 
> @@ -2217,12 +2217,12 @@ class DscBuildData(PlatformBuildClassObject):
>                          pcdarraysize = Pcd.PcdArraySize()
> 
>                          if "{CODE(" in pcddefaultvalue:
> 
>                              if Pcd.Capacity[-1] != "-1":
> 
> -                                CApp = CApp +
> '__STATIC_ASSERT(sizeof(%s_%s_%s_%s_Value) < %d * sizeof(%s),
> "Pcd %s.%s Value in Dsc exceed the array capability %s"); // From  %s \n'
%
> (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName,
> DefaultStoreName,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCN
> ame, Pcd.TokenCName,Pcd.DatumType,valuefrom)
> 
> +                                CApp = CApp +
> '__STATIC_ASSERT(sizeof(%s_%s_%s_%s_Value) <= %d * sizeof(%s),
> "Pcd %s.%s Value in Dsc exceed the array capability %s"); // From  %s \n'
%
> (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName,
> DefaultStoreName,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCN
> ame, Pcd.TokenCName,Pcd.DatumType,valuefrom)
> 
>                              CApp = CApp + ' PcdArraySize =
> sizeof(%s_%s_%s_%s_Value);\n ' % (Pcd.TokenSpaceGuidCName,
> Pcd.TokenCName,SkuName, DefaultStoreName)
> 
>                              CApp = CApp + '  memcpy
> (Pcd, %s_%s_%s_%s_Value, PcdArraySize);\n' % (Pcd.TokenSpaceGuidCName,
> Pcd.TokenCName,SkuName, DefaultStoreName)
> 
>                          else:
> 
>                              if Pcd.Capacity[-1] != "-1":
> 
> -                                CApp = CApp +
> '__STATIC_ASSERT(%d < %d * sizeof(%s), "Pcd %s.%s Value in Dsc exceed the
> array capability %s"); // From  %s \n' %
> (ValueSize,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCName,
> Pcd.TokenCName,Pcd.DatumType,valuefrom)
> 
> +                                CApp = CApp +
> '__STATIC_ASSERT(%d <= %d * sizeof(%s), "Pcd %s.%s Value in Dsc exceed the
> array capability %s"); // From  %s \n' %
> (ValueSize,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCName,
> Pcd.TokenCName,Pcd.DatumType,valuefrom)
> 
>                              CApp = CApp + ' PcdArraySize = %d;\n' %
> ValueSize
> 
>                              CApp = CApp + '  Value     = %s; //
> From DSC Default Value %s\n' % (DscBuildData.IntToCString(Value,
ValueSize),
> Pcd.DefaultFromDSC.get(TAB_DEFAULT,
> {}).get(TAB_DEFAULT_STORES_DEFAULT, Pcd.DefaultValue) if
> Pcd.DefaultFromDSC else Pcd.DefaultValue)
> 
>                              CApp = CApp + '  memcpy (Pcd, Value,
> PcdArraySize);\n'
> 
> @@ -2238,7 +2238,7 @@ class DscBuildData(PlatformBuildClassObject):
>                      if "{CODE(" in Value:
> 
>                          if Pcd.IsArray() and Pcd.Capacity[-1] != "-1":
> 
>                              pcdarraysize = Pcd.PcdArraySize()
> 
> -                            CApp = CApp +
> '__STATIC_ASSERT(sizeof(%s_%s_%s_%s_Value) < %d * sizeof(%s),
> "Pcd %s.%s Value in Dsc exceed the array capability %s"); // From %s \n' %
> (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName,
> DefaultStoreName,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCN
> ame, Pcd.TokenCName,Pcd.DatumType,valuefrom)
> 
> +                            CApp = CApp +
> '__STATIC_ASSERT(sizeof(%s_%s_%s_%s_Value) <= %d * sizeof(%s),
> "Pcd %s.%s Value in Dsc exceed the array capability %s"); // From %s \n' %
> (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName,
> DefaultStoreName,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCN
> ame, Pcd.TokenCName,Pcd.DatumType,valuefrom)
> 
>                          CApp = CApp + ' PcdArraySize =
> sizeof(%s_%s_%s_%s_Value);\n '% (Pcd.TokenSpaceGuidCName,
> Pcd.TokenCName,SkuName, DefaultStoreName)
> 
>                          CApp = CApp + '  memcpy (Pcd,
> &%s_%s_%s_%s_Value, PcdArraySize);\n' % (Pcd.TokenSpaceGuidCName,
> Pcd.TokenCName,SkuName, DefaultStoreName)
> 
>                      else:
> 
> @@ -2251,12 +2251,12 @@ class DscBuildData(PlatformBuildClassObject):
>                          pcdarraysize = Pcd.PcdArraySize()
> 
>                          if "{CODE(" in pcddefaultvalue:
> 
>                              if Pcd.Capacity[-1] != "-1":
> 
> -                                CApp = CApp +
> '__STATIC_ASSERT(sizeof(%s_%s_%s_%s_Value) < %d * sizeof(%s),
> "Pcd %s.%s Value in Dsc exceed the array capability %s"); // From  %s \n'
%
> (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName,
> DefaultStoreName,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCN
> ame, Pcd.TokenCName,Pcd.DatumType,valuefrom)
> 
> +                                CApp = CApp +
> '__STATIC_ASSERT(sizeof(%s_%s_%s_%s_Value) <= %d * sizeof(%s),
> "Pcd %s.%s Value in Dsc exceed the array capability %s"); // From  %s \n'
%
> (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName,
> DefaultStoreName,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCN
> ame, Pcd.TokenCName,Pcd.DatumType,valuefrom)
> 
>                              CApp + ' PcdArraySize =
> sizeof(%s_%s_%s_%s_Value);\n ' % (Pcd.TokenSpaceGuidCName,
> Pcd.TokenCName,SkuName, DefaultStoreName)
> 
>                              CApp = CApp + '  memcpy
> (Pcd, %s_%s_%s_%s_Value, PcdArraySize);\n' % (Pcd.TokenSpaceGuidCName,
> Pcd.TokenCName,SkuName, DefaultStoreName)
> 
>                          else:
> 
>                              if Pcd.Capacity[-1] != "-1":
> 
> -                                CApp = CApp +
> '__STATIC_ASSERT(%d < %d * sizeof(%s), "Pcd %s.%s Value in Dsc exceed the
> array capability %s"); // From  %s \n' %
> (ValueSize,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCName,
> Pcd.TokenCName,Pcd.DatumType,valuefrom)
> 
> +                                CApp = CApp +
> '__STATIC_ASSERT(%d <= %d * sizeof(%s), "Pcd %s.%s Value in Dsc exceed the
> array capability %s"); // From  %s \n' %
> (ValueSize,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCName,
> Pcd.TokenCName,Pcd.DatumType,valuefrom)
> 
>                              CApp = CApp + ' PcdArraySize = %d;\n' %
> ValueSize
> 
>                              CApp = CApp + '  Value     = %s; //
> From DSC Default Value %s\n' % (DscBuildData.IntToCString(Value,
ValueSize),
> Pcd.DscRawValue.get(TAB_DEFAULT, {}).get(TAB_DEFAULT_STORES_DEFAULT,
> Pcd.DefaultValue) if Pcd.DefaultFromDSC else Pcd.DefaultValue)
> 
>                              CApp = CApp + '  memcpy (Pcd, Value,
> PcdArraySize);\n'
> 
> --
> 2.25.1




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

* Re: [PATCH v2] BaseTools: Correct initialization data size check for array PCDs
  2022-08-30 10:20 [PATCH v2] BaseTools: Correct initialization data size check for array PCDs Konstantin Aladyshev
  2022-09-27  2:17 ` 回复: " gaoliming
@ 2022-10-01 14:43 ` Bob Feng
  1 sibling, 0 replies; 3+ messages in thread
From: Bob Feng @ 2022-10-01 14:43 UTC (permalink / raw)
  To: Konstantin Aladyshev, devel@edk2.groups.io; +Cc: Gao, Liming, Chen, Christine

Reviewed-by: Bob Feng <bob.c.feng@intel.com>

-----Original Message-----
From: Konstantin Aladyshev <aladyshev22@gmail.com> 
Sent: Tuesday, August 30, 2022 6:21 PM
To: devel@edk2.groups.io
Cc: Feng, Bob C <bob.c.feng@intel.com>; Gao, Liming <gaoliming@byosoft.com.cn>; Chen, Christine <yuwei.chen@intel.com>; Konstantin Aladyshev <aladyshev22@gmail.com>
Subject: [PATCH v2] BaseTools: Correct initialization data size check for array PCDs

Currently it is not possible to initialize all elements in the array PCD.

For example, this PCD would result to a build failure:
gTokenSpaceGuid.PcdArray|{0x11, 0x22}|UINT8[2]|0x4C4CB9A3

Correct logical operator in the initialization data size checks to fix the issue.

Signed-off-by: Konstantin Aladyshev <aladyshev22@gmail.com>
---
 .../Source/Python/Workspace/DscBuildData.py      | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py b/BaseTools/Source/Python/Workspace/DscBuildData.py
index e9f68384b4..73c6ee4006 100644
--- a/BaseTools/Source/Python/Workspace/DscBuildData.py
+++ b/BaseTools/Source/Python/Workspace/DscBuildData.py
@@ -2089,12 +2089,12 @@ class DscBuildData(PlatformBuildClassObject):
                 pcdarraysize = Pcd.PcdArraySize()                 if "{CODE(" in Pcd.DefaultValueFromDec:                     if Pcd.Capacity[-1] != "-1":-                        CApp = CApp + '__STATIC_ASSERT(sizeof(%s_%s_INIT_Value) < %d * sizeof(%s), "Pcd %s.%s Value in Dec exceed the array capability %s"); // From  %s Line %s \n ' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCName, Pcd.TokenCName,Pcd.DatumType,Pcd.DefaultValueFromDecInfo[0],Pcd.DefaultValueFromDecInfo[1])+                        CApp = CApp + '__STATIC_ASSERT(sizeof(%s_%s_INIT_Value) <= %d * sizeof(%s), "Pcd %s.%s Value in Dec exceed the array capability %s"); // From  %s Line %s \n ' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCName, Pcd.TokenCName,Pcd.DatumType,Pcd.DefaultValueFromDecInfo[0],Pcd.DefaultValueFromDecInfo[1])                     CApp = CApp + ' PcdArraySize = sizeof(%s_%s_INIT_Value);\n ' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName)                     CApp = CApp + '  memcpy (Pcd, %s_%s_INIT_Value,PcdArraySize);\n ' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName)                 else:                     if Pcd.Capacity[-1] != "-1":-                        CApp = CApp + '__STATIC_ASSERT(%d < %d * sizeof(%s), "Pcd %s.%s Value in Dec exceed the array capability %s"); // From %s Line %s \n' % (ValueSize,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCName, Pcd.TokenCName,Pcd.DatumType,Pcd.DefaultValueFromDecInfo[0],Pcd.DefaultValueFromDecInfo[1])+                        CApp = CApp + '__STATIC_ASSERT(%d <= %d * sizeof(%s), "Pcd %s.%s Value in Dec exceed the array capability %s"); // From %s Line %s \n' % (ValueSize,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCName, Pcd.TokenCName,Pcd.DatumType,Pcd.DefaultValueFromDecInfo[0],Pcd.DefaultValueFromDecInfo[1])                     CApp = CApp + ' PcdArraySize = %d;\n' % ValueSize                     CApp = CApp + '  Value     = %s; // From DEC Default Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize), Pcd.DefaultValueFromDec)                     CApp = CApp + '  memcpy (Pcd, Value, PcdArraySize);\n'@@ -2204,7 +2204,7 @@ class DscBuildData(PlatformBuildClassObject):
                     if "{CODE(" in Value:                         if Pcd.IsArray() and Pcd.Capacity[-1] != "-1":                             pcdarraysize = Pcd.PcdArraySize()-                            CApp = CApp + '__STATIC_ASSERT(sizeof(%s_%s_%s_%s_Value) < %d * sizeof(%s), "Pcd %s.%s Value in Dsc exceed the array capability %s"); // From %s \n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultStoreName,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCName, Pcd.TokenCName,Pcd.DatumType, valuefrom)+                            CApp = CApp + '__STATIC_ASSERT(sizeof(%s_%s_%s_%s_Value) <= %d * sizeof(%s), "Pcd %s.%s Value in Dsc exceed the array capability %s"); // From %s \n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultStoreName,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCName, Pcd.TokenCName,Pcd.DatumType, valuefrom)                         CApp = CApp+ ' PcdArraySize = sizeof(%s_%s_%s_%s_Value);\n ' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultStoreName)                         CApp = CApp + '  memcpy (Pcd, &%s_%s_%s_%s_Value,PcdArraySize);\n ' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultStoreName)                     else:@@ -2217,12 +2217,12 @@ class DscBuildData(PlatformBuildClassObject):
                         pcdarraysize = Pcd.PcdArraySize()                         if "{CODE(" in pcddefaultvalue:                             if Pcd.Capacity[-1] != "-1":-                                CApp = CApp + '__STATIC_ASSERT(sizeof(%s_%s_%s_%s_Value) < %d * sizeof(%s), "Pcd %s.%s Value in Dsc exceed the array capability %s"); // From  %s \n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultStoreName,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCName, Pcd.TokenCName,Pcd.DatumType,valuefrom)+                                CApp = CApp + '__STATIC_ASSERT(sizeof(%s_%s_%s_%s_Value) <= %d * sizeof(%s), "Pcd %s.%s Value in Dsc exceed the array capability %s"); // From  %s \n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultStoreName,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCName, Pcd.TokenCName,Pcd.DatumType,valuefrom)                             CApp = CApp + ' PcdArraySize = sizeof(%s_%s_%s_%s_Value);\n ' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultStoreName)                             CApp = CApp + '  memcpy (Pcd, %s_%s_%s_%s_Value, PcdArraySize);\n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultStoreName)                         else:                             if Pcd.Capacity[-1] != "-1":-                                CApp = CApp + '__STATIC_ASSERT(%d < %d * sizeof(%s), "Pcd %s.%s Value in Dsc exceed the array capability %s"); // From  %s \n' % (ValueSize,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCName, Pcd.TokenCName,Pcd.DatumType,valuefrom)+                                CApp = CApp + '__STATIC_ASSERT(%d <= %d * sizeof(%s), "Pcd %s.%s Value in Dsc exceed the array capability %s"); // From  %s \n' % (ValueSize,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCName, Pcd.TokenCName,Pcd.DatumType,valuefrom)                             CApp = CApp + ' PcdArraySize = %d;\n' % ValueSize                             CApp = CApp + '  Value     = %s; // From DSC Default Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize), Pcd.DefaultFromDSC.get(TAB_DEFAULT, {}).get(TAB_DEFAULT_STORES_DEFAULT, Pcd.DefaultValue) if Pcd.DefaultFromDSC else Pcd.DefaultValue)                             CApp = CApp + '  memcpy (Pcd, Value, PcdArraySize);\n'@@ -2238,7 +2238,7 @@ class DscBuildData(PlatformBuildClassObject):
                     if "{CODE(" in Value:                         if Pcd.IsArray() and Pcd.Capacity[-1] != "-1":                             pcdarraysize = Pcd.PcdArraySize()-                            CApp = CApp + '__STATIC_ASSERT(sizeof(%s_%s_%s_%s_Value) < %d * sizeof(%s), "Pcd %s.%s Value in Dsc exceed the array capability %s"); // From %s \n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultStoreName,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCName, Pcd.TokenCName,Pcd.DatumType,valuefrom)+                            CApp = CApp + '__STATIC_ASSERT(sizeof(%s_%s_%s_%s_Value) <= %d * sizeof(%s), "Pcd %s.%s Value in Dsc exceed the array capability %s"); // From %s \n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultStoreName,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCName, Pcd.TokenCName,Pcd.DatumType,valuefrom)                         CApp = CApp + ' PcdArraySize = sizeof(%s_%s_%s_%s_Value);\n '% (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultStoreName)                         CApp = CApp + '  memcpy (Pcd, &%s_%s_%s_%s_Value, PcdArraySize);\n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultStoreName)                     else:@@ -2251,12 +2251,12 @@ class DscBuildData(PlatformBuildClassObject):
                         pcdarraysize = Pcd.PcdArraySize()                         if "{CODE(" in pcddefaultvalue:                             if Pcd.Capacity[-1] != "-1":-                                CApp = CApp + '__STATIC_ASSERT(sizeof(%s_%s_%s_%s_Value) < %d * sizeof(%s), "Pcd %s.%s Value in Dsc exceed the array capability %s"); // From  %s \n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultStoreName,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCName, Pcd.TokenCName,Pcd.DatumType,valuefrom)+                                CApp = CApp + '__STATIC_ASSERT(sizeof(%s_%s_%s_%s_Value) <= %d * sizeof(%s), "Pcd %s.%s Value in Dsc exceed the array capability %s"); // From  %s \n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultStoreName,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCName, Pcd.TokenCName,Pcd.DatumType,valuefrom)                             CApp + ' PcdArraySize = sizeof(%s_%s_%s_%s_Value);\n ' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultStoreName)                             CApp = CApp + '  memcpy (Pcd, %s_%s_%s_%s_Value, PcdArraySize);\n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultStoreName)                         else:                             if Pcd.Capacity[-1] != "-1":-                                CApp = CApp + '__STATIC_ASSERT(%d < %d * sizeof(%s), "Pcd %s.%s Value in Dsc exceed the array capability %s"); // From  %s \n' % (ValueSize,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCName, Pcd.TokenCName,Pcd.DatumType,valuefrom)+                                CApp = CApp + '__STATIC_ASSERT(%d <= %d * sizeof(%s), "Pcd %s.%s Value in Dsc exceed the array capability %s"); // From  %s \n' % (ValueSize,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCName, Pcd.TokenCName,Pcd.DatumType,valuefrom)                             CApp = CApp + ' PcdArraySize = %d;\n' % ValueSize                             CApp = CApp + '  Value     = %s; // From DSC Default Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize), Pcd.DscRawValue.get(TAB_DEFAULT, {}).get(TAB_DEFAULT_STORES_DEFAULT, Pcd.DefaultValue) if Pcd.DefaultFromDSC else Pcd.DefaultValue)                             CApp = CApp + '  memcpy (Pcd, Value, PcdArraySize);\n'-- 
2.25.1


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

end of thread, other threads:[~2022-10-01 14:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-08-30 10:20 [PATCH v2] BaseTools: Correct initialization data size check for array PCDs Konstantin Aladyshev
2022-09-27  2:17 ` 回复: " gaoliming
2022-10-01 14:43 ` Bob Feng

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