[edk2-devel] [Patch] BaseTools: Add GCC flags to Basetool build.

Bob Feng posted 1 patch 4 years, 12 months ago
Failed in applying to current master (apply log)
BaseTools/Source/C/Makefiles/header.makefile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[edk2-devel] [Patch] BaseTools: Add GCC flags to Basetool build.
Posted by Bob Feng 4 years, 12 months ago
BZ:https://bugzilla.tianocore.org/show_bug.cgi?id=1764

Some compiler flags restrict the compiler from making
arbitrary decisions while handling undefined C/C++ behaviors.
Therefore they can be used to fix some issues caused by undefined behavior.

For example, for GCC, the following flags are available:
-fno-strict-overflow tells the compiler NOT to assume
that signed overflow does not occur.
-fno-delete-null-pointer-checks tells
the compiler NOT to assume that null pointer deference does not exist.
-fwrapv tells the compiler that signed overflow always wraps.

This patch is going to add these 3 build options to
BaseTool GCC build option.

Signed-off-by: Bob Feng <bob.c.feng@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
---
 BaseTools/Source/C/Makefiles/header.makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/BaseTools/Source/C/Makefiles/header.makefile b/BaseTools/Source/C/Makefiles/header.makefile
index 90fb3453ad..f1aed62769 100644
--- a/BaseTools/Source/C/Makefiles/header.makefile
+++ b/BaseTools/Source/C/Makefiles/header.makefile
@@ -68,11 +68,11 @@ BUILD_OPTFLAGS = -O2 $(EXTRA_OPTFLAGS)
 
 ifeq ($(DARWIN),Darwin)
 # assume clang or clang compatible flags on OS X
 BUILD_CFLAGS = -MD -fshort-wchar -fno-strict-aliasing -Wall -Werror -Wno-deprecated-declarations -Wno-self-assign -Wno-unused-result -nostdlib -g
 else
-BUILD_CFLAGS = -MD -fshort-wchar -fno-strict-aliasing -Wall -Werror -Wno-deprecated-declarations -Wno-stringop-truncation -Wno-restrict -Wno-unused-result -nostdlib -g
+BUILD_CFLAGS = -MD -fshort-wchar -fno-strict-aliasing -Wall -Werror -Wno-deprecated-declarations -Wno-stringop-truncation -Wno-restrict -Wno-unused-result -nostdlib -g -fwrapv -fno-delete-null-pointer-checks -fno-strict-overflow
 endif
 BUILD_LFLAGS =
 BUILD_CXXFLAGS = -Wno-unused-result
 
 ifeq ($(HOST_ARCH), IA32)
-- 
2.20.1.windows.1


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

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

Re: [edk2-devel] [Patch] BaseTools: Add GCC flags to Basetool build.
Posted by Laszlo Ersek 4 years, 12 months ago
Hi Bob,

On 04/29/19 10:01, Bob Feng wrote:
> BZ:https://bugzilla.tianocore.org/show_bug.cgi?id=1764
> 
> Some compiler flags restrict the compiler from making
> arbitrary decisions while handling undefined C/C++ behaviors.
> Therefore they can be used to fix some issues caused by undefined behavior.
> 
> For example, for GCC, the following flags are available:
> -fno-strict-overflow tells the compiler NOT to assume
> that signed overflow does not occur.
> -fno-delete-null-pointer-checks tells
> the compiler NOT to assume that null pointer deference does not exist.
> -fwrapv tells the compiler that signed overflow always wraps.
> 
> This patch is going to add these 3 build options to
> BaseTool GCC build option.
> 
> Signed-off-by: Bob Feng <bob.c.feng@intel.com>
> Cc: Liming Gao <liming.gao@intel.com>
> ---
>  BaseTools/Source/C/Makefiles/header.makefile | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/BaseTools/Source/C/Makefiles/header.makefile b/BaseTools/Source/C/Makefiles/header.makefile
> index 90fb3453ad..f1aed62769 100644
> --- a/BaseTools/Source/C/Makefiles/header.makefile
> +++ b/BaseTools/Source/C/Makefiles/header.makefile
> @@ -68,11 +68,11 @@ BUILD_OPTFLAGS = -O2 $(EXTRA_OPTFLAGS)
>  
>  ifeq ($(DARWIN),Darwin)
>  # assume clang or clang compatible flags on OS X
>  BUILD_CFLAGS = -MD -fshort-wchar -fno-strict-aliasing -Wall -Werror -Wno-deprecated-declarations -Wno-self-assign -Wno-unused-result -nostdlib -g
>  else
> -BUILD_CFLAGS = -MD -fshort-wchar -fno-strict-aliasing -Wall -Werror -Wno-deprecated-declarations -Wno-stringop-truncation -Wno-restrict -Wno-unused-result -nostdlib -g
> +BUILD_CFLAGS = -MD -fshort-wchar -fno-strict-aliasing -Wall -Werror -Wno-deprecated-declarations -Wno-stringop-truncation -Wno-restrict -Wno-unused-result -nostdlib -g -fwrapv -fno-delete-null-pointer-checks -fno-strict-overflow

(1) This line is hard to review. Please add a patch first that
implements no functional changes, just splits this line into multiple
<=80char lines, using the backslash.

(2) When you add "-W" and "-f" options, please try to preserve the
grouping. We already have two "-f" options, so the new ones should be
adjacent to those.

