Hello community,

here is the log from the commit of package trustedgrub2 for openSUSE:Factory 
checked in at 2020-07-03 00:11:33
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/trustedgrub2 (Old)
 and      /work/SRC/openSUSE:Factory/.trustedgrub2.new.3060 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Package is "trustedgrub2"

Fri Jul  3 00:11:33 2020 rev:9 rq:818267 version:1.4.0

Changes:
--------
--- /work/SRC/openSUSE:Factory/trustedgrub2/trustedgrub2.changes        
2019-09-07 11:53:53.886270157 +0200
+++ /work/SRC/openSUSE:Factory/.trustedgrub2.new.3060/trustedgrub2.changes      
2020-07-03 00:15:11.528618746 +0200
@@ -1,0 +2,8 @@
+Mon Jun 29 10:25:39 UTC 2020 - Michael Chang <mch...@suse.com>
+
+- Fix GCC 10 build failure
+  * 0001-mdraid1x_linux-Fix-gcc10-error-Werror-array-bounds.patch
+  * 0002-zfs-Fix-gcc10-error-Werror-zero-length-bounds.patch
+  * 0003-linux-Fix-gcc10-error-Werror-zero-length-bounds.patch
+
+-------------------------------------------------------------------

New:
----
  0001-mdraid1x_linux-Fix-gcc10-error-Werror-array-bounds.patch
  0002-zfs-Fix-gcc10-error-Werror-zero-length-bounds.patch
  0003-linux-Fix-gcc10-error-Werror-zero-length-bounds.patch

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Other differences:
------------------
++++++ trustedgrub2.spec ++++++
--- /var/tmp/diff_new_pack.dgmdF9/_old  2020-07-03 00:15:13.856626453 +0200
+++ /var/tmp/diff_new_pack.dgmdF9/_new  2020-07-03 00:15:13.860626467 +0200
@@ -1,7 +1,7 @@
 #
 # spec file for package trustedgrub2
 #
-# Copyright (c) 2019 SUSE LINUX GmbH, Nuernberg, Germany.
+# Copyright (c) 2020 SUSE LLC
 #
 # All modifications and additions to the file contributed by third parties
 # remain the property of their copyright owners, unless otherwise agreed
@@ -22,7 +22,7 @@
 Summary:        Bootloader with TCG (TPM) support  
 License:        GPL-3.0-or-later
 Group:          System/Boot
-Url:            https://github.com/Sirrix-AG/TrustedGRUB2
+URL:            https://github.com/Sirrix-AG/TrustedGRUB2
 Source0:        %{name}-%{version}.tar.gz
 Source1:        trustedgrub2.rpmlintrc
 Source2:        HOWTO.luks-keyfile
@@ -55,6 +55,10 @@
 Patch20:        0006-usbtest-Disable-gcc9-Waddress-of-packed-member.patch
 Patch21:        0007-chainloader-Fix-gcc9-error-Waddress-of-packed-member.patch
 Patch22:        0008-efi-Fix-gcc9-error-Waddress-of-packed-member.patch
+# fix build against GCC-10
+Patch23:        0001-mdraid1x_linux-Fix-gcc10-error-Werror-array-bounds.patch
+Patch24:        0002-zfs-Fix-gcc10-error-Werror-zero-length-bounds.patch
+Patch25:        0003-linux-Fix-gcc10-error-Werror-zero-length-bounds.patch
 # Btrfs snapshot booting related patches
 Patch101:       grub2-btrfs-01-add-ability-to-boot-from-subvolumes.patch
 Patch102:       grub2-btrfs-02-export-subvolume-envvars.patch

++++++ 0001-mdraid1x_linux-Fix-gcc10-error-Werror-array-bounds.patch ++++++
>From bdf170d1018a500a7fea8d43677c5b4fc8812c74 Mon Sep 17 00:00:00 2001
From: Michael Chang <mch...@suse.com>
Date: Thu, 26 Mar 2020 14:35:34 +0800
Subject: [PATCH 1/2] mdraid1x_linux: Fix gcc10 error -Werror=array-bounds

