Skip to contentSkip to conversation

./include/grub/gpt_partition.h:79:1: error: alignment 1 of ‘struct grub_gpt_partentry’ is less than 8 [-Werror=packed-not-aligned]

PATCH In review Paul Menzel 3 participants 7 messages Mar 21, 2018 – Mar 31, 2018

lore
Share & tools
lore
#0 lore raw

Dear GRUB folks,

Building GRUB’s master branch with GCC 8 shows the error below.

```
$ gcc-8 --version | head -1
gcc-8 (Debian 8-20180320-1) 8.0.1 20180320 (experimental) [trunk revision 258670]

$ git log --oneline -1
e2faabacf ieee1275: split up grub_machine_get_bootlocation
$ ./autogen.sh
$ ./configure --with-platform=coreboot --enable-boot-time CC=gcc-8
$ make
[…]
gcc-8 -DHAVE_CONFIG_H -I.  -Wall -W -DGRUB_UTIL=1 -D_FILE_OFFSET_BITS=64 -I./include -DGRUB_FILE=\"grub-core/disk/ldm.c\" -I. -I. -I. -I. -I./include -I./include -I./grub-core/lib/libgcrypt-grub/src/  -I./grub-core/gnulib -I./grub-core/gnulib -D_FILE_OFFSET_BITS=64 -Wall -W -Wshadow -Wpointer-arith -Wundef -Wchar-subscripts -Wcomment -Wdeprecated-declarations -Wdisabled-optimization -Wdiv-by-zero -Wfloat-equal -Wformat-extra-args -Wformat-security -Wformat-y2k -Wimplicit -Wimplicit-function-declaration -Wimplicit-int -Wmain -Wmissing-braces -Wmissing-format-attribute -Wmultichar -Wparentheses -Wreturn-type -Wsequence-point -Wshadow -Wsign-compare -Wswitch -Wtrigraphs -Wunknown-pragmas -Wunused -Wunused-function -Wunused-label -Wunused-parameter -Wunused-value  -Wunused-variable -Wwrite-strings -Wnested-externs -Wstrict-prototypes -Wcast-align  -Wextra -Wattributes -Wendif-labels -Winit-self -Wint-to-pointer-cast -Winvalid-pch -Wmissing-field-initializers -Wnonnull -Woverflow -Wvla -Wpointer-to-int-cast -Wstrict-aliasing -Wvariadic-macros -Wvolatile-register-var -Wpointer-sign -Wmissing-include-dirs -Wmissing-prototypes -Wmissing-declarations -Wformat=2 -Werror  -Wno-undef -Wno-sign-compare -Wno-unused -Wno-unused-parameter -Wno-redundant-decls -Wno-unreachable-code -Wno-conversion  -MT grub-core/disk/libgrubkern_a-ldm.o -MD -MP -MF grub-core/disk/.deps-util/libgrubkern_a-ldm.Tpo -c -o grub-core/disk/libgrubkern_a-ldm.o `test -f 'grub-core/disk/ldm.c' || echo './'`grub-core/disk/ldm.c
In file included from grub-core/disk/ldm.c:26:
./include/grub/gpt_partition.h:79:1: error: alignment 1 of ‘struct grub_gpt_partentry’ is less than 8 [-Werror=packed-not-aligned]
 } GRUB_PACKED;
 ^
```

Thanks,

Paul

#1 lore raw

PATCH 1/1 Fix packed-not-aligned error on GCC 8

Here just came up with a patch that fixed the GCC 8 error for me. :) Would you test it work for you as well ?

Thanks,
Michael

--

When building with GCC 8, there are several errors regarding packed-not-aligned.

./include/grub/gpt_partition.h:79:1: error: alignment 1 of ‘struct grub_gpt_partentry’ is less than 8 [-Werror=packed-not-aligned]

This patch tries to fix the build error by cleaning up the ambiguity of placing aligned structure in a packed one. In "struct grub_btrfs_time" and "struct grub_gpt_part_type", the aligned attribute seems to be superfluous, and also has to be packed, to ensure the structure is bit-to-bit mapped to the format laid on disk. I think we could blame to copy and paste error here for the mistake. In "struct efi_variable", we have to use grub_efi_packed_guid_t, as the name suggests. :)

---
 grub-core/fs/btrfs.c          | 2 +-
 include/grub/efiemu/runtime.h | 2 +-
 include/grub/gpt_partition.h  | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