(3) My gcc-4.8 manual states, under "-fstrict-overflow":

           See also the -fwrapv option.  Using -fwrapv means that
           integer signed overflow is fully defined: it wraps.  When
           -fwrapv is used, there is no difference between
           -fstrict-overflow and -fno-strict-overflow for integers.
           With -fwrapv certain types of overflow are permitted.  For
           example, if the compiler gets an overflow when doing
           arithmetic on constants, the overflowed value can still be
           used with -fwrapv, but not otherwise.

The point is that, with gcc-4.8, "-fno-strict-overflow" is redundant,
once we specify "-fwrapv" -- assuming we don't use floating point in the
C-language utilities in BaseTools.

Additionally, checking the latest published GCC docs on the web:

  https://gcc.gnu.org/onlinedocs/gcc-8.3.0/gcc/Option-Summary.html

it looks like the "-f[no-]strict-overflow" option has been removed
altogether.

Therefore I believe we should drop "-fno-strict-overflow".

Thanks,
Laszlo

>  endif
>  BUILD_LFLAGS =
>  BUILD_CXXFLAGS = -Wno-unused-result
>  
>  ifeq ($(HOST_ARCH), IA32)
> 


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

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

Re: [edk2-devel] [Patch] BaseTools: Add GCC flags to Basetool build.
Posted by Bob Feng 4 years, 12 months ago
Laszlo, thanks for your comments. I sent new patches for review.

Thanks,
Bob

-----Original Message-----
From: Laszlo Ersek [mailto:lersek@redhat.com] 
Sent: Tuesday, April 30, 2019 2:44 AM
To: devel@edk2.groups.io; Feng, Bob C <bob.c.feng@intel.com>
Cc: Gao, Liming <liming.gao@intel.com>
Subject: Re: [edk2-devel] [Patch] BaseTools: Add GCC flags to Basetool build.

Hi Bob,

On 04/29/19 10:01, Bob Feng wrote:
> BZ:https://bugzilla.tianocore.org/show_bug.cgi?id=1764
> 
> Some compiler flags restrict the compiler from making arbitrary 
> decisions while handling undefined C/C++ behaviors.
> Therefore they can be used to fix some issues caused by undefined behavior.
> 
> For example, for GCC, the following flags are available:
> -fno-strict-overflow tells the compiler NOT to assume that signed 
> overflow does not occur.
> -fno-delete-null-pointer-checks tells
> the compiler NOT to assume that null pointer deference does not exist.
> -fwrapv tells the compiler that signed overflow always wraps.
> 
> This patch is going to add these 3 build options to BaseTool GCC build 
> option.
> 
> Signed-off-by: Bob Feng <bob.c.feng@intel.com>
> Cc: Liming Gao <liming.gao@intel.com>
> ---
>  BaseTools/Source/C/Makefiles/header.makefile | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/BaseTools/Source/C/Makefiles/header.makefile 
> b/BaseTools/Source/C/Makefiles/header.makefile
> index 90fb3453ad..f1aed62769 100644
> --- a/BaseTools/Source/C/Makefiles/header.makefile
> +++ b/BaseTools/Source/C/Makefiles/header.makefile
> @@ -68,11 +68,11 @@ BUILD_OPTFLAGS = -O2 $(EXTRA_OPTFLAGS)
>  
>  ifeq ($(DARWIN),Darwin)
>  # assume clang or clang compatible flags on OS X  BUILD_CFLAGS = -MD 
> -fshort-wchar -fno-strict-aliasing -Wall -Werror 
> -Wno-deprecated-declarations -Wno-self-assign -Wno-unused-result 
> -nostdlib -g  else -BUILD_CFLAGS = -MD -fshort-wchar 
> -fno-strict-aliasing -Wall -Werror -Wno-deprecated-declarations 
> -Wno-stringop-truncation -Wno-restrict -Wno-unused-result -nostdlib -g
> +BUILD_CFLAGS = -MD -fshort-wchar -fno-strict-aliasing -Wall -Werror 
> +-Wno-deprecated-declarations -Wno-stringop-truncation -Wno-restrict 
> +-Wno-unused-result -nostdlib -g -fwrapv 
> +-fno-delete-null-pointer-checks -fno-strict-overflow

(1) This line is hard to review. Please add a patch first that implements no functional changes, just splits this line into multiple <=80char lines, using the backslash.

(2) When you add "-W" and "-f" options, please try to preserve the grouping. We already have two "-f" options, so the new ones should be adjacent to those.

(3) My gcc-4.8 manual states, under "-fstrict-overflow":

           See also the -fwrapv option.  Using -fwrapv means that
           integer signed overflow is fully defined: it wraps.  When
           -fwrapv is used, there is no difference between
           -fstrict-overflow and -fno-strict-overflow for integers.
           With -fwrapv certain types of overflow are permitted.  For
           example, if the compiler gets an overflow when doing
           arithmetic on constants, the overflowed value can still be
           used with -fwrapv, but not otherwise.

The point is that, with gcc-4.8, "-fno-strict-overflow" is redundant, once we specify "-fwrapv" -- assuming we don't use floating point in the C-language utilities in BaseTools.

Additionally, checking the latest published GCC docs on the web:

  https://gcc.gnu.org/onlinedocs/gcc-8.3.0/gcc/Option-Summary.html

it looks like the "-f[no-]strict-overflow" option has been removed altogether.

Therefore I believe we should drop "-fno-strict-overflow".

Thanks,
Laszlo

>  endif
>  BUILD_LFLAGS =
>  BUILD_CXXFLAGS = -Wno-unused-result
>  
>  ifeq ($(HOST_ARCH), IA32)
> 


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

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