We bumped into the build error while testing gcc-10 pre-release.

../../grub-core/disk/mdraid1x_linux.c: In function 'grub_mdraid_detect':
../../grub-core/disk/mdraid1x_linux.c:181:15: error: array subscript <unknown> 
is outside array bounds of 'grub_uint16_t[0]' {aka 'short unsigned int[0]'} 
[-Werror=array-bounds]
  181 |      (char *) &sb.dev_roles[grub_le_to_cpu32 (sb.dev_number)]
      |               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../grub-core/disk/mdraid1x_linux.c:98:17: note: while referencing 'dev_roles'
   98 |   grub_uint16_t dev_roles[0]; /* Role in array, or 0xffff for a spare, 
or 0xfffe for faulty.  */
      |                 ^~~~~~~~~
../../grub-core/disk/mdraid1x_linux.c:127:33: note: defined here 'sb'
  127 |       struct grub_raid_super_1x sb;
      |                                 ^~
cc1: all warnings being treated as errors

Apparently gcc issues the warning when trying to access sb.dev_roles
array's member, since it is a zero length array as the last element of
struct grub_raid_super_1x that is allocated sparsely without extra
chunks for the trailing bits, so the warning looks legitimate in this
regard.

As the whole thing here is doing offset computation, it is undue to use
syntax that would imply array member access then take address from it
later. Instead we could accomplish the same thing through basic array
pointer arithmetic to pacify the warning.

Signed-off-by: Michael Chang <mch...@suse.com>
Reviewed-by: Daniel Kiper <daniel.ki...@oracle.com>
---
 grub-core/disk/mdraid1x_linux.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/grub-core/disk/mdraid1x_linux.c b/grub-core/disk/mdraid1x_linux.c