grub-core/fs/btrfs.c +1 -1
index 4849c1ceb..be195448d 100644
@@ -175,7 +175,7 @@ struct grub_btrfs_time
 {
   grub_int64_t sec;
   grub_uint32_t nanosec;
-} __attribute__ ((aligned (4)));
+} GRUB_PACKED;
 
 struct grub_btrfs_inode
 {
include/grub/efiemu/runtime.h +1 -1
index 9b6b729f4..36d2dedf4 100644
@@ -29,7 +29,7 @@ struct grub_efiemu_ptv_rel
 
 struct efi_variable
 {
-  grub_efi_guid_t guid;
+  grub_efi_packed_guid_t guid;
   grub_uint32_t namelen;
   grub_uint32_t size;
   grub_efi_uint32_t attributes;
include/grub/gpt_partition.h +1 -1
index 1b32f6725..9668a68c3 100644
@@ -28,7 +28,7 @@ struct grub_gpt_part_type
   grub_uint16_t data2;
   grub_uint16_t data3;
   grub_uint8_t data4[8];
-} __attribute__ ((aligned(8)));
+} GRUB_PACKED;
 typedef struct grub_gpt_part_type grub_gpt_part_type_t;
 
 #define GRUB_GPT_PARTITION_TYPE_EMPTY \
Signature · 1 line
2.13.6
#2 lore raw

Re: [PATCH] Fix packed-not-aligned error on GCC 8

Hi,

Paul, does this patch work for you?

Michael, if it does please repost with your SOB and Tested-by: lines.

Daniel

Quoted 73 lines · Michael Chang

Here just came up with a patch that fixed the GCC 8 error for me. :) Would you test it work for you as well ?

Thanks,
Michael

--

When building with GCC 8, there are several errors regarding packed-not-aligned.

./include/grub/gpt_partition.h:79:1: error: alignment 1 of ???struct grub_gpt_partentry??? is less than 8 [-Werror=packed-not-aligned]

This patch tries to fix the build error by cleaning up the ambiguity of placing aligned structure in a packed one. In "struct grub_btrfs_time" and "struct grub_gpt_part_type", the aligned attribute seems to be superfluous, and also has to be packed, to ensure the structure is bit-to-bit mapped to the format laid on disk. I think we could blame to copy and paste error here for the mistake. In "struct efi_variable", we have to use grub_efi_packed_guid_t, as the name suggests. :)

---
 grub-core/fs/btrfs.c          | 2 +-
 include/grub/efiemu/runtime.h | 2 +-
 include/grub/gpt_partition.h  | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
grub-core/fs/btrfs.c +1 -1
index 4849c1ceb..be195448d 100644
@@ -175,7 +175,7 @@ struct grub_btrfs_time
 {
   grub_int64_t sec;
   grub_uint32_t nanosec;
-} __attribute__ ((aligned (4)));
+} GRUB_PACKED;
 
 struct grub_btrfs_inode
 {
include/grub/efiemu/runtime.h +1 -1
index 9b6b729f4..36d2dedf4 100644
@@ -29,7 +29,7 @@ struct grub_efiemu_ptv_rel
 
 struct efi_variable
 {
-  grub_efi_guid_t guid;
+  grub_efi_packed_guid_t guid;
   grub_uint32_t namelen;
   grub_uint32_t size;
   grub_efi_uint32_t attributes;
include/grub/gpt_partition.h +1 -2
index 1b32f6725..9668a68c3 100644
@@ -28,7 +28,7 @@ struct grub_gpt_part_type
   grub_uint16_t data2;
   grub_uint16_t data3;
   grub_uint8_t data4[8];
-} __attribute__ ((aligned(8)));
+} GRUB_PACKED;
 typedef struct grub_gpt_part_type grub_gpt_part_type_t;
 
 #define GRUB_GPT_PARTITION_TYPE_EMPTY \
--

2.13.6

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

Tested-by
#3 lore raw

Re: [PATCH] Fix packed-not-aligned error on GCC 8

When building with GCC 8, there are several errors regarding packed-not-aligned.

./include/grub/gpt_partition.h:79:1: error: alignment 1 of ‘struct grub_gpt_partentry’ is less than 8 [-Werror=packed-not-aligned]

This patch tries to fix the build error by cleaning up the ambiguity of placing aligned structure in a packed one. In "struct grub_btrfs_time" and "struct grub_gpt_part_type", the aligned attribute seems to be superfluous, and also has to be packed, to ensure the structure is bit-to-bit mapped to the format laid on disk. I think we could blame to copy and paste error here for the mistake. In "struct efi_variable", we have to use grub_efi_packed_guid_t, as the name suggests. :)

---
 grub-core/fs/btrfs.c          | 2 +-
 include/grub/efiemu/runtime.h | 2 +-
 include/grub/gpt_partition.h  | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
