From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from nwk-aaemail-lapp03.apple.com (nwk-aaemail-lapp03.apple.com [17.151.62.68]) by mx.groups.io with SMTP id smtpd.web12.29275.1595452443950401909 for ; Wed, 22 Jul 2020 14:14:04 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@apple.com header.s=20180706 header.b=J3gk/hlE; spf=pass (domain: apple.com, ip: 17.151.62.68, mailfrom: afish@apple.com) Received: from pps.filterd (nwk-aaemail-lapp03.apple.com [127.0.0.1]) by nwk-aaemail-lapp03.apple.com (8.16.0.42/8.16.0.42) with SMTP id 06MLBRLj030521; Wed, 22 Jul 2020 14:13:59 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=apple.com; h=from : message-id : content-type : mime-version : subject : date : in-reply-to : cc : to : references; s=20180706; bh=0e25noCBX7udCT35Ui8gwZ/RktrOy6zQxlPLrrfxpto=; b=J3gk/hlE8DQA7J2rtSx+PJt9iVgUMW7E3isN0m2y8N/sT8wR2dAMvKmLfm3vGGokaH9Z 7xI/Li2CvvrqCW2TCmNZmtgxSYNVez4ZJ1qC55xDkIMuO3wLL8a/FPp4rgSKh9m38Lyn Cuu9em+4T7SAfj8NsiRBPfJfnNnsOLM83PHmOi+0YVCDOE09S4z64Qy1KHQixBhTEOwA yiDSnsT/HDXrRbjFwv6NpVIhhW+LIGQAg9Bl5u3BLZjTBsG+wyTMKXF6masnXi6LmsBr Y28oR0mSkosKGg5TAGPmohXJoRsnB6w9jWWigcIdyG8r3YR+BHrO9uzwjabEBTeAOwnN cA== Received: from rn-mailsvcp-mta-lapp04.rno.apple.com (rn-mailsvcp-mta-lapp04.rno.apple.com [10.225.203.152]) by nwk-aaemail-lapp03.apple.com with ESMTP id 32cgspfxsm-5 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO); Wed, 22 Jul 2020 14:13:59 -0700 Received: from rn-mailsvcp-mmp-lapp03.rno.apple.com (rn-mailsvcp-mmp-lapp03.rno.apple.com [17.179.253.16]) by rn-mailsvcp-mta-lapp04.rno.apple.com (Oracle Communications Messaging Server 8.1.0.5.20200312 64bit (built Mar 12 2020)) with ESMTPS id <0QDW00DN02ZBR9C0@rn-mailsvcp-mta-lapp04.rno.apple.com>; Wed, 22 Jul 2020 14:13:59 -0700 (PDT) Received: from process_milters-daemon.rn-mailsvcp-mmp-lapp03.rno.apple.com by rn-mailsvcp-mmp-lapp03.rno.apple.com (Oracle Communications Messaging Server 8.1.0.5.20200312 64bit (built Mar 12 2020)) id <0QDW00X002BPKW00@rn-mailsvcp-mmp-lapp03.rno.apple.com>; Wed, 22 Jul 2020 14:13:59 -0700 (PDT) X-Va-A: X-Va-T-CD: e0acb9dc03d22e4581b62f3d752335f3 X-Va-E-CD: e15f0577c23e4745d279058b627e3e75 X-Va-R-CD: 80568e25e4cf3e056de2b659785160ff X-Va-CD: 0 X-Va-ID: b7026877-4ed9-49f9-900a-3989fb451a30 X-V-A: X-V-T-CD: e0acb9dc03d22e4581b62f3d752335f3 X-V-E-CD: e15f0577c23e4745d279058b627e3e75 X-V-R-CD: 80568e25e4cf3e056de2b659785160ff X-V-CD: 0 X-V-ID: e89abee0-e520-4c1e-b554-4031b2a1cb20 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235,18.0.687 definitions=2020-07-22_16:2020-07-22,2020-07-22 signatures=0 Received: from [17.235.24.189] (unknown [17.235.24.189]) by rn-mailsvcp-mmp-lapp03.rno.apple.com (Oracle Communications Messaging Server 8.1.0.5.20200312 64bit (built Mar 12 2020)) with ESMTPSA id <0QDW00R3Z2Z85V00@rn-mailsvcp-mmp-lapp03.rno.apple.com>; Wed, 22 Jul 2020 14:13:58 -0700 (PDT) From: "Andrew Fish" Message-id: <91DC7A55-E063-49BF-B434-6D4AED28BFB9@apple.com> MIME-version: 1.0 (Mac OS X Mail 13.4 \(3608.80.23.2.2\)) Subject: Re: [edk2-devel] [PATCH V2 1/2] BaseTools: Add gcc flag to warn on void* pointer arithmetic Date: Wed, 22 Jul 2020 14:13:56 -0700 In-reply-to: <20200722180534.GG1337@vanye> Cc: bob.c.feng@intel.com, PierreGondois , "Gao, Liming" , tomas@nuviainc.com To: edk2-devel-groups-io , leif@nuviainc.com References: <20200707083522.138944-1-pierre.gondois@arm.com> <20200707083522.138944-2-pierre.gondois@arm.com> <20200722180534.GG1337@vanye> X-Mailer: Apple Mail (2.3608.80.23.2.2) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235,18.0.687 definitions=2020-07-22_16:2020-07-22,2020-07-22 signatures=0 Content-type: multipart/alternative; boundary="Apple-Mail=_B9FAEF51-58AC-4F4F-AF4F-A26242AFD1EF" --Apple-Mail=_B9FAEF51-58AC-4F4F-AF4F-A26242AFD1EF Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Leif, I also noticed we would need this flag for clang/Xcode too.=20 ~/work/Compiler>clang -S void.c ~/work/Compiler>clang -S void.c -Wpointer-arith void.c:4:14: warning: arithmetic on a pointer to void is a GNU extension [-Wpointer-arith] return Arg + 1; ~~~ ^ 1 warning generated. ~/work/Compiler>cat void.c void * Test (void *Arg) { return Arg + 1; } Thanks, Andrew Fish > On Jul 22, 2020, at 11:05 AM, Leif Lindholm wrote: >=20 > Hi Bob, >=20 > This patch also breaks about half of the ARM/AARCH64 platforms in > edk2-platforms. I agree it should go in at a later stage, but for now, > can we please revert it? >=20 > Regards, >=20 > Leif >=20 > On Mon, Jul 20, 2020 at 04:10:27 +0000, Bob Feng wrote: >> Reviewed-by: Bob Feng >>=20 >>=20 >> -----Original Message----- >> From: PierreGondois =20 >> Sent: Tuesday, July 7, 2020 4:35 PM >> To: devel@edk2.groups.io >> Cc: Pierre Gondois ; Feng, Bob C ; Gao, Liming ; tomas.pilar@arm.com; nd@arm.c= om >> Subject: [PATCH V2 1/2] BaseTools: Add gcc flag to warn on void* pointe= r arithmetic >>=20 >> From: Pierre Gondois >>=20 >> By default, gcc allows void* pointer arithmetic. >> This is a GCC extension. >> However: >> - the C reference manual states that void* >> pointer "cannot be operands of addition >> or subtraction operators". Cf s5.3.1 >> "Generic Pointers"; >> - Visual studio compiler treat such operation as >> an error. >>=20 >> To prevent such pointer arithmetic, the "-Wpointer-arith" >> flag should be set for all GCC versions. >>=20 >> The "-Wpointer-arith" allows to: >> "Warn about anything that depends on the "size of" >> a function type or of void. GNU C assigns these >> types a size of 1, for convenience in calculations >> with void * pointers and pointers to functions." >>=20 >> This flag is available since GCC2.95.3 which came out in 2001. >>=20 >> Signed-off-by: Pierre Gondois >> --- >>=20 >> The changes can be seen at: https://github.com/PierreARM/edk2/commits/8= 31_Add_gcc_flag_warning_v2 >>=20 >> Notes: >> v1: >> - Add "-Wpointer-arith" gcc flag. [Pierre] >> v2: >> - Only add the flag for ARM and AARCH64. [Tomas] >>=20 >> BaseTools/Conf/tools_def.template | 6 +++--- >> 1 file changed, 3 insertions(+), 3 deletions(-) >>=20 >> diff --git a/BaseTools/Conf/tools_def.template b/BaseTools/Conf/tools_d= ef.template >> index 8aeb8a2a6417e41c5660cda5066f52adc8cc3089..397b011ba38f97f81f314f8= 641ac8bb95d5a2197 100755 >> --- a/BaseTools/Conf/tools_def.template >> +++ b/BaseTools/Conf/tools_def.template >> @@ -1,7 +1,7 @@ >> # >> # Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved. # Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<= BR> -# Portions copyright (c) 2011 - 2019, ARM Ltd. All rights reserved. >> +# Portions copyright (c) 2011 - 2020, ARM Ltd. All rights=20 >> +reserved.
>> # Copyright (c) 2015, Hewlett-Packard Development Company, L.P.
#= (C) Copyright 2020, Hewlett Packard Enterprise Development LP
# Cop= yright (c) Microsoft Corporation >> @@ -1921,9 +1921,9 @@ NOOPT_*_*_OBJCOPY_ADDDEBUGFLAG =3D --add-gnu-= debuglink=3D$(DEBUG_DIR)/$(MODULE_N >> DEFINE GCC_ALL_CC_FLAGS =3D -g -Os -fshort-wchar -fno-builti= n -fno-strict-aliasing -Wall -Werror -Wno-array-bounds -include AutoGen.h -= fno-common >> DEFINE GCC_IA32_CC_FLAGS =3D DEF(GCC_ALL_CC_FLAGS) -m32 -mali= gn-double -freorder-blocks -freorder-blocks-and-partition -O2 -mno-stack-ar= g-probe >> DEFINE GCC_X64_CC_FLAGS =3D DEF(GCC_ALL_CC_FLAGS) -mno-red-z= one -Wno-address -mno-stack-arg-probe >> -DEFINE GCC_ARM_CC_FLAGS =3D DEF(GCC_ALL_CC_FLAGS) -mlittle-= endian -mabi=3Daapcs -fno-short-enums -funsigned-char -ffunction-sections -= fdata-sections -fomit-frame-pointer -Wno-address -mthumb -mfloat-abi=3Dsoft= -fno-pic -fno-pie >> +DEFINE GCC_ARM_CC_FLAGS =3D DEF(GCC_ALL_CC_FLAGS) -Wpointer= -arith -mlittle-endian -mabi=3Daapcs -fno-short-enums -funsigned-char -ffun= ction-sections -fdata-sections -fomit-frame-pointer -Wno-address -mthumb -m= float-abi=3Dsoft -fno-pic -fno-pie >> DEFINE GCC_ARM_CC_XIPFLAGS =3D -mno-unaligned-access >> -DEFINE GCC_AARCH64_CC_FLAGS =3D DEF(GCC_ALL_CC_FLAGS) -mlittle-= endian -fno-short-enums -fverbose-asm -funsigned-char -ffunction-sections = -fdata-sections -Wno-address -fno-asynchronous-unwind-tables -fno-unwind-ta= bles -fno-pic -fno-pie -ffixed-x18 >> +DEFINE GCC_AARCH64_CC_FLAGS =3D DEF(GCC_ALL_CC_FLAGS) -Wpointer= -arith -mlittle-endian -fno-short-enums -fverbose-asm -funsigned-char -ffun= ction-sections -fdata-sections -Wno-address -fno-asynchronous-unwind-tables= -fno-unwind-tables -fno-pic -fno-pie -ffixed-x18 >> DEFINE GCC_AARCH64_CC_XIPFLAGS =3D -mstrict-align -mgeneral-regs-on= ly >> DEFINE GCC_DLINK_FLAGS_COMMON =3D -nostdlib --pie >> DEFINE GCC_DLINK2_FLAGS_COMMON =3D -Wl,--script=3D$(EDK_TOOLS_PATH)= /Scripts/GccBase.lds >> -- >> 'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)' >>=20 >>=20 >>=20 >>=20 >=20 >=20 --Apple-Mail=_B9FAEF51-58AC-4F4F-AF4F-A26242AFD1EF Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=us-ascii Leif,
<= br class=3D"">
I also noticed we would need this flag = for clang/Xcode too. 

