[edk2-devel] [PATCH v1] MdePkg: Use __builtin_offset with CLANGPDB toolchain

Alex James posted 1 patch 1 week ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/edk2 tags/patchew/20191128055645.53053-1-theracermaster@gmail.com
MdePkg/Include/Base.h | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)

[edk2-devel] [PATCH v1] MdePkg: Use __builtin_offset with CLANGPDB toolchain

Posted by Alex James 1 week ago
CLANGPDB does not define __GNUC__, but it does define __clang__. Check
for the __clang__ preprocessor definition to use __builtin_offsetof to
implement the OFFSET_OF macro.

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Signed-off-by: Alex James <theracermaster@gmail.com>
---
 MdePkg/Include/Base.h | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/MdePkg/Include/Base.h b/MdePkg/Include/Base.h
index 4680e64136..e0bcd0ae67 100644
--- a/MdePkg/Include/Base.h
+++ b/MdePkg/Include/Base.h
@@ -781,11 +781,9 @@ typedef UINTN  *BASE_LIST;
   @return  Offset, in bytes, of field.
 
 **/
-#ifdef __GNUC__
-#if __GNUC__ >= 4
+#if (defined(__GNUC__) && __GNUC__ >= 4) || defined(__clang__)
 #define OFFSET_OF(TYPE, Field) ((UINTN) __builtin_offsetof(TYPE, Field))
 #endif
-#endif
 
 #ifndef OFFSET_OF
 #define OFFSET_OF(TYPE, Field) ((UINTN) &(((TYPE *)0)->Field))
-- 
2.24.0


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#51446): https://edk2.groups.io/g/devel/message/51446
Mute This Topic: https://groups.io/mt/64067723/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-

Re: [edk2-devel] [PATCH v1] MdePkg: Use __builtin_offset with CLANGPDB toolchain

Posted by Liming Gao 1 week ago
BZ https://bugzilla.tianocore.org/show_bug.cgi?id=2393 is submitted to record this issue. 

This is the corner issue when STATIC_ASSERT and OFFSET_OF are used together. So, I think we can fix it after stable tag 201911.

Thanks
Liming
>-----Original Message-----
>From: Alex James [mailto:theracermaster@gmail.com]
>Sent: Thursday, November 28, 2019 1:57 PM
>To: devel@edk2.groups.io
>Cc: Kinney, Michael D <michael.d.kinney@intel.com>; Gao, Liming
><liming.gao@intel.com>
>Subject: [PATCH v1] MdePkg: Use __builtin_offset with CLANGPDB toolchain
>
>CLANGPDB does not define __GNUC__, but it does define __clang__. Check
>for the __clang__ preprocessor definition to use __builtin_offsetof to
>implement the OFFSET_OF macro.
>
>Cc: Michael D Kinney <michael.d.kinney@intel.com>
>Cc: Liming Gao <liming.gao@intel.com>
>Signed-off-by: Alex James <theracermaster@gmail.com>
>---
> MdePkg/Include/Base.h | 4 +---
> 1 file changed, 1 insertion(+), 3 deletions(-)
>
>diff --git a/MdePkg/Include/Base.h b/MdePkg/Include/Base.h
>index 4680e64136..e0bcd0ae67 100644
>--- a/MdePkg/Include/Base.h
>+++ b/MdePkg/Include/Base.h
>@@ -781,11 +781,9 @@ typedef UINTN  *BASE_LIST;
>   @return  Offset, in bytes, of field.
>
>
>
> **/
>
>-#ifdef __GNUC__
>
>-#if __GNUC__ >= 4
>
>+#if (defined(__GNUC__) && __GNUC__ >= 4) || defined(__clang__)
>
> #define OFFSET_OF(TYPE, Field) ((UINTN) __builtin_offsetof(TYPE, Field))
>
> #endif
>
>-#endif
>
>
>
> #ifndef OFFSET_OF
>
> #define OFFSET_OF(TYPE, Field) ((UINTN) &(((TYPE *)0)->Field))
>
>--
>2.24.0


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#51485): https://edk2.groups.io/g/devel/message/51485
Mute This Topic: https://groups.io/mt/64067723/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-

