This is required for silencing warnings on modern GCC versions.
GCC tracks the bounds of objects; even though the C code casts
such references to pointers to other objects, GCC keeps track of
the size of the original object.
One such case is found in delayimp.c, where we reference
"extern IMAGE_DOS_HEADER __ImageBase". A pointer to the __ImageBase
symbol is used for locating the PIMAGE_NT_HEADERS struct (in
PinhFromImageBase), which is located after the IMAGE_DOS_HEADER.
GCC flags any accesses to this struct as being out of bounds
for the original IMAGE_DOS_HEADER object.
../misc/delayimp.c: In function ‘__HrLoadAllImportsForDll’:
../misc/delayimp.c:258:10: warning: array subscript ‘struct
_IMAGE_NT_HEADERS64[0]’ is partly outside array bounds of ‘IMAGE_DOS_HEADER[1]’
[-Warray-bounds=]
258 |
if(pinh->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT].Size)
{
| ^~
../misc/delayimp.c:50:25: note: object ‘__ImageBase’ of size 64
50 | extern IMAGE_DOS_HEADER __ImageBase;
| ^~~~~~~~~~~
../misc/delayimp.c:260:45: warning: array subscript ‘struct
_IMAGE_NT_HEADERS64[0]’ is partly outside array bounds of ‘IMAGE_DOS_HEADER[1]’
[-Warray-bounds=]
260 | pidd = (PCImgDelayDescr)
PtrFromRVA(pinh->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT].VirtualAddress);
| ^~
../misc/delayimp.c:52:53: note: in definition of macro ‘PtrFromRVA’
52 | #define PtrFromRVA(RVA) (((PBYTE)&__ImageBase) + (RVA))
| ^~~
../misc/delayimp.c:50:25: note: object ‘__ImageBase’ of size 64
50 | extern IMAGE_DOS_HEADER __ImageBase;
| ^~~~~~~~~~~
Unless there's a good way to silence this diagnostic e.g. for
specific casts, we'll have to disable the warning entirely.
Signed-off-by: Martin Storsjö <[email protected]>
---
mingw-w64-crt/configure.ac | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/mingw-w64-crt/configure.ac b/mingw-w64-crt/configure.ac
index 9d690c751..bb59f10dd 100644
--- a/mingw-w64-crt/configure.ac
+++ b/mingw-w64-crt/configure.ac
@@ -449,6 +449,15 @@ if test "$supports_wpragma_pack" = "yes"; then
ADD_C_CXX_WARNING_FLAGS="$ADD_C_CXX_WARNING_FLAGS -Wno-pragma-pack"
fi
CFLAGS="$saved_CFLAGS"
+AC_MSG_CHECKING([whether the compiler supports -Warray-bounds])
+CFLAGS="$CFLAGS -Warray-bounds"
+AC_COMPILE_IFELSE([AC_LANG_SOURCE([[]])],
+ [supports_warray_bounds=yes],[supports_warray_bounds=no])
+AC_MSG_RESULT([$supports_warray_bounds])
+if test "$supports_warray_bounds" = "yes"; then
+ ADD_C_CXX_WARNING_FLAGS="$ADD_C_CXX_WARNING_FLAGS -Wno-array-bounds"
+fi
+CFLAGS="$saved_CFLAGS"
AC_SUBST(ADD_C_ONLY_WARNING_FLAGS)
AC_SUBST(ADD_C_CXX_WARNING_FLAGS)
--
2.43.0
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public