~/work/Compiler= >clang -S void.c
~/work/Compiler>clang = -S void.c -Wpointer-arith
void.c:4:14: warning:= arithmetic on a pointer to void is a GNU extension
  =     [-Wpointer-arith]
  return Arg + 1;
     &nb= sp;   ~~~ ^
1 = warning generated.
~/work/Compiler>cat void.c
void *
Test (void *Arg)
{
  return Arg + 1;
}

Thanks,

Andrew Fish
<= div>
On = Jul 22, 2020, at 11:05 AM, Leif Lindholm <leif@nuviainc.com> wrote:

Hi Bob,

This pa= tch also breaks about half of the ARM/AARCH64 platforms in
edk2-platforms. I agree it should go = in at a later stage, but for now,
can we please revert it?

Regards,

Leif

On Mon, Jul 20, 2020 at 04:10:27 +0000, Bob Fen= g wrote:
R= eviewed-by: Bob Feng<= bob.c.feng@intel.com>


--= ---Original Message-----
From: PierreGondois <pierre.gondois@arm.com> 
Sent: Tuesday= , July 7, 2020 4:35 PM
To: devel@edk2.groups.io
Cc: Pierre Gondois = <Pierre.Gondois@arm= .com>; Feng, Bob C <bob.c.feng@intel.com>; Gao, Liming <liming.gao@intel.com>; tomas.pilar@arm.com; nd@arm.com
Subject: [PATCH V2 1/= 2] BaseTools: Add gcc flag to warn on void* pointer arithmetic