index 7cc80d3df..c980feba4 100644
--- a/grub-core/disk/mdraid1x_linux.c
+++ b/grub-core/disk/mdraid1x_linux.c
@@ -178,7 +178,7 @@ grub_mdraid_detect (grub_disk_t disk,
        return NULL;
 
       if (grub_disk_read (disk, sector, 
-                         (char *) &sb.dev_roles[grub_le_to_cpu32 
(sb.dev_number)]
+                         (char *) (sb.dev_roles + grub_le_to_cpu32 
(sb.dev_number))
                          - (char *) &sb,
                          sizeof (role), &role))
        return NULL;
-- 
2.26.2

++++++ 0002-zfs-Fix-gcc10-error-Werror-zero-length-bounds.patch ++++++
>From 68006d173291c6e972c4882d4fa40dc91a9c1d45 Mon Sep 17 00:00:00 2001
From: Michael Chang <mch...@suse.com>
Date: Thu, 26 Mar 2020 14:35:35 +0800
Subject: [PATCH 2/2] zfs: Fix gcc10 error -Werror=zero-length-bounds

We bumped into the build error while testing gcc-10 pre-release.

In file included from ../../include/grub/file.h:22,
                from ../../grub-core/fs/zfs/zfs.c:34:
../../grub-core/fs/zfs/zfs.c: In function 'zap_leaf_lookup':
../../grub-core/fs/zfs/zfs.c:2263:44: error: array subscript '<unknown>' is 
outside the bounds of an interior zero-length array 'grub_uint16_t[0]' {aka 
'short unsigned int[0]'} [-Werror=zero-length-bounds]
2263 |   for (chunk = grub_zfs_to_cpu16 (l->l_hash[LEAF_HASH (blksft, h, l)], 
endian);
../../include/grub/types.h:241:48: note: in definition of macro 
'grub_le_to_cpu16'
 241 | # define grub_le_to_cpu16(x) ((grub_uint16_t) (x))
     |                                                ^
../../grub-core/fs/zfs/zfs.c:2263:16: note: in expansion of macro 
'grub_zfs_to_cpu16'
2263 |   for (chunk = grub_zfs_to_cpu16 (l->l_hash[LEAF_HASH (blksft, h, l)], 
endian);
     |                ^~~~~~~~~~~~~~~~~
In file included from ../../grub-core/fs/zfs/zfs.c:48:
../../include/grub/zfs/zap_leaf.h:72:16: note: while referencing 'l_hash'
  72 |  grub_uint16_t l_hash[0];
     |                ^~~~~~

Here I'd like to quote from the gcc document [1] which seems best to
explain what is going on here.

"Although the size of a zero-length array is zero, an array member of
this kind may increase the size of the enclosing type as a result of
tail padding. The offset of a zero-length array member from the
beginning of the enclosing structure is the same as the offset of an
array with one or more elements of the same type. The alignment of a
zero-length array is the same as the alignment of its elements.

Declaring zero-length arrays in other contexts, including as interior
members of structure objects or as non-member objects, is discouraged.
Accessing elements of zero-length arrays declared in such contexts is
undefined and may be diagnosed."

The l_hash[0] is apparnetly an interior member to the enclosed structure
while l_entries[0] is the trailing member. And the offending code tries
to access members in l_hash[0] array that triggers the diagnose.

Given that the l_entries[0] is used to get proper alignment to access
leaf chunks, we can accomplish the same thing through the ALIGN_UP macro
thus eliminating l_entries[0] from the structure. In this way we can
pacify the warning as l_hash[0] now becomes the last member to the
enclosed structure.

[1] https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html

Signed-off-by: Michael Chang <mch...@suse.com>
Reviewed-by: Daniel Kiper <daniel.ki...@oracle.com>
---
 grub-core/fs/zfs/zfs.c      | 5 ++++-
 include/grub/zfs/zap_leaf.h | 1 -
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/grub-core/fs/zfs/zfs.c b/grub-core/fs/zfs/zfs.c
index 2f72e42bf..b5e10fd0b 100644
--- a/grub-core/fs/zfs/zfs.c
+++ b/grub-core/fs/zfs/zfs.c
@@ -141,7 +141,10 @@ ZAP_LEAF_NUMCHUNKS (int bs)
 static inline zap_leaf_chunk_t *
 ZAP_LEAF_CHUNK (zap_leaf_phys_t *l, int bs, int idx)
 {
-  return &((zap_leaf_chunk_t *) (l->l_entries 
+  grub_properly_aligned_t *l_entries;
+
+  l_entries = (grub_properly_aligned_t *) ALIGN_UP((grub_addr_t)l->l_hash, 
sizeof (grub_properly_aligned_t));
+  return &((zap_leaf_chunk_t *) (l_entries
                                 + (ZAP_LEAF_HASH_NUMENTRIES(bs) * 2)
                                 / sizeof (grub_properly_aligned_t)))[idx];
 }
diff --git a/include/grub/zfs/zap_leaf.h b/include/grub/zfs/zap_leaf.h
index 95c67dcba..11447c166 100644
--- a/include/grub/zfs/zap_leaf.h
+++ b/include/grub/zfs/zap_leaf.h
@@ -70,7 +70,6 @@ typedef struct zap_leaf_phys {
         */
 
        grub_uint16_t l_hash[0];
-        grub_properly_aligned_t l_entries[0];
 } zap_leaf_phys_t;
 
 typedef union zap_leaf_chunk {
-- 
2.26.2

++++++ 0003-linux-Fix-gcc10-error-Werror-zero-length-bounds.patch ++++++
Index: trustedgrub2-1.4.0/grub-core/loader/i386/linux.c
===================================================================
--- trustedgrub2-1.4.0.orig/grub-core/loader/i386/linux.c
+++ trustedgrub2-1.4.0/grub-core/loader/i386/linux.c
@@ -823,7 +823,7 @@ grub_cmd_linux (grub_command_t cmd __att
 
   len = sizeof (linux_params) - sizeof (lh);
 
-  grub_memcpy( &linux_params + sizeof (lh), kernelBuf + kernelBufOffset, len );
+  grub_memcpy( (char *)&linux_params + sizeof (lh), kernelBuf + 
kernelBufOffset, len );
   kernelBufOffset+= len;
 
   linux_params.type_of_loader = GRUB_LINUX_BOOT_LOADER_TYPE;

Reply via email to