grub-core/fs/btrfs.c +1 -1
index 4849c1ceb..be195448d 100644
@@ -175,7 +175,7 @@ struct grub_btrfs_time
 {
   grub_int64_t sec;
   grub_uint32_t nanosec;
-} __attribute__ ((aligned (4)));
+} GRUB_PACKED;
 
 struct grub_btrfs_inode
 {
include/grub/efiemu/runtime.h +1 -1
index 9b6b729f4..36d2dedf4 100644
@@ -29,7 +29,7 @@ struct grub_efiemu_ptv_rel
 
 struct efi_variable
 {
-  grub_efi_guid_t guid;
+  grub_efi_packed_guid_t guid;
   grub_uint32_t namelen;
   grub_uint32_t size;
   grub_efi_uint32_t attributes;
include/grub/gpt_partition.h +1 -1
index 1b32f6725..9668a68c3 100644
@@ -28,7 +28,7 @@ struct grub_gpt_part_type
   grub_uint16_t data2;
   grub_uint16_t data3;
   grub_uint8_t data4[8];
-} __attribute__ ((aligned(8)));
+} GRUB_PACKED;
 typedef struct grub_gpt_part_type grub_gpt_part_type_t;
 
 #define GRUB_GPT_PARTITION_TYPE_EMPTY \
Signature · 1 line
2.13.6
#4 lore raw

Re: [PATCH] Fix packed-not-aligned error on GCC 8

Quoted 5 lines · Michael Chang

When building with GCC 8, there are several errors regarding packed-not-aligned.

./include/grub/gpt_partition.h:79:1: error: alignment 1 of ???struct grub_gpt_partentry??? is less than 8 [-Werror=packed-not-aligned]

This patch tries to fix the build error by cleaning up the ambiguity of placing

s/tries to fix/fixes/?

Quoted 9 lines

aligned structure in a packed one. In "struct grub_btrfs_time" and "struct grub_gpt_part_type", the aligned attribute seems to be superfluous, and also has to be packed, to ensure the structure is bit-to-bit mapped to the format laid on disk. I think we could blame to copy and paste error here for the mistake. In "struct efi_variable", we have to use grub_efi_packed_guid_t, as the name suggests. :)

Otherwise, Reviewed-by: Daniel Kiper <[email protected]>

If there are no objections I will apply this in a week or so.

Daniel

#5 lore raw

Re: [PATCH] Fix packed-not-aligned error on GCC 8

Quoted 8 lines · Daniel Kiper
Quoted 5 lines · Michael Chang

When building with GCC 8, there are several errors regarding packed-not-aligned.

./include/grub/gpt_partition.h:79:1: error: alignment 1 of ???struct grub_gpt_partentry??? is less than 8 [-Werror=packed-not-aligned]

This patch tries to fix the build error by cleaning up the ambiguity of placing

s/tries to fix/fixes/?

Yes. I think the patch is adequate to say so.

Quoted 8 lines
Quoted 8 lines

aligned structure in a packed one. In "struct grub_btrfs_time" and "struct grub_gpt_part_type", the aligned attribute seems to be superfluous, and also has to be packed, to ensure the structure is bit-to-bit mapped to the format laid on disk. I think we could blame to copy and paste error here for the mistake. In "struct efi_variable", we have to use grub_efi_packed_guid_t, as the name suggests. :)

Quoted 6 lines
Quoted 2 lines

Otherwise, Reviewed-by: Daniel Kiper <[email protected]>

If there are no objections I will apply this in a week or so.

Thank you very much. :)

Regards,
Michael

Quoted 2 lines

Daniel

author Tested-by
#6 lore raw

Re: [PATCH] Fix packed-not-aligned error on GCC 8

Dear Michael, dear Daniel,

Thank you for the fix.

Am Mittwoch, den 28.03.2018, 12:59 +0800 schrieb Michael Chang:

Quoted 11 lines · Daniel Kiper
Quoted 8 lines · Michael Chang
Quoted 5 lines

When building with GCC 8, there are several errors regarding packed-not-aligned.

./include/grub/gpt_partition.h:79:1: error: alignment 1 of ???struct grub_gpt_partentry??? is less than 8 [-Werror=packed-not-aligned]

This patch tries to fix the build error by cleaning up the ambiguity of placing

s/tries to fix/fixes/?

Yes. I think the patch is adequate to say so.

I also think, *fixes* sounds better. Maybe Daniel can amend that.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

aligned structure in a packed one. In "struct grub_btrfs_time" and "struct grub_gpt_part_type", the aligned attribute seems to be superfluous, and also has to be packed, to ensure the structure is bit-to-bit mapped to the format laid on disk. I think we could blame to copy and paste error here for the mistake. In "struct efi_variable", we have to use grub_efi_packed_guid_t, as the name suggests. :)

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

Otherwise, Reviewed-by: Daniel Kiper <[email protected]>

If there are no objections I will apply this in a week or so.

Thank you very much. :)

Thanks,

Paul