From: Pierre Gondois <pierre.gondois@arm.com>

By default, gcc allows void* pointer arithmetic.
This = is a GCC extension.
However:
- the C reference = manual states that void*
  pointer "cannot be opera= nds of addition
  or subtraction operators". Cf s5.= 3.1
  "Generic Pointers";
- Visual st= udio compiler treat such operation as
  an error.
To prevent such pointer arithmetic, the "-Wpoin= ter-arith"
flag should be set for all GCC versions.

The "-Wpointer-arith"  allows to:
=  "Warn about anything that depends on the "size of"
&nbs= p;a function type or of void. GNU C assigns these
 types= a size of 1, for convenience in calculations
 with void= * pointers and pointers to functions."

This f= lag is available since GCC2.95.3 which came out in 2001.

Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
---

The changes can be seen at: htt= ps://github.com/PierreARM/edk2/commits/831_Add_gcc_flag_warning_v2

Notes:
   v1:
    - Add "-Wpointer-arith" gcc flag. [Pierre]   v2:
    - = Only add the flag for ARM and AARCH64. [Tomas]

BaseTools/Conf/tools_def.template | 6 +++---
1 file changed,= 3 insertions(+), 3 deletions(-)

diff --git a/= BaseTools/Conf/tools_def.template b/BaseTools/Conf/tools_def.template
index 8aeb8a2a6417e41c5660cda5066f52adc8cc3089..397b011ba38f97f81f= 314f8641ac8bb95d5a2197 100755
--- a/BaseTools/Conf/tools_def.= template
+++ b/BaseTools/Conf/tools_def.template
@@ -1,7 +1,7 @@
#
#  Copyright (c) 2006 = - 2018, Intel Corporation. All rights reserved.<BR>  #  Por= tions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR> = -#  Portions copyright (c) 2011 - 2019, ARM Ltd. All rights reserved.&= lt;BR>
+#  Portions copyright (c) 2011 - 2020, ARM Lt= d. All rights 
+reserved.<BR>
#  Copyright (c) 2015, Hewle= tt-Packard Development Company, L.P.<BR>  #  (C) Copyright = 2020, Hewlett Packard Enterprise Development LP<BR>  #  Cop= yright (c) Microsoft Corporation
@@ -1921,9 +1921,9 @@ NOOPT_= *_*_OBJCOPY_ADDDEBUGFLAG     =3D --add-gnu-debuglink=3D= $(DEBUG_DIR)/$(MODULE_N
DEFINE GCC_ALL_CC_FLAGS   &= nbsp;        =3D -g -Os -fshort-wch= ar -fno-builtin -fno-strict-aliasing -Wall -Werror -Wno-array-bounds -inclu= de AutoGen.h -fno-common
DEFINE GCC_IA32_CC_FLAGS   = ;        =3D DEF(GCC_ALL_CC_FLAGS) = -m32 -malign-double -freorder-blocks -freorder-blocks-and-partition -O2 -mn= o-stack-arg-probe
DEFINE GCC_X64_CC_FLAGS    &= nbsp;       =3D DEF(GCC_ALL_CC_FLAGS) -m= no-red-zone -Wno-address -mno-stack-arg-probe
-DEFINE GCC_ARM= _CC_FLAGS            = ;=3D DEF(GCC_ALL_CC_FLAGS) -mlittle-endian -mabi=3Daapcs -fno-short-enums -= funsigned-char -ffunction-sections -fdata-sections -fomit-frame-pointer -Wn= o-address -mthumb -mfloat-abi=3Dsoft -fno-pic -fno-pie
+DEFIN= E GCC_ARM_CC_FLAGS          &n= bsp; =3D DEF(GCC_ALL_CC_FLAGS) -Wpointer-arith -mlittle-endian -mabi= =3Daapcs -fno-short-enums -funsigned-char -ffunction-sections -fdata-secti= ons -fomit-frame-pointer -Wno-address -mthumb -mfloat-abi=3Dsoft -fno-pic -= fno-pie
DEFINE GCC_ARM_CC_XIPFLAGS     &n= bsp;   =3D -mno-unaligned-access
-DEFINE GCC_A= ARCH64_CC_FLAGS        =3D DEF(GCC_ALL_C= C_FLAGS) -mlittle-endian -fno-short-enums -fverbose-asm -funsigned-char &nb= sp;-ffunction-sections -fdata-sections -Wno-address -fno-asynchronous-unwin= d-tables -fno-unwind-tables -fno-pic -fno-pie -ffixed-x18
+DE= FINE GCC_AARCH64_CC_FLAGS        =3D DEF= (GCC_ALL_CC_FLAGS) -Wpointer-arith -mlittle-endian -fno-short-enums -fverbo= se-asm -funsigned-char -ffunction-sections -fdata-sections -Wno-address -fn= o-asynchronous-unwind-tables -fno-unwind-tables -fno-pic -fno-pie -ffixed-x= 18
DEFINE GCC_AARCH64_CC_XIPFLAGS     =3D= -mstrict-align -mgeneral-regs-only
DEFINE GCC_DLINK_FLAGS_CO= MMON      =3D -nostdlib --pie
DEFINE= GCC_DLINK2_FLAGS_COMMON     =3D -Wl,--script=3D$(EDK_T= OOLS_PATH)/Scripts/GccBase.lds
--
'Guid(CE16566= 9-3EF3-493F-B85D-6190EE5B9759)'






= --Apple-Mail=_B9FAEF51-58AC-4F4F-AF4F-A26242AFD1EF--