mirror_edk2/BaseTools/Source/C
Laszlo Ersek 9222154ae7 BaseTools/header.makefile: add "-Wno-restrict"
gcc-8 (which is part of Fedora 28) enables the new warning
"-Wrestrict" in "-Wall". This warning is documented in detail
at <https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html>; the
introduction says

> Warn when an object referenced by a restrict-qualified parameter (or, in
> C++, a __restrict-qualified parameter) is aliased by another argument,
> or when copies between such objects overlap.

It breaks the BaseTools build (in the Brotli compression library) with:

> In function 'ProcessCommandsInternal',
>     inlined from 'ProcessCommands' at dec/decode.c:1828:10:
> dec/decode.c:1781:9: error: 'memcpy' accessing between 17 and 2147483631
> bytes at offsets 16 and 16 overlaps between 17 and 2147483631 bytes at
> offset 16 [-Werror=restrict]
>          memcpy(copy_dst + 16, copy_src + 16, (size_t)(i - 16));
>          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> In function 'ProcessCommandsInternal',
>     inlined from 'SafeProcessCommands' at dec/decode.c:1833:10:
> dec/decode.c:1781:9: error: 'memcpy' accessing between 17 and 2147483631
> bytes at offsets 16 and 16 overlaps between 17 and 2147483631 bytes at
> offset 16 [-Werror=restrict]
>          memcpy(copy_dst + 16, copy_src + 16, (size_t)(i - 16));
>          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Paolo Bonzini <pbonzini@redhat.com> analyzed the Brotli source in detail,
and concluded that the warning is a false positive:

> This seems safe to me, because it's preceded by:
>
>     uint8_t* copy_dst = &s->ringbuffer[pos];
>     uint8_t* copy_src = &s->ringbuffer[src_start];
>     int dst_end = pos + i;
>     int src_end = src_start + i;
>     if (src_end > pos && dst_end > src_start) {
>       /* Regions intersect. */
>       goto CommandPostWrapCopy;
>     }
>
> If [src_start, src_start + i) and [pos, pos + i) don't intersect, then
> neither do [src_start + 16, src_start + i) and [pos + 16, pos + i).
>
> The if seems okay:
>
>        (src_start + i > pos && pos + i > src_start)
>
> which can be rewritten to:
>
>        (pos < src_start + i && src_start < pos + i)
>
> Then the numbers are in one of these two orders:
>
>      pos <= src_start < pos + i <= src_start + i
>      src_start <= pos < src_start + i <= pos + i
>
> These two would be allowed by the "if", but they can only happen if pos
> == src_start so they degenerate to the same two orders above:
>
>      pos <= src_start < src_start + i <= pos + i
>      src_start <= pos < pos + i <= src_start + i
>
> So it is a false positive in GCC.

Disable the warning for now.

Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Cole Robinson <crobinso@redhat.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Reported-by: Cole Robinson <crobinso@redhat.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
2018-03-05 22:38:30 +01:00
..
BootSectImage BaseTools GNUmakefile: Remove HOST_ARCH in every tool Makefile 2018-02-06 13:44:42 +08:00
BrotliCompress BaseTools GNUmakefile: Remove HOST_ARCH in every tool Makefile 2018-02-06 13:44:42 +08:00
Common BaseTools GNUmakefile: Remove HOST_ARCH in every tool Makefile 2018-02-06 13:44:42 +08:00
DevicePath BaseTools: Fix byte orders when handling 8-byte array 2018-03-03 15:41:16 +08:00
EfiLdrImage BaseTools GNUmakefile: Remove HOST_ARCH in every tool Makefile 2018-02-06 13:44:42 +08:00
EfiRom BaseTools GNUmakefile: Remove HOST_ARCH in every tool Makefile 2018-02-06 13:44:42 +08:00
GenBootSector BaseTools/GenBootSector: Add/refine boundary checks for strcpy/strcat 2017-12-25 09:54:25 +08:00
GenCrc32 BaseTools GNUmakefile: Remove HOST_ARCH in every tool Makefile 2018-02-06 13:44:42 +08:00
GenFfs BaseTools GNUmakefile: Remove HOST_ARCH in every tool Makefile 2018-02-06 13:44:42 +08:00
GenFv BaseTools: Resolve BaseTools C tool build failure 2018-02-27 18:34:03 +08:00
GenFw BaseTools: Update GenFw to correct DebugEntry Offset when convert XIP image 2018-02-27 18:43:30 +08:00
GenPage BaseTools GNUmakefile: Remove HOST_ARCH in every tool Makefile 2018-02-06 13:44:42 +08:00
GenSec BaseTools GNUmakefile: Remove HOST_ARCH in every tool Makefile 2018-02-06 13:44:42 +08:00
GenVtf BaseTools GNUmakefile: Remove HOST_ARCH in every tool Makefile 2018-02-06 13:44:42 +08:00
GnuGenBootSector BaseTools GNUmakefile: Remove HOST_ARCH in every tool Makefile 2018-02-06 13:44:42 +08:00
Include BaseTools: update DNS_DEVICE_PATH/URI_DEVICE_PATH definition 2018-03-05 15:22:59 +08:00
LzmaCompress BaseTools GNUmakefile: Remove HOST_ARCH in every tool Makefile 2018-02-06 13:44:42 +08:00
Makefiles BaseTools/header.makefile: add "-Wno-restrict" 2018-03-05 22:38:30 +01:00
PyEfiCompressor License header updated to match correct format. 2014-08-28 13:53:34 +00:00
PyUtility License header updated to match correct format. 2014-08-28 13:53:34 +00:00
Split BaseTools GNUmakefile: Remove HOST_ARCH in every tool Makefile 2018-02-06 13:44:42 +08:00
TianoCompress BaseTools GNUmakefile: Remove HOST_ARCH in every tool Makefile 2018-02-06 13:44:42 +08:00
VfrCompile BaseTools GNUmakefile: Remove HOST_ARCH in every tool Makefile 2018-02-06 13:44:42 +08:00
VolInfo BaseTools GNUmakefile: Remove HOST_ARCH in every tool Makefile 2018-02-06 13:44:42 +08:00
GNUmakefile BaseTools: Add DevicePath support for PCD values 2017-12-31 13:10:49 +08:00
Makefile BaseTools: Add DevicePath support for PCD values 2017-12-31 13:10:49 +08:00