[parted-devel] [PATCH 1/3] libparted/labels: Specify 'aligned' attributes

Shin'ichiro Kawasaki kawasaki at juno.dti.ne.jp
Sun Jun 30 13:49:42 BST 2019


GCC 9 fails to compile a few of libparted/labels/*.c because of -Werror=
address-of-packed-member option. One of the error messages for atari.c
was as follows:

  CC       atari.lo
atari.c: In function 'atr_calc_rs_sum':
atari.c:763:2: error: converting a packed 'AtariRawTable' {aka 'const struct _AtariRawTable'} pointer (alignment 1) to a 'uint16_t' {aka 'const short unsigned int'} pointer (alignment 2) may result in an unaligned pointer value [-Werror=address-of-packed-member]
  763 |  const uint16_t* word = (uint16_t*)(table);
      |  ^~~~~
cc1: all warnings being treated as errors

To avoid the errors, specify 'aligned' attributes to AtariRawTable,
BSDRawLabel, GPTDiskData and SunRawLabel.

Signed-off-by: Shin'ichiro Kawasaki <kawasaki at juno.dti.ne.jp>
---
 libparted/labels/atari.c | 2 +-
 libparted/labels/bsd.c   | 2 +-
 libparted/labels/gpt.c   | 2 +-
 libparted/labels/sun.c   | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/libparted/labels/atari.c b/libparted/labels/atari.c
index ea4c87f..9f8fa5c 100644
--- a/libparted/labels/atari.c
+++ b/libparted/labels/atari.c
@@ -142,7 +142,7 @@ struct __attribute__ ((packed)) _AtariRawPartition {
 };
 typedef struct _AtariRawPartition AtariRawPartition;
 
-struct __attribute__ ((packed)) _AtariRawTable {
+struct __attribute__ ((packed)) __attribute__ ((aligned (2))) _AtariRawTable {
 	uint8_t		  boot_code[0x156]; /* room for boot code */
 	AtariRawPartition icd_part[N_ICD];  /* info for ICD-partitions 5..12 */
 	uint8_t		  unused[0xc];
diff --git a/libparted/labels/bsd.c b/libparted/labels/bsd.c
index f253a32..ba58bf8 100644
--- a/libparted/labels/bsd.c
+++ b/libparted/labels/bsd.c
@@ -105,7 +105,7 @@ struct _BSDRawLabel {
 	uint32_t	d_bbsize;		/* size of boot area at sn0, bytes */
 	uint32_t	d_sbsize;		/* max size of fs superblock, bytes */
 	BSDRawPartition d_partitions[BSD_MAXPARTITIONS];	/* actually may be more */
-} __attribute__((packed));
+} __attribute__((packed)) __attribute__((aligned (4)));
 
 typedef struct {
 	char		boot_code [512];
diff --git a/libparted/labels/gpt.c b/libparted/labels/gpt.c
index 860f415..ad5de5a 100644
--- a/libparted/labels/gpt.c
+++ b/libparted/labels/gpt.c
@@ -273,7 +273,7 @@ struct __attribute__ ((packed)) _LegacyMBR_t
 };
 
 /* uses libparted's disk_specific field in PedDisk, to store our info */
-struct __attribute__ ((packed)) _GPTDiskData
+struct __attribute__ ((packed)) __attribute__ ((aligned (8))) _GPTDiskData
 {
   PedGeometry data_area;
   int entry_count;
diff --git a/libparted/labels/sun.c b/libparted/labels/sun.c
index b23ff86..51b01fa 100644
--- a/libparted/labels/sun.c
+++ b/libparted/labels/sun.c
@@ -68,7 +68,7 @@ struct __attribute__ ((packed)) _SunPartitionInfo {
 	u_int8_t	flags;		/* Partition flags */
 };
 
-struct __attribute__ ((packed)) _SunRawLabel {
+struct __attribute__ ((packed)) __attribute__ ((aligned (2))) _SunRawLabel {
 	char 		info[128];	/* Informative text string */
 	u_int32_t	version;	/* Layout version */
 	u_int8_t	volume[8];	/* Volume name */
-- 
2.22.0




More information about the parted-devel mailing list