Re: [edk2-devel] [PATCH v1] MdePkg: Use __builtin_offset with CLANGPDB toolchain

Posted by Liming Gao 1 week ago
Alex:
  Do you find the real issue without this fix? Or is this change just an enhancement? 

  As you know, now we are in hard code freeze phase. Only functional bug is allowed. 

Thanks
Liming
>-----Original Message-----
>From: Alex James [mailto:theracermaster@gmail.com]
>Sent: Thursday, November 28, 2019 1:57 PM
>To: devel@edk2.groups.io
>Cc: Kinney, Michael D <michael.d.kinney@intel.com>; Gao, Liming
><liming.gao@intel.com>
>Subject: [PATCH v1] MdePkg: Use __builtin_offset with CLANGPDB toolchain
>
>CLANGPDB does not define __GNUC__, but it does define __clang__. Check
>for the __clang__ preprocessor definition to use __builtin_offsetof to
>implement the OFFSET_OF macro.
>
>Cc: Michael D Kinney <michael.d.kinney@intel.com>
>Cc: Liming Gao <liming.gao@intel.com>
>Signed-off-by: Alex James <theracermaster@gmail.com>
>---
> MdePkg/Include/Base.h | 4 +---
> 1 file changed, 1 insertion(+), 3 deletions(-)
>
>diff --git a/MdePkg/Include/Base.h b/MdePkg/Include/Base.h
>index 4680e64136..e0bcd0ae67 100644
>--- a/MdePkg/Include/Base.h
>+++ b/MdePkg/Include/Base.h
>@@ -781,11 +781,9 @@ typedef UINTN  *BASE_LIST;
>   @return  Offset, in bytes, of field.
>
>
>
> **/
>
>-#ifdef __GNUC__
>
>-#if __GNUC__ >= 4
>
>+#if (defined(__GNUC__) && __GNUC__ >= 4) || defined(__clang__)
>
> #define OFFSET_OF(TYPE, Field) ((UINTN) __builtin_offsetof(TYPE, Field))
>
> #endif
>
>-#endif
>
>
>
> #ifndef OFFSET_OF
>
> #define OFFSET_OF(TYPE, Field) ((UINTN) &(((TYPE *)0)->Field))
>
>--
>2.24.0


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#51478): https://edk2.groups.io/g/devel/message/51478
Mute This Topic: https://groups.io/mt/64067723/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-

Re: [edk2-devel] [PATCH v1] MdePkg: Use __builtin_offset with CLANGPDB toolchain

Posted by Philippe Mathieu-Daudé 1 week ago
On 11/28/19 6:56 AM, Alex James via Groups.Io wrote:
> CLANGPDB does not define __GNUC__, but it does define __clang__. Check
> for the __clang__ preprocessor definition to use __builtin_offsetof to
> implement the OFFSET_OF macro.
> 
> Cc: Michael D Kinney <michael.d.kinney@intel.com>
> Cc: Liming Gao <liming.gao@intel.com>
> Signed-off-by: Alex James <theracermaster@gmail.com>
> ---
>   MdePkg/Include/Base.h | 4 +---
>   1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/MdePkg/Include/Base.h b/MdePkg/Include/Base.h
> index 4680e64136..e0bcd0ae67 100644
> --- a/MdePkg/Include/Base.h
> +++ b/MdePkg/Include/Base.h
> @@ -781,11 +781,9 @@ typedef UINTN  *BASE_LIST;
>     @return  Offset, in bytes, of field.
>   
>   **/
> -#ifdef __GNUC__
> -#if __GNUC__ >= 4
> +#if (defined(__GNUC__) && __GNUC__ >= 4) || defined(__clang__)
>   #define OFFSET_OF(TYPE, Field) ((UINTN) __builtin_offsetof(TYPE, Field))
>   #endif
> -#endif
>   
>   #ifndef OFFSET_OF
>   #define OFFSET_OF(TYPE, Field) ((UINTN) &(((TYPE *)0)->Field))
> 

Reviewed-by: Philippe Mathieu-Daude <philmd@redhat.com>


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#51453): https://edk2.groups.io/g/devel/message/51453
Mute This Topic: https://groups.io/mt/64067723/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-