[syslinux:master] Packed definition: workaround for mingw + gcc 4. 7

syslinux-bot for H. Peter Anvin hpa at linux.intel.com
Mon Oct 22 13:48:02 PDT 2012


Commit-ID:  99f5441baa76a44680bf96a2fc01637f64fe3ff5
Gitweb:     http://www.syslinux.org/commit/99f5441baa76a44680bf96a2fc01637f64fe3ff5
Author:     H. Peter Anvin <hpa at linux.intel.com>
AuthorDate: Mon, 22 Oct 2012 13:42:31 -0700
Committer:  H. Peter Anvin <hpa at linux.intel.com>
CommitDate: Mon, 22 Oct 2012 13:42:31 -0700

Packed definition: workaround for mingw + gcc 4.7

__attribute__((packed)) does the wrong thing when in ms-struct
mode; this breaks compiling on mingw-w64.  Therefore force gcc struct
mode when we use packed.

This obsoletes checkin

  7d9ee65 win: Add -mno-ms-bitfields

Signed-off-by: H. Peter Anvin <hpa at linux.intel.com>

---
 libinstaller/syslxint.h |   23 +++++++++++++++++------
 1 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/libinstaller/syslxint.h b/libinstaller/syslxint.h
index 2e317d0..e5428b7 100644
--- a/libinstaller/syslxint.h
+++ b/libinstaller/syslxint.h
@@ -23,6 +23,17 @@
 # define X86_MEM 0
 #endif
 
+#ifdef __GNUC__
+# ifdef __MINGW32__
+   /* gcc 4.7 miscompiles packed structures in MS-bitfield mode */
+#  define PACKED __attribute__((packed,gcc_struct))
+# else
+#  define PACKED __attribute__((packed))
+# endif
+#else
+# error "Need to define PACKED for this compiler"
+#endif
+
 /*
  * Access functions for littleendian numbers, possibly misaligned.
  */
@@ -190,7 +201,7 @@ struct ext_patch_area {
 struct syslinux_extent {
     uint64_t lba;
     uint16_t len;
-} __attribute__((packed));
+} PACKED;
 
 /* FAT bootsector format, also used by other disk-based derivatives */
 struct fat_boot_sector {
@@ -218,7 +229,7 @@ struct fat_boot_sector {
 	    char VolumeLabel[11];
 	    char FileSysType[8];
 	    uint8_t Code[442];
-	} __attribute__ ((packed)) bs16;
+	} PACKED bs16;
 	struct {
 	    uint32_t FATSz32;
 	    uint16_t ExtFlags;
@@ -234,13 +245,13 @@ struct fat_boot_sector {
 	    char VolumeLabel[11];
 	    char FileSysType[8];
 	    uint8_t Code[414];
-	} __attribute__ ((packed)) bs32;
-    } __attribute__ ((packed));
+	} PACKED bs32;
+    } PACKED;
 
     uint32_t bsMagic;
     uint16_t bsForwardPtr;
     uint16_t bsSignature;
-} __attribute__ ((packed));
+} PACKED;
 
 /* NTFS bootsector format */
 struct ntfs_boot_sector {
@@ -273,7 +284,7 @@ struct ntfs_boot_sector {
     uint32_t bsMagic;
     uint16_t bsForwardPtr;
     uint16_t bsSignature;
-} __attribute__((packed));
+} PACKED;
 
 #define FAT_bsHead      bsJump
 #define FAT_bsHeadLen   offsetof(struct fat_boot_sector, bsBytesPerSec)


More information about the Syslinux-commits mailing list